1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_version.h"
44 #include "lpfc_compat.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
48 #define LPFC_DEF_DEVLOSS_TMO 30
49 #define LPFC_MIN_DEVLOSS_TMO 1
50 #define LPFC_MAX_DEVLOSS_TMO 255
52 #define LPFC_MAX_LINK_SPEED 8
53 #define LPFC_LINK_SPEED_BITMAP 0x00000117
54 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
57 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
58 * @incr: integer to convert.
59 * @hdw: ascii string holding converted integer plus a string terminator.
62 * JEDEC Joint Electron Device Engineering Council.
63 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
64 * character string. The string is then terminated with a NULL in byte 9.
65 * Hex 0-9 becomes ascii '0' to '9'.
66 * Hex a-f becomes ascii '=' to 'B' capital B.
69 * Coded for 32 bit integers only.
72 lpfc_jedec_to_ascii(int incr, char hdw[])
75 for (i = 0; i < 8; i++) {
78 hdw[7 - i] = 0x30 + j;
80 hdw[7 - i] = 0x61 + j - 10;
88 * lpfc_drvr_version_show - Return the Emulex driver string with version number
89 * @dev: class unused variable.
90 * @attr: device attribute, not used.
91 * @buf: on return contains the module description text.
93 * Returns: size of formatted string.
96 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
99 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
103 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
106 struct Scsi_Host *shost = class_to_shost(dev);
107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
108 struct lpfc_hba *phba = vport->phba;
110 if (phba->cfg_enable_bg)
111 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
112 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
114 return snprintf(buf, PAGE_SIZE,
115 "BlockGuard Not Supported\n");
117 return snprintf(buf, PAGE_SIZE,
118 "BlockGuard Disabled\n");
122 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
125 struct Scsi_Host *shost = class_to_shost(dev);
126 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
127 struct lpfc_hba *phba = vport->phba;
129 return snprintf(buf, PAGE_SIZE, "%llu\n",
130 (unsigned long long)phba->bg_guard_err_cnt);
134 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
137 struct Scsi_Host *shost = class_to_shost(dev);
138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
139 struct lpfc_hba *phba = vport->phba;
141 return snprintf(buf, PAGE_SIZE, "%llu\n",
142 (unsigned long long)phba->bg_apptag_err_cnt);
146 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
153 return snprintf(buf, PAGE_SIZE, "%llu\n",
154 (unsigned long long)phba->bg_reftag_err_cnt);
158 * lpfc_info_show - Return some pci info about the host in ascii
159 * @dev: class converted to a Scsi_host structure.
160 * @attr: device attribute, not used.
161 * @buf: on return contains the formatted text from lpfc_info().
163 * Returns: size of formatted string.
166 lpfc_info_show(struct device *dev, struct device_attribute *attr,
169 struct Scsi_Host *host = class_to_shost(dev);
171 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
175 * lpfc_serialnum_show - Return the hba serial number in ascii
176 * @dev: class converted to a Scsi_host structure.
177 * @attr: device attribute, not used.
178 * @buf: on return contains the formatted text serial number.
180 * Returns: size of formatted string.
183 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
186 struct Scsi_Host *shost = class_to_shost(dev);
187 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
188 struct lpfc_hba *phba = vport->phba;
190 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
194 * lpfc_temp_sensor_show - Return the temperature sensor level
195 * @dev: class converted to a Scsi_host structure.
196 * @attr: device attribute, not used.
197 * @buf: on return contains the formatted support level.
200 * Returns a number indicating the temperature sensor level currently
201 * supported, zero or one in ascii.
203 * Returns: size of formatted string.
206 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
209 struct Scsi_Host *shost = class_to_shost(dev);
210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
211 struct lpfc_hba *phba = vport->phba;
212 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
216 * lpfc_modeldesc_show - Return the model description of the hba
217 * @dev: class converted to a Scsi_host structure.
218 * @attr: device attribute, not used.
219 * @buf: on return contains the scsi vpd model description.
221 * Returns: size of formatted string.
224 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
227 struct Scsi_Host *shost = class_to_shost(dev);
228 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
229 struct lpfc_hba *phba = vport->phba;
231 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
235 * lpfc_modelname_show - Return the model name of the hba
236 * @dev: class converted to a Scsi_host structure.
237 * @attr: device attribute, not used.
238 * @buf: on return contains the scsi vpd model name.
240 * Returns: size of formatted string.
243 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
246 struct Scsi_Host *shost = class_to_shost(dev);
247 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
248 struct lpfc_hba *phba = vport->phba;
250 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
254 * lpfc_programtype_show - Return the program type of the hba
255 * @dev: class converted to a Scsi_host structure.
256 * @attr: device attribute, not used.
257 * @buf: on return contains the scsi vpd program type.
259 * Returns: size of formatted string.
262 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
265 struct Scsi_Host *shost = class_to_shost(dev);
266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
267 struct lpfc_hba *phba = vport->phba;
269 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
273 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
274 * @dev: class converted to a Scsi_host structure.
275 * @attr: device attribute, not used.
276 * @buf: on return contains the Menlo Maintenance sli flag.
278 * Returns: size of formatted string.
281 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
283 struct Scsi_Host *shost = class_to_shost(dev);
284 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
285 struct lpfc_hba *phba = vport->phba;
287 return snprintf(buf, PAGE_SIZE, "%d\n",
288 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
292 * lpfc_vportnum_show - Return the port number in ascii of the hba
293 * @dev: class converted to a Scsi_host structure.
294 * @attr: device attribute, not used.
295 * @buf: on return contains scsi vpd program type.
297 * Returns: size of formatted string.
300 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
303 struct Scsi_Host *shost = class_to_shost(dev);
304 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
305 struct lpfc_hba *phba = vport->phba;
307 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
311 * lpfc_fwrev_show - Return the firmware rev running in the hba
312 * @dev: class converted to a Scsi_host structure.
313 * @attr: device attribute, not used.
314 * @buf: on return contains the scsi vpd program type.
316 * Returns: size of formatted string.
319 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
322 struct Scsi_Host *shost = class_to_shost(dev);
323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
324 struct lpfc_hba *phba = vport->phba;
327 lpfc_decode_firmware_rev(phba, fwrev, 1);
328 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
332 * lpfc_hdw_show - Return the jedec information about the hba
333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
337 * Returns: size of formatted string.
340 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
343 struct Scsi_Host *shost = class_to_shost(dev);
344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
346 lpfc_vpd_t *vp = &phba->vpd;
348 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
349 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
353 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the ROM and FCode ascii strings.
358 * Returns: size of formatted string.
361 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
364 struct Scsi_Host *shost = class_to_shost(dev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
368 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
372 * lpfc_state_show - Return the link state of the port
373 * @dev: class converted to a Scsi_host structure.
374 * @attr: device attribute, not used.
375 * @buf: on return contains text describing the state of the link.
378 * The switch statement has no default so zero will be returned.
380 * Returns: size of formatted string.
383 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
386 struct Scsi_Host *shost = class_to_shost(dev);
387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
388 struct lpfc_hba *phba = vport->phba;
391 switch (phba->link_state) {
392 case LPFC_LINK_UNKNOWN:
393 case LPFC_WARM_START:
394 case LPFC_INIT_START:
395 case LPFC_INIT_MBX_CMDS:
398 if (phba->hba_flag & LINK_DISABLED)
399 len += snprintf(buf + len, PAGE_SIZE-len,
400 "Link Down - User disabled\n");
402 len += snprintf(buf + len, PAGE_SIZE-len,
408 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
410 switch (vport->port_state) {
411 case LPFC_LOCAL_CFG_LINK:
412 len += snprintf(buf + len, PAGE_SIZE-len,
413 "Configuring Link\n");
417 case LPFC_FABRIC_CFG_LINK:
420 case LPFC_BUILD_DISC_LIST:
422 len += snprintf(buf + len, PAGE_SIZE - len,
425 case LPFC_VPORT_READY:
426 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
429 case LPFC_VPORT_FAILED:
430 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
433 case LPFC_VPORT_UNKNOWN:
434 len += snprintf(buf + len, PAGE_SIZE - len,
438 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
439 len += snprintf(buf + len, PAGE_SIZE-len,
440 " Menlo Maint Mode\n");
441 else if (phba->fc_topology == TOPOLOGY_LOOP) {
442 if (vport->fc_flag & FC_PUBLIC_LOOP)
443 len += snprintf(buf + len, PAGE_SIZE-len,
446 len += snprintf(buf + len, PAGE_SIZE-len,
449 if (vport->fc_flag & FC_FABRIC)
450 len += snprintf(buf + len, PAGE_SIZE-len,
453 len += snprintf(buf + len, PAGE_SIZE-len,
462 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
463 * @dev: class device that is converted into a Scsi_host.
464 * @attr: device attribute, not used.
465 * @buf: on return contains the sum of fc mapped and unmapped.
468 * Returns the ascii text number of the sum of the fc mapped and unmapped
471 * Returns: size of formatted string.
474 lpfc_num_discovered_ports_show(struct device *dev,
475 struct device_attribute *attr, char *buf)
477 struct Scsi_Host *shost = class_to_shost(dev);
478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
480 return snprintf(buf, PAGE_SIZE, "%d\n",
481 vport->fc_map_cnt + vport->fc_unmap_cnt);
485 * lpfc_issue_lip - Misnomer, name carried over from long ago
486 * @shost: Scsi_Host pointer.
489 * Bring the link down gracefully then re-init the link. The firmware will
490 * re-init the fiber channel interface as required. Does not issue a LIP.
493 * -EPERM port offline or management commands are being blocked
494 * -ENOMEM cannot allocate memory for the mailbox command
495 * -EIO error sending the mailbox command
499 lpfc_issue_lip(struct Scsi_Host *shost)
501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
502 struct lpfc_hba *phba = vport->phba;
503 LPFC_MBOXQ_t *pmboxq;
504 int mbxstatus = MBXERR_ERROR;
506 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
507 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
510 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
515 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
516 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
517 pmboxq->u.mb.mbxOwner = OWN_HOST;
519 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
521 if ((mbxstatus == MBX_SUCCESS) &&
522 (pmboxq->u.mb.mbxStatus == 0 ||
523 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
524 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
525 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
526 phba->cfg_link_speed);
527 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
531 lpfc_set_loopback_flag(phba);
532 if (mbxstatus != MBX_TIMEOUT)
533 mempool_free(pmboxq, phba->mbox_mem_pool);
535 if (mbxstatus == MBXERR_ERROR)
542 * lpfc_do_offline - Issues a mailbox command to bring the link down
543 * @phba: lpfc_hba pointer.
544 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
547 * Assumes any error from lpfc_do_offline() will be negative.
548 * Can wait up to 5 seconds for the port ring buffers count
549 * to reach zero, prints a warning if it is not zero and continues.
550 * lpfc_workq_post_event() returns a non-zero return code if call fails.
553 * -EIO error posting the event
557 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
559 struct completion online_compl;
560 struct lpfc_sli_ring *pring;
561 struct lpfc_sli *psli;
566 init_completion(&online_compl);
567 lpfc_workq_post_event(phba, &status, &online_compl,
568 LPFC_EVT_OFFLINE_PREP);
569 wait_for_completion(&online_compl);
576 /* Wait a little for things to settle down, but not
577 * long enough for dev loss timeout to expire.
579 for (i = 0; i < psli->num_rings; i++) {
580 pring = &psli->ring[i];
581 while (pring->txcmplq_cnt) {
583 if (cnt++ > 500) { /* 5 secs */
584 lpfc_printf_log(phba,
585 KERN_WARNING, LOG_INIT,
586 "0466 Outstanding IO when "
587 "bringing Adapter offline\n");
593 init_completion(&online_compl);
594 lpfc_workq_post_event(phba, &status, &online_compl, type);
595 wait_for_completion(&online_compl);
604 * lpfc_selective_reset - Offline then onlines the port
605 * @phba: lpfc_hba pointer.
608 * If the port is configured to allow a reset then the hba is brought
609 * offline then online.
612 * Assumes any error from lpfc_do_offline() will be negative.
615 * lpfc_do_offline() return code if not zero
616 * -EIO reset not configured or error posting the event
620 lpfc_selective_reset(struct lpfc_hba *phba)
622 struct completion online_compl;
625 if (!phba->cfg_enable_hba_reset)
628 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
633 init_completion(&online_compl);
634 lpfc_workq_post_event(phba, &status, &online_compl,
636 wait_for_completion(&online_compl);
645 * lpfc_issue_reset - Selectively resets an adapter
646 * @dev: class device that is converted into a Scsi_host.
647 * @attr: device attribute, not used.
648 * @buf: containing the string "selective".
649 * @count: unused variable.
652 * If the buf contains the string "selective" then lpfc_selective_reset()
653 * is called to perform the reset.
656 * Assumes any error from lpfc_selective_reset() will be negative.
657 * If lpfc_selective_reset() returns zero then the length of the buffer
658 * is returned which indicates succcess
661 * -EINVAL if the buffer does not contain the string "selective"
662 * length of buf if lpfc-selective_reset() if the call succeeds
663 * return value of lpfc_selective_reset() if the call fails
666 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
667 const char *buf, size_t count)
669 struct Scsi_Host *shost = class_to_shost(dev);
670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
671 struct lpfc_hba *phba = vport->phba;
673 int status = -EINVAL;
675 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
676 status = lpfc_selective_reset(phba);
685 * lpfc_nport_evt_cnt_show - Return the number of nport events
686 * @dev: class device that is converted into a Scsi_host.
687 * @attr: device attribute, not used.
688 * @buf: on return contains the ascii number of nport events.
690 * Returns: size of formatted string.
693 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
696 struct Scsi_Host *shost = class_to_shost(dev);
697 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
698 struct lpfc_hba *phba = vport->phba;
700 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
704 * lpfc_board_mode_show - Return the state of the board
705 * @dev: class device that is converted into a Scsi_host.
706 * @attr: device attribute, not used.
707 * @buf: on return contains the state of the adapter.
709 * Returns: size of formatted string.
712 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
715 struct Scsi_Host *shost = class_to_shost(dev);
716 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
717 struct lpfc_hba *phba = vport->phba;
720 if (phba->link_state == LPFC_HBA_ERROR)
722 else if (phba->link_state == LPFC_WARM_START)
723 state = "warm start";
724 else if (phba->link_state == LPFC_INIT_START)
729 return snprintf(buf, PAGE_SIZE, "%s\n", state);
733 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
734 * @dev: class device that is converted into a Scsi_host.
735 * @attr: device attribute, not used.
736 * @buf: containing one of the strings "online", "offline", "warm" or "error".
737 * @count: unused variable.
740 * -EACCES if enable hba reset not enabled
741 * -EINVAL if the buffer does not contain a valid string (see above)
742 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
743 * buf length greater than zero indicates success
746 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
747 const char *buf, size_t count)
749 struct Scsi_Host *shost = class_to_shost(dev);
750 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
751 struct lpfc_hba *phba = vport->phba;
752 struct completion online_compl;
755 if (!phba->cfg_enable_hba_reset)
757 init_completion(&online_compl);
759 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
760 lpfc_workq_post_event(phba, &status, &online_compl,
762 wait_for_completion(&online_compl);
763 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
764 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
765 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
766 if (phba->sli_rev == LPFC_SLI_REV4)
769 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
770 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
771 if (phba->sli_rev == LPFC_SLI_REV4)
774 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
785 * lpfc_get_hba_info - Return various bits of informaton about the adapter
786 * @phba: pointer to the adapter structure.
787 * @mxri: max xri count.
788 * @axri: available xri count.
789 * @mrpi: max rpi count.
790 * @arpi: available rpi count.
791 * @mvpi: max vpi count.
792 * @avpi: available vpi count.
795 * If an integer pointer for an count is not null then the value for the
803 lpfc_get_hba_info(struct lpfc_hba *phba,
804 uint32_t *mxri, uint32_t *axri,
805 uint32_t *mrpi, uint32_t *arpi,
806 uint32_t *mvpi, uint32_t *avpi)
808 struct lpfc_sli *psli = &phba->sli;
809 struct lpfc_mbx_read_config *rd_config;
810 LPFC_MBOXQ_t *pmboxq;
815 * prevent udev from issuing mailbox commands until the port is
818 if (phba->link_state < LPFC_LINK_DOWN ||
819 !phba->mbox_mem_pool ||
820 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
823 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
826 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
829 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
832 pmb->mbxCommand = MBX_READ_CONFIG;
833 pmb->mbxOwner = OWN_HOST;
834 pmboxq->context1 = NULL;
836 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
837 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
838 rc = MBX_NOT_FINISHED;
840 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
842 if (rc != MBX_SUCCESS) {
843 if (rc != MBX_TIMEOUT)
844 mempool_free(pmboxq, phba->mbox_mem_pool);
848 if (phba->sli_rev == LPFC_SLI_REV4) {
849 rd_config = &pmboxq->u.mqe.un.rd_config;
851 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
853 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
854 phba->sli4_hba.max_cfg_param.rpi_used;
856 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
858 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
859 phba->sli4_hba.max_cfg_param.xri_used;
861 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
863 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
864 phba->sli4_hba.max_cfg_param.vpi_used;
867 *mrpi = pmb->un.varRdConfig.max_rpi;
869 *arpi = pmb->un.varRdConfig.avail_rpi;
871 *mxri = pmb->un.varRdConfig.max_xri;
873 *axri = pmb->un.varRdConfig.avail_xri;
875 *mvpi = pmb->un.varRdConfig.max_vpi;
877 *avpi = pmb->un.varRdConfig.avail_vpi;
880 mempool_free(pmboxq, phba->mbox_mem_pool);
885 * lpfc_max_rpi_show - Return maximum rpi
886 * @dev: class device that is converted into a Scsi_host.
887 * @attr: device attribute, not used.
888 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
891 * Calls lpfc_get_hba_info() asking for just the mrpi count.
892 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
893 * to "Unknown" and the buffer length is returned, therefore the caller
894 * must check for "Unknown" in the buffer to detect a failure.
896 * Returns: size of formatted string.
899 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
902 struct Scsi_Host *shost = class_to_shost(dev);
903 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
904 struct lpfc_hba *phba = vport->phba;
907 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
908 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
909 return snprintf(buf, PAGE_SIZE, "Unknown\n");
913 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
914 * @dev: class device that is converted into a Scsi_host.
915 * @attr: device attribute, not used.
916 * @buf: containing the used rpi count in decimal or "Unknown".
919 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
920 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
921 * to "Unknown" and the buffer length is returned, therefore the caller
922 * must check for "Unknown" in the buffer to detect a failure.
924 * Returns: size of formatted string.
927 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
930 struct Scsi_Host *shost = class_to_shost(dev);
931 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
932 struct lpfc_hba *phba = vport->phba;
935 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
936 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
937 return snprintf(buf, PAGE_SIZE, "Unknown\n");
941 * lpfc_max_xri_show - Return maximum xri
942 * @dev: class device that is converted into a Scsi_host.
943 * @attr: device attribute, not used.
944 * @buf: on return contains the maximum xri count in decimal or "Unknown".
947 * Calls lpfc_get_hba_info() asking for just the mrpi count.
948 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
949 * to "Unknown" and the buffer length is returned, therefore the caller
950 * must check for "Unknown" in the buffer to detect a failure.
952 * Returns: size of formatted string.
955 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
958 struct Scsi_Host *shost = class_to_shost(dev);
959 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
960 struct lpfc_hba *phba = vport->phba;
963 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
964 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
965 return snprintf(buf, PAGE_SIZE, "Unknown\n");
969 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
970 * @dev: class device that is converted into a Scsi_host.
971 * @attr: device attribute, not used.
972 * @buf: on return contains the used xri count in decimal or "Unknown".
975 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
976 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
977 * to "Unknown" and the buffer length is returned, therefore the caller
978 * must check for "Unknown" in the buffer to detect a failure.
980 * Returns: size of formatted string.
983 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
986 struct Scsi_Host *shost = class_to_shost(dev);
987 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
988 struct lpfc_hba *phba = vport->phba;
991 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
992 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
993 return snprintf(buf, PAGE_SIZE, "Unknown\n");
997 * lpfc_max_vpi_show - Return maximum vpi
998 * @dev: class device that is converted into a Scsi_host.
999 * @attr: device attribute, not used.
1000 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1003 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1004 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1005 * to "Unknown" and the buffer length is returned, therefore the caller
1006 * must check for "Unknown" in the buffer to detect a failure.
1008 * Returns: size of formatted string.
1011 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1014 struct Scsi_Host *shost = class_to_shost(dev);
1015 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1016 struct lpfc_hba *phba = vport->phba;
1019 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1020 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1021 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1025 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1026 * @dev: class device that is converted into a Scsi_host.
1027 * @attr: device attribute, not used.
1028 * @buf: on return contains the used vpi count in decimal or "Unknown".
1031 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1032 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1033 * to "Unknown" and the buffer length is returned, therefore the caller
1034 * must check for "Unknown" in the buffer to detect a failure.
1036 * Returns: size of formatted string.
1039 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1042 struct Scsi_Host *shost = class_to_shost(dev);
1043 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1044 struct lpfc_hba *phba = vport->phba;
1047 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1048 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1049 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1053 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1054 * @dev: class device that is converted into a Scsi_host.
1055 * @attr: device attribute, not used.
1056 * @buf: text that must be interpreted to determine if npiv is supported.
1059 * Buffer will contain text indicating npiv is not suppoerted on the port,
1060 * the port is an NPIV physical port, or it is an npiv virtual port with
1061 * the id of the vport.
1063 * Returns: size of formatted string.
1066 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1069 struct Scsi_Host *shost = class_to_shost(dev);
1070 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1071 struct lpfc_hba *phba = vport->phba;
1073 if (!(phba->max_vpi))
1074 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1075 if (vport->port_type == LPFC_PHYSICAL_PORT)
1076 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1077 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1081 * lpfc_poll_show - Return text about poll support for the adapter
1082 * @dev: class device that is converted into a Scsi_host.
1083 * @attr: device attribute, not used.
1084 * @buf: on return contains the cfg_poll in hex.
1087 * cfg_poll should be a lpfc_polling_flags type.
1089 * Returns: size of formatted string.
1092 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1095 struct Scsi_Host *shost = class_to_shost(dev);
1096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
1099 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1103 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1104 * @dev: class device that is converted into a Scsi_host.
1105 * @attr: device attribute, not used.
1106 * @buf: one or more lpfc_polling_flags values.
1110 * buf contents converted to integer and checked for a valid value.
1113 * -EINVAL if the buffer connot be converted or is out of range
1114 * length of the buf on success
1117 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1118 const char *buf, size_t count)
1120 struct Scsi_Host *shost = class_to_shost(dev);
1121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1122 struct lpfc_hba *phba = vport->phba;
1127 if (!isdigit(buf[0]))
1130 if (sscanf(buf, "%i", &val) != 1)
1133 if ((val & 0x3) != val)
1136 spin_lock_irq(&phba->hbalock);
1138 old_val = phba->cfg_poll;
1140 if (val & ENABLE_FCP_RING_POLLING) {
1141 if ((val & DISABLE_FCP_RING_INT) &&
1142 !(old_val & DISABLE_FCP_RING_INT)) {
1143 creg_val = readl(phba->HCregaddr);
1144 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1145 writel(creg_val, phba->HCregaddr);
1146 readl(phba->HCregaddr); /* flush */
1148 lpfc_poll_start_timer(phba);
1150 } else if (val != 0x0) {
1151 spin_unlock_irq(&phba->hbalock);
1155 if (!(val & DISABLE_FCP_RING_INT) &&
1156 (old_val & DISABLE_FCP_RING_INT))
1158 spin_unlock_irq(&phba->hbalock);
1159 del_timer(&phba->fcp_poll_timer);
1160 spin_lock_irq(&phba->hbalock);
1161 creg_val = readl(phba->HCregaddr);
1162 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1163 writel(creg_val, phba->HCregaddr);
1164 readl(phba->HCregaddr); /* flush */
1167 phba->cfg_poll = val;
1169 spin_unlock_irq(&phba->hbalock);
1175 * lpfc_param_show - Return a cfg attribute value in decimal
1178 * Macro that given an attr e.g. hba_queue_depth expands
1179 * into a function with the name lpfc_hba_queue_depth_show.
1181 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1182 * @dev: class device that is converted into a Scsi_host.
1183 * @attr: device attribute, not used.
1184 * @buf: on return contains the attribute value in decimal.
1186 * Returns: size of formatted string.
1188 #define lpfc_param_show(attr) \
1190 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1193 struct Scsi_Host *shost = class_to_shost(dev);\
1194 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1195 struct lpfc_hba *phba = vport->phba;\
1197 val = phba->cfg_##attr;\
1198 return snprintf(buf, PAGE_SIZE, "%d\n",\
1203 * lpfc_param_hex_show - Return a cfg attribute value in hex
1206 * Macro that given an attr e.g. hba_queue_depth expands
1207 * into a function with the name lpfc_hba_queue_depth_show
1209 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1210 * @dev: class device that is converted into a Scsi_host.
1211 * @attr: device attribute, not used.
1212 * @buf: on return contains the attribute value in hexadecimal.
1214 * Returns: size of formatted string.
1216 #define lpfc_param_hex_show(attr) \
1218 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1221 struct Scsi_Host *shost = class_to_shost(dev);\
1222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1223 struct lpfc_hba *phba = vport->phba;\
1225 val = phba->cfg_##attr;\
1226 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1231 * lpfc_param_init - Intializes a cfg attribute
1234 * Macro that given an attr e.g. hba_queue_depth expands
1235 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1236 * takes a default argument, a minimum and maximum argument.
1238 * lpfc_##attr##_init: Initializes an attribute.
1239 * @phba: pointer the the adapter structure.
1240 * @val: integer attribute value.
1242 * Validates the min and max values then sets the adapter config field
1243 * accordingly, or uses the default if out of range and prints an error message.
1247 * -EINVAL if default used
1249 #define lpfc_param_init(attr, default, minval, maxval) \
1251 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1253 if (val >= minval && val <= maxval) {\
1254 phba->cfg_##attr = val;\
1257 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1258 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1259 "allowed range is ["#minval", "#maxval"]\n", val); \
1260 phba->cfg_##attr = default;\
1265 * lpfc_param_set - Set a cfg attribute value
1268 * Macro that given an attr e.g. hba_queue_depth expands
1269 * into a function with the name lpfc_hba_queue_depth_set
1271 * lpfc_##attr##_set: Sets an attribute value.
1272 * @phba: pointer the the adapter structure.
1273 * @val: integer attribute value.
1276 * Validates the min and max values then sets the
1277 * adapter config field if in the valid range. prints error message
1278 * and does not set the parameter if invalid.
1282 * -EINVAL if val is invalid
1284 #define lpfc_param_set(attr, default, minval, maxval) \
1286 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1288 if (val >= minval && val <= maxval) {\
1289 phba->cfg_##attr = val;\
1292 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1293 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1294 "allowed range is ["#minval", "#maxval"]\n", val); \
1299 * lpfc_param_store - Set a vport attribute value
1302 * Macro that given an attr e.g. hba_queue_depth expands
1303 * into a function with the name lpfc_hba_queue_depth_store.
1305 * lpfc_##attr##_store: Set an sttribute value.
1306 * @dev: class device that is converted into a Scsi_host.
1307 * @attr: device attribute, not used.
1308 * @buf: contains the attribute value in ascii.
1312 * Convert the ascii text number to an integer, then
1313 * use the lpfc_##attr##_set function to set the value.
1316 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1317 * length of buffer upon success.
1319 #define lpfc_param_store(attr) \
1321 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1322 const char *buf, size_t count) \
1324 struct Scsi_Host *shost = class_to_shost(dev);\
1325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1326 struct lpfc_hba *phba = vport->phba;\
1328 if (!isdigit(buf[0]))\
1330 if (sscanf(buf, "%i", &val) != 1)\
1332 if (lpfc_##attr##_set(phba, val) == 0) \
1333 return strlen(buf);\
1339 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1342 * Macro that given an attr e.g. hba_queue_depth expands
1343 * into a function with the name lpfc_hba_queue_depth_show
1345 * lpfc_##attr##_show: prints the attribute value in decimal.
1346 * @dev: class device that is converted into a Scsi_host.
1347 * @attr: device attribute, not used.
1348 * @buf: on return contains the attribute value in decimal.
1350 * Returns: length of formatted string.
1352 #define lpfc_vport_param_show(attr) \
1354 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1357 struct Scsi_Host *shost = class_to_shost(dev);\
1358 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1360 val = vport->cfg_##attr;\
1361 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1365 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1368 * Macro that given an attr e.g.
1369 * hba_queue_depth expands into a function with the name
1370 * lpfc_hba_queue_depth_show
1372 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1373 * @dev: class device that is converted into a Scsi_host.
1374 * @attr: device attribute, not used.
1375 * @buf: on return contains the attribute value in hexadecimal.
1377 * Returns: length of formatted string.
1379 #define lpfc_vport_param_hex_show(attr) \
1381 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1384 struct Scsi_Host *shost = class_to_shost(dev);\
1385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1387 val = vport->cfg_##attr;\
1388 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1392 * lpfc_vport_param_init - Initialize a vport cfg attribute
1395 * Macro that given an attr e.g. hba_queue_depth expands
1396 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1397 * takes a default argument, a minimum and maximum argument.
1399 * lpfc_##attr##_init: validates the min and max values then sets the
1400 * adapter config field accordingly, or uses the default if out of range
1401 * and prints an error message.
1402 * @phba: pointer the the adapter structure.
1403 * @val: integer attribute value.
1407 * -EINVAL if default used
1409 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1411 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1413 if (val >= minval && val <= maxval) {\
1414 vport->cfg_##attr = val;\
1417 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1418 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1419 "allowed range is ["#minval", "#maxval"]\n", val); \
1420 vport->cfg_##attr = default;\
1425 * lpfc_vport_param_set - Set a vport cfg attribute
1428 * Macro that given an attr e.g. hba_queue_depth expands
1429 * into a function with the name lpfc_hba_queue_depth_set
1431 * lpfc_##attr##_set: validates the min and max values then sets the
1432 * adapter config field if in the valid range. prints error message
1433 * and does not set the parameter if invalid.
1434 * @phba: pointer the the adapter structure.
1435 * @val: integer attribute value.
1439 * -EINVAL if val is invalid
1441 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1443 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1445 if (val >= minval && val <= maxval) {\
1446 vport->cfg_##attr = val;\
1449 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1450 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1451 "allowed range is ["#minval", "#maxval"]\n", val); \
1456 * lpfc_vport_param_store - Set a vport attribute
1459 * Macro that given an attr e.g. hba_queue_depth
1460 * expands into a function with the name lpfc_hba_queue_depth_store
1462 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1463 * use the lpfc_##attr##_set function to set the value.
1464 * @cdev: class device that is converted into a Scsi_host.
1465 * @buf: contains the attribute value in decimal.
1469 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1470 * length of buffer upon success.
1472 #define lpfc_vport_param_store(attr) \
1474 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1475 const char *buf, size_t count) \
1477 struct Scsi_Host *shost = class_to_shost(dev);\
1478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1480 if (!isdigit(buf[0]))\
1482 if (sscanf(buf, "%i", &val) != 1)\
1484 if (lpfc_##attr##_set(vport, val) == 0) \
1485 return strlen(buf);\
1491 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1492 static int lpfc_##name = defval;\
1493 module_param(lpfc_##name, int, 0);\
1494 MODULE_PARM_DESC(lpfc_##name, desc);\
1495 lpfc_param_init(name, defval, minval, maxval)
1497 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1498 static int lpfc_##name = defval;\
1499 module_param(lpfc_##name, int, 0);\
1500 MODULE_PARM_DESC(lpfc_##name, desc);\
1501 lpfc_param_show(name)\
1502 lpfc_param_init(name, defval, minval, maxval)\
1503 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1505 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1506 static int lpfc_##name = defval;\
1507 module_param(lpfc_##name, int, 0);\
1508 MODULE_PARM_DESC(lpfc_##name, desc);\
1509 lpfc_param_show(name)\
1510 lpfc_param_init(name, defval, minval, maxval)\
1511 lpfc_param_set(name, defval, minval, maxval)\
1512 lpfc_param_store(name)\
1513 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1514 lpfc_##name##_show, lpfc_##name##_store)
1516 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1517 static int lpfc_##name = defval;\
1518 module_param(lpfc_##name, int, 0);\
1519 MODULE_PARM_DESC(lpfc_##name, desc);\
1520 lpfc_param_hex_show(name)\
1521 lpfc_param_init(name, defval, minval, maxval)\
1522 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1524 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1525 static int lpfc_##name = defval;\
1526 module_param(lpfc_##name, int, 0);\
1527 MODULE_PARM_DESC(lpfc_##name, desc);\
1528 lpfc_param_hex_show(name)\
1529 lpfc_param_init(name, defval, minval, maxval)\
1530 lpfc_param_set(name, defval, minval, maxval)\
1531 lpfc_param_store(name)\
1532 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1533 lpfc_##name##_show, lpfc_##name##_store)
1535 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1536 static int lpfc_##name = defval;\
1537 module_param(lpfc_##name, int, 0);\
1538 MODULE_PARM_DESC(lpfc_##name, desc);\
1539 lpfc_vport_param_init(name, defval, minval, maxval)
1541 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1542 static int lpfc_##name = defval;\
1543 module_param(lpfc_##name, int, 0);\
1544 MODULE_PARM_DESC(lpfc_##name, desc);\
1545 lpfc_vport_param_show(name)\
1546 lpfc_vport_param_init(name, defval, minval, maxval)\
1547 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1549 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1550 static int lpfc_##name = defval;\
1551 module_param(lpfc_##name, int, 0);\
1552 MODULE_PARM_DESC(lpfc_##name, desc);\
1553 lpfc_vport_param_show(name)\
1554 lpfc_vport_param_init(name, defval, minval, maxval)\
1555 lpfc_vport_param_set(name, defval, minval, maxval)\
1556 lpfc_vport_param_store(name)\
1557 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1558 lpfc_##name##_show, lpfc_##name##_store)
1560 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1561 static int lpfc_##name = defval;\
1562 module_param(lpfc_##name, int, 0);\
1563 MODULE_PARM_DESC(lpfc_##name, desc);\
1564 lpfc_vport_param_hex_show(name)\
1565 lpfc_vport_param_init(name, defval, minval, maxval)\
1566 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1568 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1569 static int lpfc_##name = defval;\
1570 module_param(lpfc_##name, int, 0);\
1571 MODULE_PARM_DESC(lpfc_##name, desc);\
1572 lpfc_vport_param_hex_show(name)\
1573 lpfc_vport_param_init(name, defval, minval, maxval)\
1574 lpfc_vport_param_set(name, defval, minval, maxval)\
1575 lpfc_vport_param_store(name)\
1576 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1577 lpfc_##name##_show, lpfc_##name##_store)
1579 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1580 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1581 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1582 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1583 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1584 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1585 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1586 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1587 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1588 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1589 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1590 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1591 static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
1592 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1593 lpfc_option_rom_version_show, NULL);
1594 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1595 lpfc_num_discovered_ports_show, NULL);
1596 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1597 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1598 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1599 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1600 lpfc_board_mode_show, lpfc_board_mode_store);
1601 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1602 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1603 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1604 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1605 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1606 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1607 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1608 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1609 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1612 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1615 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1616 * @dev: class device that is converted into a Scsi_host.
1617 * @attr: device attribute, not used.
1618 * @buf: containing the string lpfc_soft_wwn_key.
1619 * @count: must be size of lpfc_soft_wwn_key.
1622 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1623 * length of buf indicates success
1626 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1627 const char *buf, size_t count)
1629 struct Scsi_Host *shost = class_to_shost(dev);
1630 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1631 struct lpfc_hba *phba = vport->phba;
1632 unsigned int cnt = count;
1635 * We're doing a simple sanity check for soft_wwpn setting.
1636 * We require that the user write a specific key to enable
1637 * the soft_wwpn attribute to be settable. Once the attribute
1638 * is written, the enable key resets. If further updates are
1639 * desired, the key must be written again to re-enable the
1642 * The "key" is not secret - it is a hardcoded string shown
1643 * here. The intent is to protect against the random user or
1644 * application that is just writing attributes.
1647 /* count may include a LF at end of string */
1648 if (buf[cnt-1] == '\n')
1651 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1652 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1655 phba->soft_wwn_enable = 1;
1658 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1659 lpfc_soft_wwn_enable_store);
1662 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1663 * @dev: class device that is converted into a Scsi_host.
1664 * @attr: device attribute, not used.
1665 * @buf: on return contains the wwpn in hexadecimal.
1667 * Returns: size of formatted string.
1670 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1673 struct Scsi_Host *shost = class_to_shost(dev);
1674 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1675 struct lpfc_hba *phba = vport->phba;
1677 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1678 (unsigned long long)phba->cfg_soft_wwpn);
1682 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1683 * @dev class device that is converted into a Scsi_host.
1684 * @attr: device attribute, not used.
1685 * @buf: contains the wwpn in hexadecimal.
1686 * @count: number of wwpn bytes in buf
1689 * -EACCES hba reset not enabled, adapter over temp
1690 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1691 * -EIO error taking adapter offline or online
1692 * value of count on success
1695 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1696 const char *buf, size_t count)
1698 struct Scsi_Host *shost = class_to_shost(dev);
1699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1700 struct lpfc_hba *phba = vport->phba;
1701 struct completion online_compl;
1702 int stat1=0, stat2=0;
1703 unsigned int i, j, cnt=count;
1706 if (!phba->cfg_enable_hba_reset)
1708 spin_lock_irq(&phba->hbalock);
1709 if (phba->over_temp_state == HBA_OVER_TEMP) {
1710 spin_unlock_irq(&phba->hbalock);
1713 spin_unlock_irq(&phba->hbalock);
1714 /* count may include a LF at end of string */
1715 if (buf[cnt-1] == '\n')
1718 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1719 ((cnt == 17) && (*buf++ != 'x')) ||
1720 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1723 phba->soft_wwn_enable = 0;
1725 memset(wwpn, 0, sizeof(wwpn));
1727 /* Validate and store the new name */
1728 for (i=0, j=0; i < 16; i++) {
1729 if ((*buf >= 'a') && (*buf <= 'f'))
1730 j = ((j << 4) | ((*buf++ -'a') + 10));
1731 else if ((*buf >= 'A') && (*buf <= 'F'))
1732 j = ((j << 4) | ((*buf++ -'A') + 10));
1733 else if ((*buf >= '0') && (*buf <= '9'))
1734 j = ((j << 4) | (*buf++ -'0'));
1738 wwpn[i/2] = j & 0xff;
1742 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1743 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1744 if (phba->cfg_soft_wwnn)
1745 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1747 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1748 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1750 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1753 "0463 lpfc_soft_wwpn attribute set failed to "
1754 "reinit adapter - %d\n", stat1);
1755 init_completion(&online_compl);
1756 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1757 wait_for_completion(&online_compl);
1759 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1760 "0464 lpfc_soft_wwpn attribute set failed to "
1761 "reinit adapter - %d\n", stat2);
1762 return (stat1 || stat2) ? -EIO : count;
1764 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1765 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1768 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1769 * @dev: class device that is converted into a Scsi_host.
1770 * @attr: device attribute, not used.
1771 * @buf: on return contains the wwnn in hexadecimal.
1773 * Returns: size of formatted string.
1776 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1779 struct Scsi_Host *shost = class_to_shost(dev);
1780 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1781 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1782 (unsigned long long)phba->cfg_soft_wwnn);
1786 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1787 * @cdev: class device that is converted into a Scsi_host.
1788 * @buf: contains the ww node name in hexadecimal.
1789 * @count: number of wwnn bytes in buf.
1792 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1793 * value of count on success
1796 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1797 const char *buf, size_t count)
1799 struct Scsi_Host *shost = class_to_shost(dev);
1800 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1801 unsigned int i, j, cnt=count;
1804 /* count may include a LF at end of string */
1805 if (buf[cnt-1] == '\n')
1808 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1809 ((cnt == 17) && (*buf++ != 'x')) ||
1810 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1814 * Allow wwnn to be set many times, as long as the enable is set.
1815 * However, once the wwpn is set, everything locks.
1818 memset(wwnn, 0, sizeof(wwnn));
1820 /* Validate and store the new name */
1821 for (i=0, j=0; i < 16; i++) {
1822 if ((*buf >= 'a') && (*buf <= 'f'))
1823 j = ((j << 4) | ((*buf++ -'a') + 10));
1824 else if ((*buf >= 'A') && (*buf <= 'F'))
1825 j = ((j << 4) | ((*buf++ -'A') + 10));
1826 else if ((*buf >= '0') && (*buf <= '9'))
1827 j = ((j << 4) | (*buf++ -'0'));
1831 wwnn[i/2] = j & 0xff;
1835 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1837 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1838 "lpfc%d: soft_wwnn set. Value will take effect upon "
1839 "setting of the soft_wwpn\n", phba->brd_no);
1843 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1844 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1847 static int lpfc_poll = 0;
1848 module_param(lpfc_poll, int, 0);
1849 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1851 " 1 - poll with interrupts enabled"
1852 " 3 - poll and disable FCP ring interrupts");
1854 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1855 lpfc_poll_show, lpfc_poll_store);
1857 int lpfc_sli_mode = 0;
1858 module_param(lpfc_sli_mode, int, 0);
1859 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1860 " 0 - auto (SLI-3 if supported),"
1861 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1862 " 3 - select SLI-3");
1864 int lpfc_enable_npiv = 0;
1865 module_param(lpfc_enable_npiv, int, 0);
1866 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1867 lpfc_param_show(enable_npiv);
1868 lpfc_param_init(enable_npiv, 0, 0, 1);
1869 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1870 lpfc_enable_npiv_show, NULL);
1873 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1874 # until the timer expires. Value range is [0,255]. Default value is 30.
1876 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1877 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1878 module_param(lpfc_nodev_tmo, int, 0);
1879 MODULE_PARM_DESC(lpfc_nodev_tmo,
1880 "Seconds driver will hold I/O waiting "
1881 "for a device to come back");
1884 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
1885 * @dev: class converted to a Scsi_host structure.
1886 * @attr: device attribute, not used.
1887 * @buf: on return contains the dev loss timeout in decimal.
1889 * Returns: size of formatted string.
1892 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1895 struct Scsi_Host *shost = class_to_shost(dev);
1896 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1898 val = vport->cfg_devloss_tmo;
1899 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1903 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
1904 * @vport: lpfc vport structure pointer.
1905 * @val: contains the nodev timeout value.
1908 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1909 * a kernel error message is printed and zero is returned.
1910 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1911 * Otherwise nodev tmo is set to the default value.
1914 * zero if already set or if val is in range
1915 * -EINVAL val out of range
1918 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1920 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1921 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1922 if (val != LPFC_DEF_DEVLOSS_TMO)
1923 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1924 "0407 Ignoring nodev_tmo module "
1925 "parameter because devloss_tmo is "
1930 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1931 vport->cfg_nodev_tmo = val;
1932 vport->cfg_devloss_tmo = val;
1935 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1936 "0400 lpfc_nodev_tmo attribute cannot be set to"
1937 " %d, allowed range is [%d, %d]\n",
1938 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1939 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1944 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
1945 * @vport: lpfc vport structure pointer.
1948 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1951 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1953 struct Scsi_Host *shost;
1954 struct lpfc_nodelist *ndlp;
1956 shost = lpfc_shost_from_vport(vport);
1957 spin_lock_irq(shost->host_lock);
1958 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1959 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
1960 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1961 spin_unlock_irq(shost->host_lock);
1965 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
1966 * @vport: lpfc vport structure pointer.
1967 * @val: contains the tmo value.
1970 * If the devloss tmo is already set or the vport dev loss tmo has changed
1971 * then a kernel error message is printed and zero is returned.
1972 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1973 * Otherwise nodev tmo is set to the default value.
1976 * zero if already set or if val is in range
1977 * -EINVAL val out of range
1980 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
1982 if (vport->dev_loss_tmo_changed ||
1983 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
1984 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1985 "0401 Ignoring change to nodev_tmo "
1986 "because devloss_tmo is set.\n");
1989 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1990 vport->cfg_nodev_tmo = val;
1991 vport->cfg_devloss_tmo = val;
1992 lpfc_update_rport_devloss_tmo(vport);
1995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1996 "0403 lpfc_nodev_tmo attribute cannot be set to"
1997 "%d, allowed range is [%d, %d]\n",
1998 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2002 lpfc_vport_param_store(nodev_tmo)
2004 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2005 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2008 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2009 # disappear until the timer expires. Value range is [0,255]. Default
2012 module_param(lpfc_devloss_tmo, int, 0);
2013 MODULE_PARM_DESC(lpfc_devloss_tmo,
2014 "Seconds driver will hold I/O waiting "
2015 "for a device to come back");
2016 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2017 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2018 lpfc_vport_param_show(devloss_tmo)
2021 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2022 * @vport: lpfc vport structure pointer.
2023 * @val: contains the tmo value.
2026 * If val is in a valid range then set the vport nodev tmo,
2027 * devloss tmo, also set the vport dev loss tmo changed flag.
2028 * Else a kernel error message is printed.
2031 * zero if val is in range
2032 * -EINVAL val out of range
2035 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2037 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2038 vport->cfg_nodev_tmo = val;
2039 vport->cfg_devloss_tmo = val;
2040 vport->dev_loss_tmo_changed = 1;
2041 lpfc_update_rport_devloss_tmo(vport);
2045 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2046 "0404 lpfc_devloss_tmo attribute cannot be set to"
2047 " %d, allowed range is [%d, %d]\n",
2048 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2052 lpfc_vport_param_store(devloss_tmo)
2053 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2054 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2057 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2058 # deluged with LOTS of information.
2059 # You can set a bit mask to record specific types of verbose messages:
2060 # See lpfc_logmsh.h for definitions.
2062 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2063 "Verbose logging bit-mask");
2066 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2067 # objects that have been registered with the nameserver after login.
2069 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2070 "Deregister nameserver objects before LOGO");
2073 # lun_queue_depth: This parameter is used to limit the number of outstanding
2074 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2076 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2077 "Max number of FCP commands we can queue to a specific LUN");
2080 # hba_queue_depth: This parameter is used to limit the number of outstanding
2081 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2082 # value is greater than the maximum number of exchanges supported by the HBA,
2083 # then maximum number of exchanges supported by the HBA is used to determine
2084 # the hba_queue_depth.
2086 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2087 "Max number of FCP commands we can queue to a lpfc HBA");
2090 # peer_port_login: This parameter allows/prevents logins
2091 # between peer ports hosted on the same physical port.
2092 # When this parameter is set 0 peer ports of same physical port
2093 # are not allowed to login to each other.
2094 # When this parameter is set 1 peer ports of same physical port
2095 # are allowed to login to each other.
2096 # Default value of this parameter is 0.
2098 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2099 "Allow peer ports on the same physical port to login to each "
2103 # restrict_login: This parameter allows/prevents logins
2104 # between Virtual Ports and remote initiators.
2105 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2106 # other initiators and will attempt to PLOGI all remote ports.
2107 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2108 # remote ports and will not attempt to PLOGI to other initiators.
2109 # This parameter does not restrict to the physical port.
2110 # This parameter does not restrict logins to Fabric resident remote ports.
2111 # Default value of this parameter is 1.
2113 static int lpfc_restrict_login = 1;
2114 module_param(lpfc_restrict_login, int, 0);
2115 MODULE_PARM_DESC(lpfc_restrict_login,
2116 "Restrict virtual ports login to remote initiators.");
2117 lpfc_vport_param_show(restrict_login);
2120 * lpfc_restrict_login_init - Set the vport restrict login flag
2121 * @vport: lpfc vport structure pointer.
2122 * @val: contains the restrict login value.
2125 * If val is not in a valid range then log a kernel error message and set
2126 * the vport restrict login to one.
2127 * If the port type is physical clear the restrict login flag and return.
2128 * Else set the restrict login flag to val.
2131 * zero if val is in range
2132 * -EINVAL val out of range
2135 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2137 if (val < 0 || val > 1) {
2138 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2139 "0422 lpfc_restrict_login attribute cannot "
2140 "be set to %d, allowed range is [0, 1]\n",
2142 vport->cfg_restrict_login = 1;
2145 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2146 vport->cfg_restrict_login = 0;
2149 vport->cfg_restrict_login = val;
2154 * lpfc_restrict_login_set - Set the vport restrict login flag
2155 * @vport: lpfc vport structure pointer.
2156 * @val: contains the restrict login value.
2159 * If val is not in a valid range then log a kernel error message and set
2160 * the vport restrict login to one.
2161 * If the port type is physical and the val is not zero log a kernel
2162 * error message, clear the restrict login flag and return zero.
2163 * Else set the restrict login flag to val.
2166 * zero if val is in range
2167 * -EINVAL val out of range
2170 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2172 if (val < 0 || val > 1) {
2173 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2174 "0425 lpfc_restrict_login attribute cannot "
2175 "be set to %d, allowed range is [0, 1]\n",
2177 vport->cfg_restrict_login = 1;
2180 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2181 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2182 "0468 lpfc_restrict_login must be 0 for "
2183 "Physical ports.\n");
2184 vport->cfg_restrict_login = 0;
2187 vport->cfg_restrict_login = val;
2190 lpfc_vport_param_store(restrict_login);
2191 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2192 lpfc_restrict_login_show, lpfc_restrict_login_store);
2195 # Some disk devices have a "select ID" or "select Target" capability.
2196 # From a protocol standpoint "select ID" usually means select the
2197 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2198 # annex" which contains a table that maps a "select ID" (a number
2199 # between 0 and 7F) to an ALPA. By default, for compatibility with
2200 # older drivers, the lpfc driver scans this table from low ALPA to high
2203 # Turning on the scan-down variable (on = 1, off = 0) will
2204 # cause the lpfc driver to use an inverted table, effectively
2205 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2207 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2208 # and will not work across a fabric. Also this parameter will take
2209 # effect only in the case when ALPA map is not available.)
2211 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2212 "Start scanning for devices from highest ALPA to lowest");
2215 # lpfc_topology: link topology for init link
2216 # 0x0 = attempt loop mode then point-to-point
2217 # 0x01 = internal loopback mode
2218 # 0x02 = attempt point-to-point mode only
2219 # 0x04 = attempt loop mode only
2220 # 0x06 = attempt point-to-point mode then loop
2221 # Set point-to-point mode if you want to run as an N_Port.
2222 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2223 # Default value is 0.
2227 * lpfc_topology_set - Set the adapters topology field
2228 * @phba: lpfc_hba pointer.
2229 * @val: topology value.
2232 * If val is in a valid range then set the adapter's topology field and
2233 * issue a lip; if the lip fails reset the topology to the old value.
2235 * If the value is not in range log a kernel error message and return an error.
2238 * zero if val is in range and lip okay
2239 * non-zero return value from lpfc_issue_lip()
2240 * -EINVAL val out of range
2243 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2244 const char *buf, size_t count)
2246 struct Scsi_Host *shost = class_to_shost(dev);
2247 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2248 struct lpfc_hba *phba = vport->phba;
2251 const char *val_buf = buf;
2255 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2257 val_buf = &buf[strlen("nolip ")];
2260 if (!isdigit(val_buf[0]))
2262 if (sscanf(val_buf, "%i", &val) != 1)
2265 if (val >= 0 && val <= 6) {
2266 prev_val = phba->cfg_topology;
2267 phba->cfg_topology = val;
2271 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2273 phba->cfg_topology = prev_val;
2278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2279 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2280 "allowed range is [0, 6]\n",
2284 static int lpfc_topology = 0;
2285 module_param(lpfc_topology, int, 0);
2286 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2287 lpfc_param_show(topology)
2288 lpfc_param_init(topology, 0, 0, 6)
2289 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2290 lpfc_topology_show, lpfc_topology_store);
2293 * lpfc_static_vport_show: Read callback function for
2294 * lpfc_static_vport sysfs file.
2295 * @dev: Pointer to class device object.
2296 * @attr: device attribute structure.
2297 * @buf: Data buffer.
2299 * This function is the read call back function for
2300 * lpfc_static_vport sysfs file. The lpfc_static_vport
2301 * sysfs file report the mageability of the vport.
2304 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2307 struct Scsi_Host *shost = class_to_shost(dev);
2308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2309 if (vport->vport_flag & STATIC_VPORT)
2310 sprintf(buf, "1\n");
2312 sprintf(buf, "0\n");
2318 * Sysfs attribute to control the statistical data collection.
2320 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2321 lpfc_static_vport_show, NULL);
2324 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2325 * @dev: Pointer to class device.
2326 * @buf: Data buffer.
2327 * @count: Size of the data buffer.
2329 * This function get called when an user write to the lpfc_stat_data_ctrl
2330 * sysfs file. This function parse the command written to the sysfs file
2331 * and take appropriate action. These commands are used for controlling
2332 * driver statistical data collection.
2333 * Following are the command this function handles.
2335 * setbucket <bucket_type> <base> <step>
2336 * = Set the latency buckets.
2337 * destroybucket = destroy all the buckets.
2338 * start = start data collection
2339 * stop = stop data collection
2340 * reset = reset the collected data
2343 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2344 const char *buf, size_t count)
2346 struct Scsi_Host *shost = class_to_shost(dev);
2347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2348 struct lpfc_hba *phba = vport->phba;
2349 #define LPFC_MAX_DATA_CTRL_LEN 1024
2350 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2352 char *str_ptr, *token;
2353 struct lpfc_vport **vports;
2354 struct Scsi_Host *v_shost;
2355 char *bucket_type_str, *base_str, *step_str;
2356 unsigned long base, step, bucket_type;
2358 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2359 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2362 strcpy(bucket_data, buf);
2363 str_ptr = &bucket_data[0];
2364 /* Ignore this token - this is command token */
2365 token = strsep(&str_ptr, "\t ");
2369 bucket_type_str = strsep(&str_ptr, "\t ");
2370 if (!bucket_type_str)
2373 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2374 bucket_type = LPFC_LINEAR_BUCKET;
2375 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2376 bucket_type = LPFC_POWER2_BUCKET;
2380 base_str = strsep(&str_ptr, "\t ");
2383 base = simple_strtoul(base_str, NULL, 0);
2385 step_str = strsep(&str_ptr, "\t ");
2388 step = simple_strtoul(step_str, NULL, 0);
2392 /* Block the data collection for every vport */
2393 vports = lpfc_create_vport_work_array(phba);
2397 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2398 v_shost = lpfc_shost_from_vport(vports[i]);
2399 spin_lock_irq(v_shost->host_lock);
2400 /* Block and reset data collection */
2401 vports[i]->stat_data_blocked = 1;
2402 if (vports[i]->stat_data_enabled)
2403 lpfc_vport_reset_stat_data(vports[i]);
2404 spin_unlock_irq(v_shost->host_lock);
2407 /* Set the bucket attributes */
2408 phba->bucket_type = bucket_type;
2409 phba->bucket_base = base;
2410 phba->bucket_step = step;
2412 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2413 v_shost = lpfc_shost_from_vport(vports[i]);
2415 /* Unblock data collection */
2416 spin_lock_irq(v_shost->host_lock);
2417 vports[i]->stat_data_blocked = 0;
2418 spin_unlock_irq(v_shost->host_lock);
2420 lpfc_destroy_vport_work_array(phba, vports);
2424 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2425 vports = lpfc_create_vport_work_array(phba);
2429 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2430 v_shost = lpfc_shost_from_vport(vports[i]);
2431 spin_lock_irq(shost->host_lock);
2432 vports[i]->stat_data_blocked = 1;
2433 lpfc_free_bucket(vport);
2434 vport->stat_data_enabled = 0;
2435 vports[i]->stat_data_blocked = 0;
2436 spin_unlock_irq(shost->host_lock);
2438 lpfc_destroy_vport_work_array(phba, vports);
2439 phba->bucket_type = LPFC_NO_BUCKET;
2440 phba->bucket_base = 0;
2441 phba->bucket_step = 0;
2445 if (!strncmp(buf, "start", strlen("start"))) {
2446 /* If no buckets configured return error */
2447 if (phba->bucket_type == LPFC_NO_BUCKET)
2449 spin_lock_irq(shost->host_lock);
2450 if (vport->stat_data_enabled) {
2451 spin_unlock_irq(shost->host_lock);
2454 lpfc_alloc_bucket(vport);
2455 vport->stat_data_enabled = 1;
2456 spin_unlock_irq(shost->host_lock);
2460 if (!strncmp(buf, "stop", strlen("stop"))) {
2461 spin_lock_irq(shost->host_lock);
2462 if (vport->stat_data_enabled == 0) {
2463 spin_unlock_irq(shost->host_lock);
2466 lpfc_free_bucket(vport);
2467 vport->stat_data_enabled = 0;
2468 spin_unlock_irq(shost->host_lock);
2472 if (!strncmp(buf, "reset", strlen("reset"))) {
2473 if ((phba->bucket_type == LPFC_NO_BUCKET)
2474 || !vport->stat_data_enabled)
2476 spin_lock_irq(shost->host_lock);
2477 vport->stat_data_blocked = 1;
2478 lpfc_vport_reset_stat_data(vport);
2479 vport->stat_data_blocked = 0;
2480 spin_unlock_irq(shost->host_lock);
2488 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2489 * @dev: Pointer to class device object.
2490 * @buf: Data buffer.
2492 * This function is the read call back function for
2493 * lpfc_stat_data_ctrl sysfs file. This function report the
2494 * current statistical data collection state.
2497 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2500 struct Scsi_Host *shost = class_to_shost(dev);
2501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2502 struct lpfc_hba *phba = vport->phba;
2506 unsigned long bucket_value;
2508 switch (phba->bucket_type) {
2509 case LPFC_LINEAR_BUCKET:
2510 bucket_type = "linear";
2512 case LPFC_POWER2_BUCKET:
2513 bucket_type = "power2";
2516 bucket_type = "No Bucket";
2520 sprintf(&buf[index], "Statistical Data enabled :%d, "
2521 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2522 " Bucket step :%d\nLatency Ranges :",
2523 vport->stat_data_enabled, vport->stat_data_blocked,
2524 bucket_type, phba->bucket_base, phba->bucket_step);
2525 index = strlen(buf);
2526 if (phba->bucket_type != LPFC_NO_BUCKET) {
2527 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2528 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2529 bucket_value = phba->bucket_base +
2530 phba->bucket_step * i;
2532 bucket_value = phba->bucket_base +
2533 (1 << i) * phba->bucket_step;
2535 if (index + 10 > PAGE_SIZE)
2537 sprintf(&buf[index], "%08ld ", bucket_value);
2538 index = strlen(buf);
2541 sprintf(&buf[index], "\n");
2546 * Sysfs attribute to control the statistical data collection.
2548 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2549 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2552 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2556 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2559 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2560 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2561 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2565 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2566 * @kobj: Pointer to the kernel object
2567 * @bin_attr: Attribute object
2568 * @buff: Buffer pointer
2570 * @count: Buffer size
2572 * This function is the read call back function for lpfc_drvr_stat_data
2573 * sysfs file. This function export the statistical data to user
2577 sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2578 char *buf, loff_t off, size_t count)
2580 struct device *dev = container_of(kobj, struct device,
2582 struct Scsi_Host *shost = class_to_shost(dev);
2583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2584 struct lpfc_hba *phba = vport->phba;
2585 int i = 0, index = 0;
2586 unsigned long nport_index;
2587 struct lpfc_nodelist *ndlp = NULL;
2588 nport_index = (unsigned long)off /
2589 MAX_STAT_DATA_SIZE_PER_TARGET;
2591 if (!vport->stat_data_enabled || vport->stat_data_blocked
2592 || (phba->bucket_type == LPFC_NO_BUCKET))
2595 spin_lock_irq(shost->host_lock);
2596 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2597 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2600 if (nport_index > 0) {
2605 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2609 if (!ndlp->lat_data)
2613 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2614 ndlp->nlp_portname.u.wwn[0],
2615 ndlp->nlp_portname.u.wwn[1],
2616 ndlp->nlp_portname.u.wwn[2],
2617 ndlp->nlp_portname.u.wwn[3],
2618 ndlp->nlp_portname.u.wwn[4],
2619 ndlp->nlp_portname.u.wwn[5],
2620 ndlp->nlp_portname.u.wwn[6],
2621 ndlp->nlp_portname.u.wwn[7]);
2623 index = strlen(buf);
2625 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2626 sprintf(&buf[index], "%010u,",
2627 ndlp->lat_data[i].cmd_count);
2628 index = strlen(buf);
2630 sprintf(&buf[index], "\n");
2631 index = strlen(buf);
2633 spin_unlock_irq(shost->host_lock);
2637 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2639 .name = "lpfc_drvr_stat_data",
2641 .owner = THIS_MODULE,
2643 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2644 .read = sysfs_drvr_stat_data_read,
2649 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2651 # 0 = auto select (default)
2656 # Value range is [0,8]. Default value is 0.
2660 * lpfc_link_speed_set - Set the adapters link speed
2661 * @phba: lpfc_hba pointer.
2662 * @val: link speed value.
2665 * If val is in a valid range then set the adapter's link speed field and
2666 * issue a lip; if the lip fails reset the link speed to the old value.
2669 * If the value is not in range log a kernel error message and return an error.
2672 * zero if val is in range and lip okay.
2673 * non-zero return value from lpfc_issue_lip()
2674 * -EINVAL val out of range
2677 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2678 const char *buf, size_t count)
2680 struct Scsi_Host *shost = class_to_shost(dev);
2681 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2682 struct lpfc_hba *phba = vport->phba;
2685 const char *val_buf = buf;
2689 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2691 val_buf = &buf[strlen("nolip ")];
2694 if (!isdigit(val_buf[0]))
2696 if (sscanf(val_buf, "%i", &val) != 1)
2699 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2700 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2701 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2702 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2703 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2706 if ((val >= 0 && val <= 8)
2707 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2708 prev_val = phba->cfg_link_speed;
2709 phba->cfg_link_speed = val;
2713 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2715 phba->cfg_link_speed = prev_val;
2721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2722 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2723 "allowed range is [0, 8]\n",
2728 static int lpfc_link_speed = 0;
2729 module_param(lpfc_link_speed, int, 0);
2730 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2731 lpfc_param_show(link_speed)
2734 * lpfc_link_speed_init - Set the adapters link speed
2735 * @phba: lpfc_hba pointer.
2736 * @val: link speed value.
2739 * If val is in a valid range then set the adapter's link speed field.
2742 * If the value is not in range log a kernel error message, clear the link
2743 * speed and return an error.
2746 * zero if val saved.
2747 * -EINVAL val out of range
2750 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2752 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2753 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2754 phba->cfg_link_speed = val;
2757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2758 "0405 lpfc_link_speed attribute cannot "
2759 "be set to %d, allowed values are "
2760 "["LPFC_LINK_SPEED_STRING"]\n", val);
2761 phba->cfg_link_speed = 0;
2765 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2766 lpfc_link_speed_show, lpfc_link_speed_store);
2769 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2770 # Value range is [2,3]. Default value is 3.
2772 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2773 "Select Fibre Channel class of service for FCP sequences");
2776 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2777 # is [0,1]. Default value is 0.
2779 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2780 "Use ADISC on rediscovery to authenticate FCP devices");
2783 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2784 # depth. Default value is 0. When the value of this parameter is zero the
2785 # SCSI command completion time is not used for controlling I/O queue depth. When
2786 # the parameter is set to a non-zero value, the I/O queue depth is controlled
2787 # to limit the I/O completion time to the parameter value.
2788 # The value is set in milliseconds.
2790 static int lpfc_max_scsicmpl_time;
2791 module_param(lpfc_max_scsicmpl_time, int, 0);
2792 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2793 "Use command completion time to control queue depth");
2794 lpfc_vport_param_show(max_scsicmpl_time);
2795 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2797 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2800 struct lpfc_nodelist *ndlp, *next_ndlp;
2802 if (val == vport->cfg_max_scsicmpl_time)
2804 if ((val < 0) || (val > 60000))
2806 vport->cfg_max_scsicmpl_time = val;
2808 spin_lock_irq(shost->host_lock);
2809 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2810 if (!NLP_CHK_NODE_ACT(ndlp))
2812 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2814 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2816 spin_unlock_irq(shost->host_lock);
2819 lpfc_vport_param_store(max_scsicmpl_time);
2820 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2821 lpfc_max_scsicmpl_time_show,
2822 lpfc_max_scsicmpl_time_store);
2825 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2826 # range is [0,1]. Default value is 0.
2828 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2831 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2832 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
2833 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
2834 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2835 # cr_delay is set to 0.
2837 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
2838 "interrupt response is generated");
2840 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
2841 "interrupt response is generated");
2844 # lpfc_multi_ring_support: Determines how many rings to spread available
2845 # cmd/rsp IOCB entries across.
2846 # Value range is [1,2]. Default value is 1.
2848 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2849 "SLI rings to spread IOCB entries across");
2852 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2853 # identifies what rctl value to configure the additional ring for.
2854 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2856 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
2857 255, "Identifies RCTL for additional ring configuration");
2860 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2861 # identifies what type value to configure the additional ring for.
2862 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2864 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
2865 255, "Identifies TYPE for additional ring configuration");
2868 # lpfc_fdmi_on: controls FDMI support.
2869 # 0 = no FDMI support
2870 # 1 = support FDMI without attribute of hostname
2871 # 2 = support FDMI with attribute of hostname
2872 # Value range [0,2]. Default value is 0.
2874 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
2877 # Specifies the maximum number of ELS cmds we can have outstanding (for
2878 # discovery). Value range is [1,64]. Default value = 32.
2880 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
2881 "during discovery");
2884 # lpfc_max_luns: maximum allowed LUN.
2885 # Value range is [0,65535]. Default value is 255.
2886 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
2888 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
2891 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2892 # Value range is [1,255], default value is 10.
2894 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2895 "Milliseconds driver will wait between polling FCP ring");
2898 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2899 # support this feature
2900 # 0 = MSI disabled (default)
2903 # Value range is [0,2]. Default value is 0.
2905 LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
2906 "MSI-X (2), if possible");
2909 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
2911 # Value range is [636,651042]. Default value is 10000.
2913 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
2914 "Set the maximum number of fast-path FCP interrupts per second");
2917 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
2919 # Value range is [1,31]. Default value is 4.
2921 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
2922 "Set the number of fast-path FCP work queues, if possible");
2925 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
2927 # Value range is [1,7]. Default value is 1.
2929 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
2930 "Set the number of fast-path FCP event queues, if possible");
2933 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2934 # 0 = HBA resets disabled
2935 # 1 = HBA resets enabled (default)
2936 # Value range is [0,1]. Default value is 1.
2938 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
2941 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2942 # 0 = HBA Heartbeat disabled
2943 # 1 = HBA Heartbeat enabled (default)
2944 # Value range is [0,1]. Default value is 1.
2946 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
2949 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
2950 # 0 = BlockGuard disabled (default)
2951 # 1 = BlockGuard enabled
2952 # Value range is [0,1]. Default value is 0.
2954 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
2957 # lpfc_enable_fip: When set, FIP is required to start discovery. If not
2958 # set, the driver will add an FCF record manually if the port has no
2959 # FCF records available and start discovery.
2960 # Value range is [0,1]. Default value is 1 (enabled)
2962 LPFC_ATTR_RW(enable_fip, 0, 0, 1, "Enable FIP Discovery");
2967 # - Bit mask of host protection capabilities used to register with the
2969 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
2970 # - Allows you to ultimately specify which profiles to use
2971 # - Default will result in registering capabilities for all profiles.
2974 unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
2976 module_param(lpfc_prot_mask, uint, 0);
2977 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
2980 # lpfc_prot_guard: i
2981 # - Bit mask of protection guard types to register with the SCSI mid-layer
2982 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
2983 # - Allows you to ultimately specify which profiles to use
2984 # - Default will result in registering capabilities for all guard types
2987 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
2988 module_param(lpfc_prot_guard, byte, 0);
2989 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
2993 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
2994 * This value can be set to values between 64 and 256. The default value is
2995 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2996 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2998 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2999 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3001 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3002 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3003 "Max Protection Scatter Gather Segment Count");
3005 struct device_attribute *lpfc_hba_attrs[] = {
3007 &dev_attr_bg_guard_err,
3008 &dev_attr_bg_apptag_err,
3009 &dev_attr_bg_reftag_err,
3011 &dev_attr_serialnum,
3012 &dev_attr_modeldesc,
3013 &dev_attr_modelname,
3014 &dev_attr_programtype,
3018 &dev_attr_option_rom_version,
3019 &dev_attr_link_state,
3020 &dev_attr_num_discovered_ports,
3021 &dev_attr_menlo_mgmt_mode,
3022 &dev_attr_lpfc_drvr_version,
3023 &dev_attr_lpfc_temp_sensor,
3024 &dev_attr_lpfc_log_verbose,
3025 &dev_attr_lpfc_lun_queue_depth,
3026 &dev_attr_lpfc_hba_queue_depth,
3027 &dev_attr_lpfc_peer_port_login,
3028 &dev_attr_lpfc_nodev_tmo,
3029 &dev_attr_lpfc_devloss_tmo,
3030 &dev_attr_lpfc_enable_fip,
3031 &dev_attr_lpfc_fcp_class,
3032 &dev_attr_lpfc_use_adisc,
3033 &dev_attr_lpfc_ack0,
3034 &dev_attr_lpfc_topology,
3035 &dev_attr_lpfc_scan_down,
3036 &dev_attr_lpfc_link_speed,
3037 &dev_attr_lpfc_cr_delay,
3038 &dev_attr_lpfc_cr_count,
3039 &dev_attr_lpfc_multi_ring_support,
3040 &dev_attr_lpfc_multi_ring_rctl,
3041 &dev_attr_lpfc_multi_ring_type,
3042 &dev_attr_lpfc_fdmi_on,
3043 &dev_attr_lpfc_max_luns,
3044 &dev_attr_lpfc_enable_npiv,
3045 &dev_attr_nport_evt_cnt,
3046 &dev_attr_board_mode,
3053 &dev_attr_npiv_info,
3054 &dev_attr_issue_reset,
3055 &dev_attr_lpfc_poll,
3056 &dev_attr_lpfc_poll_tmo,
3057 &dev_attr_lpfc_use_msi,
3058 &dev_attr_lpfc_fcp_imax,
3059 &dev_attr_lpfc_fcp_wq_count,
3060 &dev_attr_lpfc_fcp_eq_count,
3061 &dev_attr_lpfc_enable_bg,
3062 &dev_attr_lpfc_soft_wwnn,
3063 &dev_attr_lpfc_soft_wwpn,
3064 &dev_attr_lpfc_soft_wwn_enable,
3065 &dev_attr_lpfc_enable_hba_reset,
3066 &dev_attr_lpfc_enable_hba_heartbeat,
3067 &dev_attr_lpfc_sg_seg_cnt,
3068 &dev_attr_lpfc_max_scsicmpl_time,
3069 &dev_attr_lpfc_stat_data_ctrl,
3070 &dev_attr_lpfc_prot_sg_seg_cnt,
3074 struct device_attribute *lpfc_vport_attrs[] = {
3076 &dev_attr_link_state,
3077 &dev_attr_num_discovered_ports,
3078 &dev_attr_lpfc_drvr_version,
3079 &dev_attr_lpfc_log_verbose,
3080 &dev_attr_lpfc_lun_queue_depth,
3081 &dev_attr_lpfc_nodev_tmo,
3082 &dev_attr_lpfc_devloss_tmo,
3083 &dev_attr_lpfc_enable_fip,
3084 &dev_attr_lpfc_hba_queue_depth,
3085 &dev_attr_lpfc_peer_port_login,
3086 &dev_attr_lpfc_restrict_login,
3087 &dev_attr_lpfc_fcp_class,
3088 &dev_attr_lpfc_use_adisc,
3089 &dev_attr_lpfc_fdmi_on,
3090 &dev_attr_lpfc_max_luns,
3091 &dev_attr_nport_evt_cnt,
3092 &dev_attr_npiv_info,
3093 &dev_attr_lpfc_enable_da_id,
3094 &dev_attr_lpfc_max_scsicmpl_time,
3095 &dev_attr_lpfc_stat_data_ctrl,
3096 &dev_attr_lpfc_static_vport,
3101 * sysfs_ctlreg_write - Write method for writing to ctlreg
3102 * @kobj: kernel kobject that contains the kernel class device.
3103 * @bin_attr: kernel attributes passed to us.
3104 * @buf: contains the data to be written to the adapter IOREG space.
3105 * @off: offset into buffer to beginning of data.
3106 * @count: bytes to transfer.
3109 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3110 * Uses the adapter io control registers to send buf contents to the adapter.
3113 * -ERANGE off and count combo out of range
3114 * -EINVAL off, count or buff address invalid
3115 * -EPERM adapter is offline
3116 * value of count, buf contents written
3119 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3120 char *buf, loff_t off, size_t count)
3123 struct device *dev = container_of(kobj, struct device, kobj);
3124 struct Scsi_Host *shost = class_to_shost(dev);
3125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3126 struct lpfc_hba *phba = vport->phba;
3128 if (phba->sli_rev >= LPFC_SLI_REV4)
3131 if ((off + count) > FF_REG_AREA_SIZE)
3134 if (count == 0) return 0;
3136 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3139 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3143 spin_lock_irq(&phba->hbalock);
3144 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3145 writel(*((uint32_t *)(buf + buf_off)),
3146 phba->ctrl_regs_memmap_p + off + buf_off);
3148 spin_unlock_irq(&phba->hbalock);
3154 * sysfs_ctlreg_read - Read method for reading from ctlreg
3155 * @kobj: kernel kobject that contains the kernel class device.
3156 * @bin_attr: kernel attributes passed to us.
3157 * @buf: if succesful contains the data from the adapter IOREG space.
3158 * @off: offset into buffer to beginning of data.
3159 * @count: bytes to transfer.
3162 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3163 * Uses the adapter io control registers to read data into buf.
3166 * -ERANGE off and count combo out of range
3167 * -EINVAL off, count or buff address invalid
3168 * value of count, buf contents read
3171 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3172 char *buf, loff_t off, size_t count)
3176 struct device *dev = container_of(kobj, struct device, kobj);
3177 struct Scsi_Host *shost = class_to_shost(dev);
3178 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3179 struct lpfc_hba *phba = vport->phba;
3181 if (phba->sli_rev >= LPFC_SLI_REV4)
3184 if (off > FF_REG_AREA_SIZE)
3187 if ((off + count) > FF_REG_AREA_SIZE)
3188 count = FF_REG_AREA_SIZE - off;
3190 if (count == 0) return 0;
3192 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3195 spin_lock_irq(&phba->hbalock);
3197 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3198 tmp_ptr = (uint32_t *)(buf + buf_off);
3199 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3202 spin_unlock_irq(&phba->hbalock);
3207 static struct bin_attribute sysfs_ctlreg_attr = {
3210 .mode = S_IRUSR | S_IWUSR,
3213 .read = sysfs_ctlreg_read,
3214 .write = sysfs_ctlreg_write,
3218 * sysfs_mbox_idle - frees the sysfs mailbox
3219 * @phba: lpfc_hba pointer
3222 sysfs_mbox_idle(struct lpfc_hba *phba)
3224 phba->sysfs_mbox.state = SMBOX_IDLE;
3225 phba->sysfs_mbox.offset = 0;
3227 if (phba->sysfs_mbox.mbox) {
3228 mempool_free(phba->sysfs_mbox.mbox,
3229 phba->mbox_mem_pool);
3230 phba->sysfs_mbox.mbox = NULL;
3235 * sysfs_mbox_write - Write method for writing information via mbox
3236 * @kobj: kernel kobject that contains the kernel class device.
3237 * @bin_attr: kernel attributes passed to us.
3238 * @buf: contains the data to be written to sysfs mbox.
3239 * @off: offset into buffer to beginning of data.
3240 * @count: bytes to transfer.
3243 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3244 * Uses the sysfs mbox to send buf contents to the adapter.
3247 * -ERANGE off and count combo out of range
3248 * -EINVAL off, count or buff address invalid
3249 * zero if count is zero
3250 * -EPERM adapter is offline
3251 * -ENOMEM failed to allocate memory for the mail box
3252 * -EAGAIN offset, state or mbox is NULL
3253 * count number of bytes transferred
3256 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3257 char *buf, loff_t off, size_t count)
3259 struct device *dev = container_of(kobj, struct device, kobj);
3260 struct Scsi_Host *shost = class_to_shost(dev);
3261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3262 struct lpfc_hba *phba = vport->phba;
3263 struct lpfcMboxq *mbox = NULL;
3265 if ((count + off) > MAILBOX_CMD_SIZE)
3268 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3275 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3278 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3281 spin_lock_irq(&phba->hbalock);
3284 if (phba->sysfs_mbox.mbox)
3285 mempool_free(mbox, phba->mbox_mem_pool);
3287 phba->sysfs_mbox.mbox = mbox;
3288 phba->sysfs_mbox.state = SMBOX_WRITING;
3290 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3291 phba->sysfs_mbox.offset != off ||
3292 phba->sysfs_mbox.mbox == NULL) {
3293 sysfs_mbox_idle(phba);
3294 spin_unlock_irq(&phba->hbalock);
3299 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3302 phba->sysfs_mbox.offset = off + count;
3304 spin_unlock_irq(&phba->hbalock);
3310 * sysfs_mbox_read - Read method for reading information via mbox
3311 * @kobj: kernel kobject that contains the kernel class device.
3312 * @bin_attr: kernel attributes passed to us.
3313 * @buf: contains the data to be read from sysfs mbox.
3314 * @off: offset into buffer to beginning of data.
3315 * @count: bytes to transfer.
3318 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3319 * Uses the sysfs mbox to receive data from to the adapter.
3322 * -ERANGE off greater than mailbox command size
3323 * -EINVAL off, count or buff address invalid
3324 * zero if off and count are zero
3325 * -EACCES adapter over temp
3326 * -EPERM garbage can value to catch a multitude of errors
3327 * -EAGAIN management IO not permitted, state or off error
3328 * -ETIME mailbox timeout
3329 * -ENODEV mailbox error
3330 * count number of bytes transferred
3333 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3334 char *buf, loff_t off, size_t count)
3336 struct device *dev = container_of(kobj, struct device, kobj);
3337 struct Scsi_Host *shost = class_to_shost(dev);
3338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3339 struct lpfc_hba *phba = vport->phba;
3343 if (off > MAILBOX_CMD_SIZE)
3346 if ((count + off) > MAILBOX_CMD_SIZE)
3347 count = MAILBOX_CMD_SIZE - off;
3349 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3352 if (off && count == 0)
3355 spin_lock_irq(&phba->hbalock);
3357 if (phba->over_temp_state == HBA_OVER_TEMP) {
3358 sysfs_mbox_idle(phba);
3359 spin_unlock_irq(&phba->hbalock);
3364 phba->sysfs_mbox.state == SMBOX_WRITING &&
3365 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3366 pmb = &phba->sysfs_mbox.mbox->u.mb;
3367 switch (pmb->mbxCommand) {
3371 case MBX_CONFIG_LINK:
3372 case MBX_CONFIG_RING:
3373 case MBX_RESET_RING:
3374 case MBX_UNREG_LOGIN:
3376 case MBX_DUMP_CONTEXT:
3381 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3382 printk(KERN_WARNING "mbox_read:Command 0x%x "
3383 "is illegal in on-line state\n",
3385 sysfs_mbox_idle(phba);
3386 spin_unlock_irq(&phba->hbalock);
3390 case MBX_WRITE_VPARMS:
3393 case MBX_READ_CONFIG:
3394 case MBX_READ_RCONFIG:
3395 case MBX_READ_STATUS:
3398 case MBX_READ_LNK_STAT:
3399 case MBX_DUMP_MEMORY:
3401 case MBX_UPDATE_CFG:
3402 case MBX_KILL_BOARD:
3404 case MBX_LOAD_EXP_ROM:
3406 case MBX_DEL_LD_ENTRY:
3407 case MBX_SET_VARIABLE:
3409 case MBX_PORT_CAPABILITIES:
3410 case MBX_PORT_IOV_CONTROL:
3412 case MBX_READ_SPARM64:
3416 case MBX_REG_LOGIN64:
3417 case MBX_CONFIG_PORT:
3418 case MBX_RUN_BIU_DIAG:
3419 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3421 sysfs_mbox_idle(phba);
3422 spin_unlock_irq(&phba->hbalock);
3425 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3427 sysfs_mbox_idle(phba);
3428 spin_unlock_irq(&phba->hbalock);
3432 /* If HBA encountered an error attention, allow only DUMP
3433 * or RESTART mailbox commands until the HBA is restarted.
3435 if (phba->pport->stopped &&
3436 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3437 pmb->mbxCommand != MBX_RESTART &&
3438 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3439 pmb->mbxCommand != MBX_WRITE_WWN)
3440 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3441 "1259 mbox: Issued mailbox cmd "
3442 "0x%x while in stopped state.\n",
3445 phba->sysfs_mbox.mbox->vport = vport;
3447 /* Don't allow mailbox commands to be sent when blocked
3448 * or when in the middle of discovery
3450 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3451 sysfs_mbox_idle(phba);
3452 spin_unlock_irq(&phba->hbalock);
3456 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3457 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3459 spin_unlock_irq(&phba->hbalock);
3460 rc = lpfc_sli_issue_mbox (phba,
3461 phba->sysfs_mbox.mbox,
3463 spin_lock_irq(&phba->hbalock);
3466 spin_unlock_irq(&phba->hbalock);
3467 rc = lpfc_sli_issue_mbox_wait (phba,
3468 phba->sysfs_mbox.mbox,
3469 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3470 spin_lock_irq(&phba->hbalock);
3473 if (rc != MBX_SUCCESS) {
3474 if (rc == MBX_TIMEOUT) {
3475 phba->sysfs_mbox.mbox = NULL;
3477 sysfs_mbox_idle(phba);
3478 spin_unlock_irq(&phba->hbalock);
3479 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3481 phba->sysfs_mbox.state = SMBOX_READING;
3483 else if (phba->sysfs_mbox.offset != off ||
3484 phba->sysfs_mbox.state != SMBOX_READING) {
3485 printk(KERN_WARNING "mbox_read: Bad State\n");
3486 sysfs_mbox_idle(phba);
3487 spin_unlock_irq(&phba->hbalock);
3491 memcpy(buf, (uint8_t *) &pmb + off, count);
3493 phba->sysfs_mbox.offset = off + count;
3495 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3496 sysfs_mbox_idle(phba);
3498 spin_unlock_irq(&phba->hbalock);
3503 static struct bin_attribute sysfs_mbox_attr = {
3506 .mode = S_IRUSR | S_IWUSR,
3508 .size = MAILBOX_CMD_SIZE,
3509 .read = sysfs_mbox_read,
3510 .write = sysfs_mbox_write,
3514 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3515 * @vport: address of lpfc vport structure.
3519 * error return code from sysfs_create_bin_file()
3522 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3527 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3528 &sysfs_drvr_stat_data_attr);
3530 /* Virtual ports do not need ctrl_reg and mbox */
3531 if (error || vport->port_type == LPFC_NPIV_PORT)
3534 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3535 &sysfs_ctlreg_attr);
3537 goto out_remove_stat_attr;
3539 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3542 goto out_remove_ctlreg_attr;
3545 out_remove_ctlreg_attr:
3546 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3547 out_remove_stat_attr:
3548 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3549 &sysfs_drvr_stat_data_attr);
3555 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
3556 * @vport: address of lpfc vport structure.
3559 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
3561 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3562 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3563 &sysfs_drvr_stat_data_attr);
3564 /* Virtual ports do not need ctrl_reg and mbox */
3565 if (vport->port_type == LPFC_NPIV_PORT)
3567 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3568 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3573 * Dynamic FC Host Attributes Support
3577 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
3578 * @shost: kernel scsi host pointer.
3581 lpfc_get_host_port_id(struct Scsi_Host *shost)
3583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3585 /* note: fc_myDID already in cpu endianness */
3586 fc_host_port_id(shost) = vport->fc_myDID;
3590 * lpfc_get_host_port_type - Set the value of the scsi host port type
3591 * @shost: kernel scsi host pointer.
3594 lpfc_get_host_port_type(struct Scsi_Host *shost)
3596 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3597 struct lpfc_hba *phba = vport->phba;
3599 spin_lock_irq(shost->host_lock);
3601 if (vport->port_type == LPFC_NPIV_PORT) {
3602 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3603 } else if (lpfc_is_link_up(phba)) {
3604 if (phba->fc_topology == TOPOLOGY_LOOP) {
3605 if (vport->fc_flag & FC_PUBLIC_LOOP)
3606 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3608 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3610 if (vport->fc_flag & FC_FABRIC)
3611 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3613 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3616 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3618 spin_unlock_irq(shost->host_lock);
3622 * lpfc_get_host_port_state - Set the value of the scsi host port state
3623 * @shost: kernel scsi host pointer.
3626 lpfc_get_host_port_state(struct Scsi_Host *shost)
3628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3629 struct lpfc_hba *phba = vport->phba;
3631 spin_lock_irq(shost->host_lock);
3633 if (vport->fc_flag & FC_OFFLINE_MODE)
3634 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3636 switch (phba->link_state) {
3637 case LPFC_LINK_UNKNOWN:
3638 case LPFC_LINK_DOWN:
3639 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3643 case LPFC_HBA_READY:
3644 /* Links up, beyond this port_type reports state */
3645 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3647 case LPFC_HBA_ERROR:
3648 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3651 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3656 spin_unlock_irq(shost->host_lock);
3660 * lpfc_get_host_speed - Set the value of the scsi host speed
3661 * @shost: kernel scsi host pointer.
3664 lpfc_get_host_speed(struct Scsi_Host *shost)
3666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3667 struct lpfc_hba *phba = vport->phba;
3669 spin_lock_irq(shost->host_lock);
3671 if (lpfc_is_link_up(phba)) {
3672 switch(phba->fc_linkspeed) {
3674 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3677 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3680 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3683 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3686 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3689 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3693 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3695 spin_unlock_irq(shost->host_lock);
3699 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
3700 * @shost: kernel scsi host pointer.
3703 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3705 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3706 struct lpfc_hba *phba = vport->phba;
3709 spin_lock_irq(shost->host_lock);
3711 if ((vport->fc_flag & FC_FABRIC) ||
3712 ((phba->fc_topology == TOPOLOGY_LOOP) &&
3713 (vport->fc_flag & FC_PUBLIC_LOOP)))
3714 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
3716 /* fabric is local port if there is no F/FL_Port */
3719 spin_unlock_irq(shost->host_lock);
3721 fc_host_fabric_name(shost) = node_name;
3725 * lpfc_get_stats - Return statistical information about the adapter
3726 * @shost: kernel scsi host pointer.
3729 * NULL on error for link down, no mbox pool, sli2 active,
3730 * management not allowed, memory allocation error, or mbox error.
3734 * address of the adapter host statistics
3736 static struct fc_host_statistics *
3737 lpfc_get_stats(struct Scsi_Host *shost)
3739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3740 struct lpfc_hba *phba = vport->phba;
3741 struct lpfc_sli *psli = &phba->sli;
3742 struct fc_host_statistics *hs = &phba->link_stats;
3743 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
3744 LPFC_MBOXQ_t *pmboxq;
3746 unsigned long seconds;
3750 * prevent udev from issuing mailbox commands until the port is
3753 if (phba->link_state < LPFC_LINK_DOWN ||
3754 !phba->mbox_mem_pool ||
3755 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
3758 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3761 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3764 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3766 pmb = &pmboxq->u.mb;
3767 pmb->mbxCommand = MBX_READ_STATUS;
3768 pmb->mbxOwner = OWN_HOST;
3769 pmboxq->context1 = NULL;
3770 pmboxq->vport = vport;
3772 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3773 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
3774 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3776 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3778 if (rc != MBX_SUCCESS) {
3779 if (rc != MBX_TIMEOUT)
3780 mempool_free(pmboxq, phba->mbox_mem_pool);
3784 memset(hs, 0, sizeof (struct fc_host_statistics));
3786 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3787 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3788 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3789 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3791 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3792 pmb->mbxCommand = MBX_READ_LNK_STAT;
3793 pmb->mbxOwner = OWN_HOST;
3794 pmboxq->context1 = NULL;
3795 pmboxq->vport = vport;
3797 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3798 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
3799 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3801 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3803 if (rc != MBX_SUCCESS) {
3804 if (rc != MBX_TIMEOUT)
3805 mempool_free(pmboxq, phba->mbox_mem_pool);
3809 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3810 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3811 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3812 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3813 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3814 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3815 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3817 hs->link_failure_count -= lso->link_failure_count;
3818 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3819 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3820 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3821 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3822 hs->invalid_crc_count -= lso->invalid_crc_count;
3823 hs->error_frames -= lso->error_frames;
3825 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
3827 hs->nos_count = (phba->link_events >> 1);
3828 hs->nos_count -= lso->link_events;
3829 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
3830 hs->lip_count = (phba->fc_eventTag >> 1);
3831 hs->lip_count -= lso->link_events;
3835 hs->nos_count = (phba->fc_eventTag >> 1);
3836 hs->nos_count -= lso->link_events;
3839 hs->dumped_frames = -1;
3841 seconds = get_seconds();
3842 if (seconds < psli->stats_start)
3843 hs->seconds_since_last_reset = seconds +
3844 ((unsigned long)-1 - psli->stats_start);
3846 hs->seconds_since_last_reset = seconds - psli->stats_start;
3848 mempool_free(pmboxq, phba->mbox_mem_pool);
3854 * lpfc_reset_stats - Copy the adapter link stats information
3855 * @shost: kernel scsi host pointer.
3858 lpfc_reset_stats(struct Scsi_Host *shost)
3860 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3861 struct lpfc_hba *phba = vport->phba;
3862 struct lpfc_sli *psli = &phba->sli;
3863 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
3864 LPFC_MBOXQ_t *pmboxq;
3868 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3871 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3874 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3876 pmb = &pmboxq->u.mb;
3877 pmb->mbxCommand = MBX_READ_STATUS;
3878 pmb->mbxOwner = OWN_HOST;
3879 pmb->un.varWords[0] = 0x1; /* reset request */
3880 pmboxq->context1 = NULL;
3881 pmboxq->vport = vport;
3883 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3884 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
3885 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3887 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3889 if (rc != MBX_SUCCESS) {
3890 if (rc != MBX_TIMEOUT)
3891 mempool_free(pmboxq, phba->mbox_mem_pool);
3895 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3896 pmb->mbxCommand = MBX_READ_LNK_STAT;
3897 pmb->mbxOwner = OWN_HOST;
3898 pmboxq->context1 = NULL;
3899 pmboxq->vport = vport;
3901 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3902 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
3903 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3905 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3907 if (rc != MBX_SUCCESS) {
3908 if (rc != MBX_TIMEOUT)
3909 mempool_free( pmboxq, phba->mbox_mem_pool);
3913 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3914 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3915 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3916 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3917 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3918 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3919 lso->error_frames = pmb->un.varRdLnk.crcCnt;
3920 if (phba->hba_flag & HBA_FCOE_SUPPORT)
3921 lso->link_events = (phba->link_events >> 1);
3923 lso->link_events = (phba->fc_eventTag >> 1);
3925 psli->stats_start = get_seconds();
3927 mempool_free(pmboxq, phba->mbox_mem_pool);
3933 * The LPFC driver treats linkdown handling as target loss events so there
3934 * are no sysfs handlers for link_down_tmo.
3938 * lpfc_get_node_by_target - Return the nodelist for a target
3939 * @starget: kernel scsi target pointer.
3942 * address of the node list if found
3943 * NULL target not found
3945 static struct lpfc_nodelist *
3946 lpfc_get_node_by_target(struct scsi_target *starget)
3948 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3949 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3950 struct lpfc_nodelist *ndlp;
3952 spin_lock_irq(shost->host_lock);
3953 /* Search for this, mapped, target ID */
3954 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3955 if (NLP_CHK_NODE_ACT(ndlp) &&
3956 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
3957 starget->id == ndlp->nlp_sid) {
3958 spin_unlock_irq(shost->host_lock);
3962 spin_unlock_irq(shost->host_lock);
3967 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
3968 * @starget: kernel scsi target pointer.
3971 lpfc_get_starget_port_id(struct scsi_target *starget)
3973 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3975 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
3979 * lpfc_get_starget_node_name - Set the target node name
3980 * @starget: kernel scsi target pointer.
3982 * Description: Set the target node name to the ndlp node name wwn or zero.
3985 lpfc_get_starget_node_name(struct scsi_target *starget)
3987 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3989 fc_starget_node_name(starget) =
3990 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
3994 * lpfc_get_starget_port_name - Set the target port name
3995 * @starget: kernel scsi target pointer.
3997 * Description: set the target port name to the ndlp port name wwn or zero.
4000 lpfc_get_starget_port_name(struct scsi_target *starget)
4002 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4004 fc_starget_port_name(starget) =
4005 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4009 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4010 * @rport: fc rport address.
4011 * @timeout: new value for dev loss tmo.
4014 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4015 * dev_loss_tmo to one.
4018 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4021 rport->dev_loss_tmo = timeout;
4023 rport->dev_loss_tmo = 1;
4027 * lpfc_rport_show_function - Return rport target information
4030 * Macro that uses field to generate a function with the name lpfc_show_rport_
4032 * lpfc_show_rport_##field: returns the bytes formatted in buf
4033 * @cdev: class converted to an fc_rport.
4034 * @buf: on return contains the target_field or zero.
4036 * Returns: size of formatted string.
4038 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4040 lpfc_show_rport_##field (struct device *dev, \
4041 struct device_attribute *attr, \
4044 struct fc_rport *rport = transport_class_to_rport(dev); \
4045 struct lpfc_rport_data *rdata = rport->hostdata; \
4046 return snprintf(buf, sz, format_string, \
4047 (rdata->target) ? cast rdata->target->field : 0); \
4050 #define lpfc_rport_rd_attr(field, format_string, sz) \
4051 lpfc_rport_show_function(field, format_string, sz, ) \
4052 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4055 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4056 * @fc_vport: The fc_vport who's symbolic name has been changed.
4059 * This function is called by the transport after the @fc_vport's symbolic name
4060 * has been changed. This function re-registers the symbolic name with the
4061 * switch to propogate the change into the fabric if the vport is active.
4064 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4066 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4068 if (vport->port_state == LPFC_VPORT_READY)
4069 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4073 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4074 * @phba: Pointer to lpfc_hba struct.
4076 * This function is called by the lpfc_get_cfgparam() routine to set the
4077 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4078 * log messsage according to the module's lpfc_log_verbose parameter setting
4079 * before hba port or vport created.
4082 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4084 phba->cfg_log_verbose = verbose;
4087 struct fc_function_template lpfc_transport_functions = {
4088 /* fixed attributes the driver supports */
4089 .show_host_node_name = 1,
4090 .show_host_port_name = 1,
4091 .show_host_supported_classes = 1,
4092 .show_host_supported_fc4s = 1,
4093 .show_host_supported_speeds = 1,
4094 .show_host_maxframe_size = 1,
4095 .show_host_symbolic_name = 1,
4097 /* dynamic attributes the driver supports */
4098 .get_host_port_id = lpfc_get_host_port_id,
4099 .show_host_port_id = 1,
4101 .get_host_port_type = lpfc_get_host_port_type,
4102 .show_host_port_type = 1,
4104 .get_host_port_state = lpfc_get_host_port_state,
4105 .show_host_port_state = 1,
4107 /* active_fc4s is shown but doesn't change (thus no get function) */
4108 .show_host_active_fc4s = 1,
4110 .get_host_speed = lpfc_get_host_speed,
4111 .show_host_speed = 1,
4113 .get_host_fabric_name = lpfc_get_host_fabric_name,
4114 .show_host_fabric_name = 1,
4117 * The LPFC driver treats linkdown handling as target loss events
4118 * so there are no sysfs handlers for link_down_tmo.
4121 .get_fc_host_stats = lpfc_get_stats,
4122 .reset_fc_host_stats = lpfc_reset_stats,
4124 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4125 .show_rport_maxframe_size = 1,
4126 .show_rport_supported_classes = 1,
4128 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4129 .show_rport_dev_loss_tmo = 1,
4131 .get_starget_port_id = lpfc_get_starget_port_id,
4132 .show_starget_port_id = 1,
4134 .get_starget_node_name = lpfc_get_starget_node_name,
4135 .show_starget_node_name = 1,
4137 .get_starget_port_name = lpfc_get_starget_port_name,
4138 .show_starget_port_name = 1,
4140 .issue_fc_host_lip = lpfc_issue_lip,
4141 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4142 .terminate_rport_io = lpfc_terminate_rport_io,
4144 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4146 .vport_disable = lpfc_vport_disable,
4148 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4150 .bsg_request = lpfc_bsg_request,
4151 .bsg_timeout = lpfc_bsg_timeout,
4154 struct fc_function_template lpfc_vport_transport_functions = {
4155 /* fixed attributes the driver supports */
4156 .show_host_node_name = 1,
4157 .show_host_port_name = 1,
4158 .show_host_supported_classes = 1,
4159 .show_host_supported_fc4s = 1,
4160 .show_host_supported_speeds = 1,
4161 .show_host_maxframe_size = 1,
4162 .show_host_symbolic_name = 1,
4164 /* dynamic attributes the driver supports */
4165 .get_host_port_id = lpfc_get_host_port_id,
4166 .show_host_port_id = 1,
4168 .get_host_port_type = lpfc_get_host_port_type,
4169 .show_host_port_type = 1,
4171 .get_host_port_state = lpfc_get_host_port_state,
4172 .show_host_port_state = 1,
4174 /* active_fc4s is shown but doesn't change (thus no get function) */
4175 .show_host_active_fc4s = 1,
4177 .get_host_speed = lpfc_get_host_speed,
4178 .show_host_speed = 1,
4180 .get_host_fabric_name = lpfc_get_host_fabric_name,
4181 .show_host_fabric_name = 1,
4184 * The LPFC driver treats linkdown handling as target loss events
4185 * so there are no sysfs handlers for link_down_tmo.
4188 .get_fc_host_stats = lpfc_get_stats,
4189 .reset_fc_host_stats = lpfc_reset_stats,
4191 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4192 .show_rport_maxframe_size = 1,
4193 .show_rport_supported_classes = 1,
4195 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4196 .show_rport_dev_loss_tmo = 1,
4198 .get_starget_port_id = lpfc_get_starget_port_id,
4199 .show_starget_port_id = 1,
4201 .get_starget_node_name = lpfc_get_starget_node_name,
4202 .show_starget_node_name = 1,
4204 .get_starget_port_name = lpfc_get_starget_port_name,
4205 .show_starget_port_name = 1,
4207 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4208 .terminate_rport_io = lpfc_terminate_rport_io,
4210 .vport_disable = lpfc_vport_disable,
4212 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4216 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4217 * @phba: lpfc_hba pointer.
4220 lpfc_get_cfgparam(struct lpfc_hba *phba)
4222 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4223 lpfc_cr_count_init(phba, lpfc_cr_count);
4224 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4225 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4226 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4227 lpfc_ack0_init(phba, lpfc_ack0);
4228 lpfc_topology_init(phba, lpfc_topology);
4229 lpfc_link_speed_init(phba, lpfc_link_speed);
4230 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4231 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4232 lpfc_use_msi_init(phba, lpfc_use_msi);
4233 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4234 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4235 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4236 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4237 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4238 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4239 phba->cfg_poll = lpfc_poll;
4240 phba->cfg_soft_wwnn = 0L;
4241 phba->cfg_soft_wwpn = 0L;
4242 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4243 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4244 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4245 lpfc_enable_fip_init(phba, lpfc_enable_fip);
4246 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4252 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4253 * @vport: lpfc_vport pointer.
4256 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4258 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4259 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4260 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4261 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4262 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4263 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4264 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4265 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4266 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4267 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4268 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4269 lpfc_max_luns_init(vport, lpfc_max_luns);
4270 lpfc_scan_down_init(vport, lpfc_scan_down);
4271 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);