1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_tcq.h>
31 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_logmsg.h"
39 #include "lpfc_version.h"
40 #include "lpfc_compat.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
44 #define LPFC_DEF_DEVLOSS_TMO 30
45 #define LPFC_MIN_DEVLOSS_TMO 1
46 #define LPFC_MAX_DEVLOSS_TMO 255
48 #define LPFC_MAX_LINK_SPEED 8
49 #define LPFC_LINK_SPEED_BITMAP 0x00000117
50 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
53 * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules.
54 * @incr: integer to convert.
55 * @hdw: ascii string holding converted integer plus a string terminator.
58 * JEDEC Joint Electron Device Engineering Council.
59 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
60 * character string. The string is then terminated with a NULL in byte 9.
61 * Hex 0-9 becomes ascii '0' to '9'.
62 * Hex a-f becomes ascii '=' to 'B' capital B.
65 * Coded for 32 bit integers only.
68 lpfc_jedec_to_ascii(int incr, char hdw[])
71 for (i = 0; i < 8; i++) {
74 hdw[7 - i] = 0x30 + j;
76 hdw[7 - i] = 0x61 + j - 10;
84 * lpfc_drvr_version_show: Return the Emulex driver string with version number.
85 * @dev: class unused variable.
86 * @attr: device attribute, not used.
87 * @buf: on return contains the module description text.
89 * Returns: size of formatted string.
92 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
95 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99 * lpfc_info_show: Return some pci info about the host in ascii.
100 * @dev: class converted to a Scsi_host structure.
101 * @attr: device attribute, not used.
102 * @buf: on return contains the formatted text from lpfc_info().
104 * Returns: size of formatted string.
107 lpfc_info_show(struct device *dev, struct device_attribute *attr,
110 struct Scsi_Host *host = class_to_shost(dev);
112 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
116 * lpfc_serialnum_show: Return the hba serial number in ascii.
117 * @dev: class converted to a Scsi_host structure.
118 * @attr: device attribute, not used.
119 * @buf: on return contains the formatted text serial number.
121 * Returns: size of formatted string.
124 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
131 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
135 * lpfc_temp_sensor_show: Return the temperature sensor level.
136 * @dev: class converted to a Scsi_host structure.
137 * @attr: device attribute, not used.
138 * @buf: on return contains the formatted support level.
141 * Returns a number indicating the temperature sensor level currently
142 * supported, zero or one in ascii.
144 * Returns: size of formatted string.
147 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
150 struct Scsi_Host *shost = class_to_shost(dev);
151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152 struct lpfc_hba *phba = vport->phba;
153 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
157 * lpfc_modeldesc_show: Return the model description of the hba.
158 * @dev: class converted to a Scsi_host structure.
159 * @attr: device attribute, not used.
160 * @buf: on return contains the scsi vpd model description.
162 * Returns: size of formatted string.
165 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
168 struct Scsi_Host *shost = class_to_shost(dev);
169 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
170 struct lpfc_hba *phba = vport->phba;
172 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
176 * lpfc_modelname_show: Return the model name of the hba.
177 * @dev: class converted to a Scsi_host structure.
178 * @attr: device attribute, not used.
179 * @buf: on return contains the scsi vpd model name.
181 * Returns: size of formatted string.
184 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
187 struct Scsi_Host *shost = class_to_shost(dev);
188 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
189 struct lpfc_hba *phba = vport->phba;
191 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
195 * lpfc_programtype_show: Return the program type of the hba.
196 * @dev: class converted to a Scsi_host structure.
197 * @attr: device attribute, not used.
198 * @buf: on return contains the scsi vpd program type.
200 * Returns: size of formatted string.
203 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
206 struct Scsi_Host *shost = class_to_shost(dev);
207 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
208 struct lpfc_hba *phba = vport->phba;
210 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
214 * lpfc_mlomgmt_show: Return the Menlo Maintenance sli flag.
215 * @dev: class converted to a Scsi_host structure.
216 * @attr: device attribute, not used.
217 * @buf: on return contains the Menlo Maintenance sli flag.
219 * Returns: size of formatted string.
222 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
224 struct Scsi_Host *shost = class_to_shost(dev);
225 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
226 struct lpfc_hba *phba = vport->phba;
228 return snprintf(buf, PAGE_SIZE, "%d\n",
229 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
233 * lpfc_vportnum_show: Return the port number in ascii of the hba.
234 * @dev: class converted to a Scsi_host structure.
235 * @attr: device attribute, not used.
236 * @buf: on return contains scsi vpd program type.
238 * Returns: size of formatted string.
241 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
244 struct Scsi_Host *shost = class_to_shost(dev);
245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
246 struct lpfc_hba *phba = vport->phba;
248 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
252 * lpfc_fwrev_show: Return the firmware rev running in the hba.
253 * @dev: class converted to a Scsi_host structure.
254 * @attr: device attribute, not used.
255 * @buf: on return contains the scsi vpd program type.
257 * Returns: size of formatted string.
260 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
263 struct Scsi_Host *shost = class_to_shost(dev);
264 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
265 struct lpfc_hba *phba = vport->phba;
268 lpfc_decode_firmware_rev(phba, fwrev, 1);
269 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
273 * lpfc_hdw_show: Return the jedec information about the hba.
274 * @dev: class converted to a Scsi_host structure.
275 * @attr: device attribute, not used.
276 * @buf: on return contains the scsi vpd program type.
278 * Returns: size of formatted string.
281 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
284 struct Scsi_Host *shost = class_to_shost(dev);
285 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
286 struct lpfc_hba *phba = vport->phba;
287 lpfc_vpd_t *vp = &phba->vpd;
289 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
290 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
294 * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the ROM and FCode ascii strings.
299 * Returns: size of formatted string.
302 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
305 struct Scsi_Host *shost = class_to_shost(dev);
306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
307 struct lpfc_hba *phba = vport->phba;
309 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
313 * lpfc_state_show: Return the link state of the port.
314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains text describing the state of the link.
319 * The switch statement has no default so zero will be returned.
321 * Returns: size of formatted string.
324 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
327 struct Scsi_Host *shost = class_to_shost(dev);
328 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
329 struct lpfc_hba *phba = vport->phba;
332 switch (phba->link_state) {
333 case LPFC_LINK_UNKNOWN:
334 case LPFC_WARM_START:
335 case LPFC_INIT_START:
336 case LPFC_INIT_MBX_CMDS:
339 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
344 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
346 switch (vport->port_state) {
347 case LPFC_LOCAL_CFG_LINK:
348 len += snprintf(buf + len, PAGE_SIZE-len,
349 "Configuring Link\n");
353 case LPFC_FABRIC_CFG_LINK:
356 case LPFC_BUILD_DISC_LIST:
358 len += snprintf(buf + len, PAGE_SIZE - len,
361 case LPFC_VPORT_READY:
362 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
365 case LPFC_VPORT_FAILED:
366 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
369 case LPFC_VPORT_UNKNOWN:
370 len += snprintf(buf + len, PAGE_SIZE - len,
374 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
375 len += snprintf(buf + len, PAGE_SIZE-len,
376 " Menlo Maint Mode\n");
377 else if (phba->fc_topology == TOPOLOGY_LOOP) {
378 if (vport->fc_flag & FC_PUBLIC_LOOP)
379 len += snprintf(buf + len, PAGE_SIZE-len,
382 len += snprintf(buf + len, PAGE_SIZE-len,
385 if (vport->fc_flag & FC_FABRIC)
386 len += snprintf(buf + len, PAGE_SIZE-len,
389 len += snprintf(buf + len, PAGE_SIZE-len,
398 * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
399 * @dev: class device that is converted into a Scsi_host.
400 * @attr: device attribute, not used.
401 * @buf: on return contains the sum of fc mapped and unmapped.
404 * Returns the ascii text number of the sum of the fc mapped and unmapped
407 * Returns: size of formatted string.
410 lpfc_num_discovered_ports_show(struct device *dev,
411 struct device_attribute *attr, char *buf)
413 struct Scsi_Host *shost = class_to_shost(dev);
414 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
416 return snprintf(buf, PAGE_SIZE, "%d\n",
417 vport->fc_map_cnt + vport->fc_unmap_cnt);
421 * lpfc_issue_lip: Misnomer, name carried over from long ago.
422 * @shost: Scsi_Host pointer.
425 * Bring the link down gracefully then re-init the link. The firmware will
426 * re-init the fiber channel interface as required. Does not issue a LIP.
429 * -EPERM port offline or management commands are being blocked
430 * -ENOMEM cannot allocate memory for the mailbox command
431 * -EIO error sending the mailbox command
435 lpfc_issue_lip(struct Scsi_Host *shost)
437 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
438 struct lpfc_hba *phba = vport->phba;
439 LPFC_MBOXQ_t *pmboxq;
440 int mbxstatus = MBXERR_ERROR;
442 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
443 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
446 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
451 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
452 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
453 pmboxq->mb.mbxOwner = OWN_HOST;
455 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
457 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
458 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
459 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
460 phba->cfg_link_speed);
461 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
465 lpfc_set_loopback_flag(phba);
466 if (mbxstatus != MBX_TIMEOUT)
467 mempool_free(pmboxq, phba->mbox_mem_pool);
469 if (mbxstatus == MBXERR_ERROR)
476 * lpfc_do_offline: Issues a mailbox command to bring the link down.
477 * @phba: lpfc_hba pointer.
478 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
481 * Assumes any error from lpfc_do_offline() will be negative.
482 * Can wait up to 5 seconds for the port ring buffers count
483 * to reach zero, prints a warning if it is not zero and continues.
484 * lpfc_workq_post_event() returns a non-zero return coce if call fails.
487 * -EIO error posting the event
491 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
493 struct completion online_compl;
494 struct lpfc_sli_ring *pring;
495 struct lpfc_sli *psli;
500 init_completion(&online_compl);
501 lpfc_workq_post_event(phba, &status, &online_compl,
502 LPFC_EVT_OFFLINE_PREP);
503 wait_for_completion(&online_compl);
510 /* Wait a little for things to settle down, but not
511 * long enough for dev loss timeout to expire.
513 for (i = 0; i < psli->num_rings; i++) {
514 pring = &psli->ring[i];
515 while (pring->txcmplq_cnt) {
517 if (cnt++ > 500) { /* 5 secs */
518 lpfc_printf_log(phba,
519 KERN_WARNING, LOG_INIT,
520 "0466 Outstanding IO when "
521 "bringing Adapter offline\n");
527 init_completion(&online_compl);
528 lpfc_workq_post_event(phba, &status, &online_compl, type);
529 wait_for_completion(&online_compl);
538 * lpfc_selective_reset: Offline then onlines the port.
539 * @phba: lpfc_hba pointer.
542 * If the port is configured to allow a reset then the hba is brought
543 * offline then online.
546 * Assumes any error from lpfc_do_offline() will be negative.
549 * lpfc_do_offline() return code if not zero
550 * -EIO reset not configured or error posting the event
554 lpfc_selective_reset(struct lpfc_hba *phba)
556 struct completion online_compl;
559 if (!phba->cfg_enable_hba_reset)
562 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
567 init_completion(&online_compl);
568 lpfc_workq_post_event(phba, &status, &online_compl,
570 wait_for_completion(&online_compl);
579 * lpfc_issue_reset: Selectively resets an adapter.
580 * @dev: class device that is converted into a Scsi_host.
581 * @attr: device attribute, not used.
582 * @buf: containing the string "selective".
583 * @count: unused variable.
586 * If the buf contains the string "selective" then lpfc_selective_reset()
587 * is called to perform the reset.
590 * Assumes any error from lpfc_selective_reset() will be negative.
591 * If lpfc_selective_reset() returns zero then the length of the buffer
592 * is returned which indicates succcess
595 * -EINVAL if the buffer does not contain the string "selective"
596 * length of buf if lpfc-selective_reset() if the call succeeds
597 * return value of lpfc_selective_reset() if the call fails
600 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
601 const char *buf, size_t count)
603 struct Scsi_Host *shost = class_to_shost(dev);
604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
605 struct lpfc_hba *phba = vport->phba;
607 int status = -EINVAL;
609 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
610 status = lpfc_selective_reset(phba);
619 * lpfc_nport_evt_cnt_show: Return the number of nport events.
620 * @dev: class device that is converted into a Scsi_host.
621 * @attr: device attribute, not used.
622 * @buf: on return contains the ascii number of nport events.
624 * Returns: size of formatted string.
627 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
630 struct Scsi_Host *shost = class_to_shost(dev);
631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
632 struct lpfc_hba *phba = vport->phba;
634 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
638 * lpfc_board_mode_show: Return the state of the board.
639 * @dev: class device that is converted into a Scsi_host.
640 * @attr: device attribute, not used.
641 * @buf: on return contains the state of the adapter.
643 * Returns: size of formatted string.
646 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
649 struct Scsi_Host *shost = class_to_shost(dev);
650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
651 struct lpfc_hba *phba = vport->phba;
654 if (phba->link_state == LPFC_HBA_ERROR)
656 else if (phba->link_state == LPFC_WARM_START)
657 state = "warm start";
658 else if (phba->link_state == LPFC_INIT_START)
663 return snprintf(buf, PAGE_SIZE, "%s\n", state);
667 * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
668 * @dev: class device that is converted into a Scsi_host.
669 * @attr: device attribute, not used.
670 * @buf: containing one of the strings "online", "offline", "warm" or "error".
671 * @count: unused variable.
674 * -EACCES if enable hba reset not enabled
675 * -EINVAL if the buffer does not contain a valid string (see above)
676 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
677 * buf length greater than zero indicates success
680 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
681 const char *buf, size_t count)
683 struct Scsi_Host *shost = class_to_shost(dev);
684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685 struct lpfc_hba *phba = vport->phba;
686 struct completion online_compl;
689 if (!phba->cfg_enable_hba_reset)
691 init_completion(&online_compl);
693 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
694 lpfc_workq_post_event(phba, &status, &online_compl,
696 wait_for_completion(&online_compl);
697 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
699 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
700 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
701 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
702 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
713 * lpfc_get_hba_info: Return various bits of informaton about the adapter.
714 * @phba: pointer to the adapter structure.
715 * @mxri max xri count.
716 * @axri available xri count.
717 * @mrpi max rpi count.
718 * @arpi available rpi count.
719 * @mvpi max vpi count.
720 * @avpi available vpi count.
723 * If an integer pointer for an count is not null then the value for the
731 lpfc_get_hba_info(struct lpfc_hba *phba,
732 uint32_t *mxri, uint32_t *axri,
733 uint32_t *mrpi, uint32_t *arpi,
734 uint32_t *mvpi, uint32_t *avpi)
736 struct lpfc_sli *psli = &phba->sli;
737 LPFC_MBOXQ_t *pmboxq;
742 * prevent udev from issuing mailbox commands until the port is
745 if (phba->link_state < LPFC_LINK_DOWN ||
746 !phba->mbox_mem_pool ||
747 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
750 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
753 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
756 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
759 pmb->mbxCommand = MBX_READ_CONFIG;
760 pmb->mbxOwner = OWN_HOST;
761 pmboxq->context1 = NULL;
763 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
764 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
765 rc = MBX_NOT_FINISHED;
767 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
769 if (rc != MBX_SUCCESS) {
770 if (rc != MBX_TIMEOUT)
771 mempool_free(pmboxq, phba->mbox_mem_pool);
776 *mrpi = pmb->un.varRdConfig.max_rpi;
778 *arpi = pmb->un.varRdConfig.avail_rpi;
780 *mxri = pmb->un.varRdConfig.max_xri;
782 *axri = pmb->un.varRdConfig.avail_xri;
784 *mvpi = pmb->un.varRdConfig.max_vpi;
786 *avpi = pmb->un.varRdConfig.avail_vpi;
788 mempool_free(pmboxq, phba->mbox_mem_pool);
793 * lpfc_max_rpi_show: Return maximum rpi.
794 * @dev: class device that is converted into a Scsi_host.
795 * @attr: device attribute, not used.
796 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
799 * Calls lpfc_get_hba_info() asking for just the mrpi count.
800 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
801 * to "Unknown" and the buffer length is returned, therefore the caller
802 * must check for "Unknown" in the buffer to detect a failure.
804 * Returns: size of formatted string.
807 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
810 struct Scsi_Host *shost = class_to_shost(dev);
811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
815 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
816 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
817 return snprintf(buf, PAGE_SIZE, "Unknown\n");
821 * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
822 * @dev: class device that is converted into a Scsi_host.
823 * @attr: device attribute, not used.
824 * @buf: containing the used rpi count in decimal or "Unknown".
827 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
828 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
829 * to "Unknown" and the buffer length is returned, therefore the caller
830 * must check for "Unknown" in the buffer to detect a failure.
832 * Returns: size of formatted string.
835 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
838 struct Scsi_Host *shost = class_to_shost(dev);
839 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
840 struct lpfc_hba *phba = vport->phba;
843 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
844 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
845 return snprintf(buf, PAGE_SIZE, "Unknown\n");
849 * lpfc_max_xri_show: Return maximum xri.
850 * @dev: class device that is converted into a Scsi_host.
851 * @attr: device attribute, not used.
852 * @buf: on return contains the maximum xri count in decimal or "Unknown".
855 * Calls lpfc_get_hba_info() asking for just the mrpi count.
856 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
857 * to "Unknown" and the buffer length is returned, therefore the caller
858 * must check for "Unknown" in the buffer to detect a failure.
860 * Returns: size of formatted string.
863 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
866 struct Scsi_Host *shost = class_to_shost(dev);
867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
868 struct lpfc_hba *phba = vport->phba;
871 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
872 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
873 return snprintf(buf, PAGE_SIZE, "Unknown\n");
877 * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
878 * @dev: class device that is converted into a Scsi_host.
879 * @attr: device attribute, not used.
880 * @buf: on return contains the used xri count in decimal or "Unknown".
883 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
884 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
885 * to "Unknown" and the buffer length is returned, therefore the caller
886 * must check for "Unknown" in the buffer to detect a failure.
888 * Returns: size of formatted string.
891 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
894 struct Scsi_Host *shost = class_to_shost(dev);
895 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
896 struct lpfc_hba *phba = vport->phba;
899 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
900 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
901 return snprintf(buf, PAGE_SIZE, "Unknown\n");
905 * lpfc_max_vpi_show: Return maximum vpi.
906 * @dev: class device that is converted into a Scsi_host.
907 * @attr: device attribute, not used.
908 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
911 * Calls lpfc_get_hba_info() asking for just the mvpi count.
912 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
913 * to "Unknown" and the buffer length is returned, therefore the caller
914 * must check for "Unknown" in the buffer to detect a failure.
916 * Returns: size of formatted string.
919 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
922 struct Scsi_Host *shost = class_to_shost(dev);
923 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
924 struct lpfc_hba *phba = vport->phba;
927 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
928 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
929 return snprintf(buf, PAGE_SIZE, "Unknown\n");
933 * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
934 * @dev: class device that is converted into a Scsi_host.
935 * @attr: device attribute, not used.
936 * @buf: on return contains the used vpi count in decimal or "Unknown".
939 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
940 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
941 * to "Unknown" and the buffer length is returned, therefore the caller
942 * must check for "Unknown" in the buffer to detect a failure.
944 * Returns: size of formatted string.
947 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
950 struct Scsi_Host *shost = class_to_shost(dev);
951 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
952 struct lpfc_hba *phba = vport->phba;
955 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
956 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
957 return snprintf(buf, PAGE_SIZE, "Unknown\n");
961 * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
962 * @dev: class device that is converted into a Scsi_host.
963 * @attr: device attribute, not used.
964 * @buf: text that must be interpreted to determine if npiv is supported.
967 * Buffer will contain text indicating npiv is not suppoerted on the port,
968 * the port is an NPIV physical port, or it is an npiv virtual port with
969 * the id of the vport.
971 * Returns: size of formatted string.
974 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
977 struct Scsi_Host *shost = class_to_shost(dev);
978 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
979 struct lpfc_hba *phba = vport->phba;
981 if (!(phba->max_vpi))
982 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
983 if (vport->port_type == LPFC_PHYSICAL_PORT)
984 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
985 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
989 * lpfc_poll_show: Return text about poll support for the adapter.
990 * @dev: class device that is converted into a Scsi_host.
991 * @attr: device attribute, not used.
992 * @buf: on return contains the cfg_poll in hex.
995 * cfg_poll should be a lpfc_polling_flags type.
997 * Returns: size of formatted string.
1000 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1003 struct Scsi_Host *shost = class_to_shost(dev);
1004 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1005 struct lpfc_hba *phba = vport->phba;
1007 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1011 * lpfc_poll_store: Set the value of cfg_poll for the adapter.
1012 * @dev: class device that is converted into a Scsi_host.
1013 * @attr: device attribute, not used.
1014 * @buf: one or more lpfc_polling_flags values.
1018 * buf contents converted to integer and checked for a valid value.
1021 * -EINVAL if the buffer connot be converted or is out of range
1022 * length of the buf on success
1025 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1026 const char *buf, size_t count)
1028 struct Scsi_Host *shost = class_to_shost(dev);
1029 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1030 struct lpfc_hba *phba = vport->phba;
1035 if (!isdigit(buf[0]))
1038 if (sscanf(buf, "%i", &val) != 1)
1041 if ((val & 0x3) != val)
1044 spin_lock_irq(&phba->hbalock);
1046 old_val = phba->cfg_poll;
1048 if (val & ENABLE_FCP_RING_POLLING) {
1049 if ((val & DISABLE_FCP_RING_INT) &&
1050 !(old_val & DISABLE_FCP_RING_INT)) {
1051 creg_val = readl(phba->HCregaddr);
1052 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1053 writel(creg_val, phba->HCregaddr);
1054 readl(phba->HCregaddr); /* flush */
1056 lpfc_poll_start_timer(phba);
1058 } else if (val != 0x0) {
1059 spin_unlock_irq(&phba->hbalock);
1063 if (!(val & DISABLE_FCP_RING_INT) &&
1064 (old_val & DISABLE_FCP_RING_INT))
1066 spin_unlock_irq(&phba->hbalock);
1067 del_timer(&phba->fcp_poll_timer);
1068 spin_lock_irq(&phba->hbalock);
1069 creg_val = readl(phba->HCregaddr);
1070 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1071 writel(creg_val, phba->HCregaddr);
1072 readl(phba->HCregaddr); /* flush */
1075 phba->cfg_poll = val;
1077 spin_unlock_irq(&phba->hbalock);
1083 * lpfc_param_show: Return a cfg attribute value in decimal.
1086 * Macro that given an attr e.g. hba_queue_depth expands
1087 * into a function with the name lpfc_hba_queue_depth_show.
1089 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1090 * @dev: class device that is converted into a Scsi_host.
1091 * @attr: device attribute, not used.
1092 * @buf: on return contains the attribute value in decimal.
1094 * Returns: size of formatted string.
1096 #define lpfc_param_show(attr) \
1098 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1101 struct Scsi_Host *shost = class_to_shost(dev);\
1102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1103 struct lpfc_hba *phba = vport->phba;\
1105 val = phba->cfg_##attr;\
1106 return snprintf(buf, PAGE_SIZE, "%d\n",\
1111 * lpfc_param_hex_show: Return a cfg attribute value in hex.
1114 * Macro that given an attr e.g. hba_queue_depth expands
1115 * into a function with the name lpfc_hba_queue_depth_show
1117 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1118 * @dev: class device that is converted into a Scsi_host.
1119 * @attr: device attribute, not used.
1120 * @buf: on return contains the attribute value in hexidecimal.
1122 * Returns: size of formatted string.
1124 #define lpfc_param_hex_show(attr) \
1126 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1129 struct Scsi_Host *shost = class_to_shost(dev);\
1130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1131 struct lpfc_hba *phba = vport->phba;\
1133 val = phba->cfg_##attr;\
1134 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1139 * lpfc_param_init: Intializes a cfg attribute.
1142 * Macro that given an attr e.g. hba_queue_depth expands
1143 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1144 * takes a default argument, a minimum and maximum argument.
1146 * lpfc_##attr##_init: Initializes an attribute.
1147 * @phba: pointer the the adapter structure.
1148 * @val: integer attribute value.
1150 * Validates the min and max values then sets the adapter config field
1151 * accordingly, or uses the default if out of range and prints an error message.
1155 * -EINVAL if default used
1157 #define lpfc_param_init(attr, default, minval, maxval) \
1159 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1161 if (val >= minval && val <= maxval) {\
1162 phba->cfg_##attr = val;\
1165 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1166 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1167 "allowed range is ["#minval", "#maxval"]\n", val); \
1168 phba->cfg_##attr = default;\
1173 * lpfc_param_set: Set a cfg attribute value.
1176 * Macro that given an attr e.g. hba_queue_depth expands
1177 * into a function with the name lpfc_hba_queue_depth_set
1179 * lpfc_##attr##_set: Sets an attribute value.
1180 * @phba: pointer the the adapter structure.
1181 * @val: integer attribute value.
1184 * Validates the min and max values then sets the
1185 * adapter config field if in the valid range. prints error message
1186 * and does not set the parameter if invalid.
1190 * -EINVAL if val is invalid
1192 #define lpfc_param_set(attr, default, minval, maxval) \
1194 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1196 if (val >= minval && val <= maxval) {\
1197 phba->cfg_##attr = val;\
1200 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1201 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1202 "allowed range is ["#minval", "#maxval"]\n", val); \
1207 * lpfc_param_store: Set a vport attribute value.
1210 * Macro that given an attr e.g. hba_queue_depth expands
1211 * into a function with the name lpfc_hba_queue_depth_store.
1213 * lpfc_##attr##_store: Set an sttribute value.
1214 * @dev: class device that is converted into a Scsi_host.
1215 * @attr: device attribute, not used.
1216 * @buf: contains the attribute value in ascii.
1220 * Convert the ascii text number to an integer, then
1221 * use the lpfc_##attr##_set function to set the value.
1224 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1225 * length of buffer upon success.
1227 #define lpfc_param_store(attr) \
1229 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1230 const char *buf, size_t count) \
1232 struct Scsi_Host *shost = class_to_shost(dev);\
1233 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1234 struct lpfc_hba *phba = vport->phba;\
1236 if (!isdigit(buf[0]))\
1238 if (sscanf(buf, "%i", &val) != 1)\
1240 if (lpfc_##attr##_set(phba, val) == 0) \
1241 return strlen(buf);\
1247 * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
1250 * Macro that given an attr e.g. hba_queue_depth expands
1251 * into a function with the name lpfc_hba_queue_depth_show
1253 * lpfc_##attr##_show: prints the attribute value in decimal.
1254 * @dev: class device that is converted into a Scsi_host.
1255 * @attr: device attribute, not used.
1256 * @buf: on return contains the attribute value in decimal.
1258 * Returns: length of formatted string.
1260 #define lpfc_vport_param_show(attr) \
1262 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1265 struct Scsi_Host *shost = class_to_shost(dev);\
1266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1268 val = vport->cfg_##attr;\
1269 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1273 * lpfc_vport_param_hex_show: Return hex formatted attribute value.
1276 * Macro that given an attr e.g.
1277 * hba_queue_depth expands into a function with the name
1278 * lpfc_hba_queue_depth_show
1280 * lpfc_##attr##_show: prints the attribute value in hexidecimal.
1281 * @dev: class device that is converted into a Scsi_host.
1282 * @attr: device attribute, not used.
1283 * @buf: on return contains the attribute value in hexidecimal.
1285 * Returns: length of formatted string.
1287 #define lpfc_vport_param_hex_show(attr) \
1289 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1292 struct Scsi_Host *shost = class_to_shost(dev);\
1293 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1295 val = vport->cfg_##attr;\
1296 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1300 * lpfc_vport_param_init: Initialize a vport cfg attribute.
1303 * Macro that given an attr e.g. hba_queue_depth expands
1304 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1305 * takes a default argument, a minimum and maximum argument.
1307 * lpfc_##attr##_init: validates the min and max values then sets the
1308 * adapter config field accordingly, or uses the default if out of range
1309 * and prints an error message.
1310 * @phba: pointer the the adapter structure.
1311 * @val: integer attribute value.
1315 * -EINVAL if default used
1317 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1319 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1321 if (val >= minval && val <= maxval) {\
1322 vport->cfg_##attr = val;\
1325 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1326 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1327 "allowed range is ["#minval", "#maxval"]\n", val); \
1328 vport->cfg_##attr = default;\
1333 * lpfc_vport_param_set: Set a vport cfg attribute.
1336 * Macro that given an attr e.g. hba_queue_depth expands
1337 * into a function with the name lpfc_hba_queue_depth_set
1339 * lpfc_##attr##_set: validates the min and max values then sets the
1340 * adapter config field if in the valid range. prints error message
1341 * and does not set the parameter if invalid.
1342 * @phba: pointer the the adapter structure.
1343 * @val: integer attribute value.
1347 * -EINVAL if val is invalid
1349 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1351 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1353 if (val >= minval && val <= maxval) {\
1354 vport->cfg_##attr = val;\
1357 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1358 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1359 "allowed range is ["#minval", "#maxval"]\n", val); \
1364 * lpfc_vport_param_store: Set a vport attribute.
1367 * Macro that given an attr e.g. hba_queue_depth
1368 * expands into a function with the name lpfc_hba_queue_depth_store
1370 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1371 * use the lpfc_##attr##_set function to set the value.
1372 * @cdev: class device that is converted into a Scsi_host.
1373 * @buf: contains the attribute value in decimal.
1377 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1378 * length of buffer upon success.
1380 #define lpfc_vport_param_store(attr) \
1382 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1383 const char *buf, size_t count) \
1385 struct Scsi_Host *shost = class_to_shost(dev);\
1386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1388 if (!isdigit(buf[0]))\
1390 if (sscanf(buf, "%i", &val) != 1)\
1392 if (lpfc_##attr##_set(vport, val) == 0) \
1393 return strlen(buf);\
1399 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1400 static int lpfc_##name = defval;\
1401 module_param(lpfc_##name, int, 0);\
1402 MODULE_PARM_DESC(lpfc_##name, desc);\
1403 lpfc_param_init(name, defval, minval, maxval)
1405 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1406 static int lpfc_##name = defval;\
1407 module_param(lpfc_##name, int, 0);\
1408 MODULE_PARM_DESC(lpfc_##name, desc);\
1409 lpfc_param_show(name)\
1410 lpfc_param_init(name, defval, minval, maxval)\
1411 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1413 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1414 static int lpfc_##name = defval;\
1415 module_param(lpfc_##name, int, 0);\
1416 MODULE_PARM_DESC(lpfc_##name, desc);\
1417 lpfc_param_show(name)\
1418 lpfc_param_init(name, defval, minval, maxval)\
1419 lpfc_param_set(name, defval, minval, maxval)\
1420 lpfc_param_store(name)\
1421 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1422 lpfc_##name##_show, lpfc_##name##_store)
1424 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1425 static int lpfc_##name = defval;\
1426 module_param(lpfc_##name, int, 0);\
1427 MODULE_PARM_DESC(lpfc_##name, desc);\
1428 lpfc_param_hex_show(name)\
1429 lpfc_param_init(name, defval, minval, maxval)\
1430 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1432 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1433 static int lpfc_##name = defval;\
1434 module_param(lpfc_##name, int, 0);\
1435 MODULE_PARM_DESC(lpfc_##name, desc);\
1436 lpfc_param_hex_show(name)\
1437 lpfc_param_init(name, defval, minval, maxval)\
1438 lpfc_param_set(name, defval, minval, maxval)\
1439 lpfc_param_store(name)\
1440 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1441 lpfc_##name##_show, lpfc_##name##_store)
1443 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1444 static int lpfc_##name = defval;\
1445 module_param(lpfc_##name, int, 0);\
1446 MODULE_PARM_DESC(lpfc_##name, desc);\
1447 lpfc_vport_param_init(name, defval, minval, maxval)
1449 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1450 static int lpfc_##name = defval;\
1451 module_param(lpfc_##name, int, 0);\
1452 MODULE_PARM_DESC(lpfc_##name, desc);\
1453 lpfc_vport_param_show(name)\
1454 lpfc_vport_param_init(name, defval, minval, maxval)\
1455 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1457 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1458 static int lpfc_##name = defval;\
1459 module_param(lpfc_##name, int, 0);\
1460 MODULE_PARM_DESC(lpfc_##name, desc);\
1461 lpfc_vport_param_show(name)\
1462 lpfc_vport_param_init(name, defval, minval, maxval)\
1463 lpfc_vport_param_set(name, defval, minval, maxval)\
1464 lpfc_vport_param_store(name)\
1465 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1466 lpfc_##name##_show, lpfc_##name##_store)
1468 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1469 static int lpfc_##name = defval;\
1470 module_param(lpfc_##name, int, 0);\
1471 MODULE_PARM_DESC(lpfc_##name, desc);\
1472 lpfc_vport_param_hex_show(name)\
1473 lpfc_vport_param_init(name, defval, minval, maxval)\
1474 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1476 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1477 static int lpfc_##name = defval;\
1478 module_param(lpfc_##name, int, 0);\
1479 MODULE_PARM_DESC(lpfc_##name, desc);\
1480 lpfc_vport_param_hex_show(name)\
1481 lpfc_vport_param_init(name, defval, minval, maxval)\
1482 lpfc_vport_param_set(name, defval, minval, maxval)\
1483 lpfc_vport_param_store(name)\
1484 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1485 lpfc_##name##_show, lpfc_##name##_store)
1487 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1488 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1489 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1490 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1491 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1492 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1493 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1494 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1495 static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
1496 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1497 lpfc_option_rom_version_show, NULL);
1498 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1499 lpfc_num_discovered_ports_show, NULL);
1500 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1501 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1502 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1503 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1504 lpfc_board_mode_show, lpfc_board_mode_store);
1505 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1506 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1507 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1508 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1509 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1510 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1511 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1512 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1513 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1516 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1519 * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
1520 * @dev: class device that is converted into a Scsi_host.
1521 * @attr: device attribute, not used.
1522 * @buf: containing the string lpfc_soft_wwn_key.
1523 * @count: must be size of lpfc_soft_wwn_key.
1526 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1527 * length of buf indicates success
1530 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1531 const char *buf, size_t count)
1533 struct Scsi_Host *shost = class_to_shost(dev);
1534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1535 struct lpfc_hba *phba = vport->phba;
1536 unsigned int cnt = count;
1539 * We're doing a simple sanity check for soft_wwpn setting.
1540 * We require that the user write a specific key to enable
1541 * the soft_wwpn attribute to be settable. Once the attribute
1542 * is written, the enable key resets. If further updates are
1543 * desired, the key must be written again to re-enable the
1546 * The "key" is not secret - it is a hardcoded string shown
1547 * here. The intent is to protect against the random user or
1548 * application that is just writing attributes.
1551 /* count may include a LF at end of string */
1552 if (buf[cnt-1] == '\n')
1555 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1556 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1559 phba->soft_wwn_enable = 1;
1562 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1563 lpfc_soft_wwn_enable_store);
1566 * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
1567 * @dev: class device that is converted into a Scsi_host.
1568 * @attr: device attribute, not used.
1569 * @buf: on return contains the wwpn in hexidecimal.
1571 * Returns: size of formatted string.
1574 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1577 struct Scsi_Host *shost = class_to_shost(dev);
1578 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1579 struct lpfc_hba *phba = vport->phba;
1581 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1582 (unsigned long long)phba->cfg_soft_wwpn);
1586 * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
1587 * @dev class device that is converted into a Scsi_host.
1588 * @attr: device attribute, not used.
1589 * @buf: contains the wwpn in hexidecimal.
1590 * @count: number of wwpn bytes in buf
1593 * -EACCES hba reset not enabled, adapter over temp
1594 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1595 * -EIO error taking adapter offline or online
1596 * value of count on success
1599 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1600 const char *buf, size_t count)
1602 struct Scsi_Host *shost = class_to_shost(dev);
1603 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1604 struct lpfc_hba *phba = vport->phba;
1605 struct completion online_compl;
1606 int stat1=0, stat2=0;
1607 unsigned int i, j, cnt=count;
1610 if (!phba->cfg_enable_hba_reset)
1612 spin_lock_irq(&phba->hbalock);
1613 if (phba->over_temp_state == HBA_OVER_TEMP) {
1614 spin_unlock_irq(&phba->hbalock);
1617 spin_unlock_irq(&phba->hbalock);
1618 /* count may include a LF at end of string */
1619 if (buf[cnt-1] == '\n')
1622 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1623 ((cnt == 17) && (*buf++ != 'x')) ||
1624 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1627 phba->soft_wwn_enable = 0;
1629 memset(wwpn, 0, sizeof(wwpn));
1631 /* Validate and store the new name */
1632 for (i=0, j=0; i < 16; i++) {
1633 if ((*buf >= 'a') && (*buf <= 'f'))
1634 j = ((j << 4) | ((*buf++ -'a') + 10));
1635 else if ((*buf >= 'A') && (*buf <= 'F'))
1636 j = ((j << 4) | ((*buf++ -'A') + 10));
1637 else if ((*buf >= '0') && (*buf <= '9'))
1638 j = ((j << 4) | (*buf++ -'0'));
1642 wwpn[i/2] = j & 0xff;
1646 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1647 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1648 if (phba->cfg_soft_wwnn)
1649 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1651 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1652 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1654 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1656 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1657 "0463 lpfc_soft_wwpn attribute set failed to "
1658 "reinit adapter - %d\n", stat1);
1659 init_completion(&online_compl);
1660 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1661 wait_for_completion(&online_compl);
1663 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1664 "0464 lpfc_soft_wwpn attribute set failed to "
1665 "reinit adapter - %d\n", stat2);
1666 return (stat1 || stat2) ? -EIO : count;
1668 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1669 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1672 * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
1673 * @dev: class device that is converted into a Scsi_host.
1674 * @attr: device attribute, not used.
1675 * @buf: on return contains the wwnn in hexidecimal.
1677 * Returns: size of formatted string.
1680 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1683 struct Scsi_Host *shost = class_to_shost(dev);
1684 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1685 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1686 (unsigned long long)phba->cfg_soft_wwnn);
1690 * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
1691 * @cdev: class device that is converted into a Scsi_host.
1692 * @buf: contains the ww node name in hexidecimal.
1693 * @count: number of wwnn bytes in buf.
1696 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1697 * value of count on success
1700 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1701 const char *buf, size_t count)
1703 struct Scsi_Host *shost = class_to_shost(dev);
1704 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1705 unsigned int i, j, cnt=count;
1708 /* count may include a LF at end of string */
1709 if (buf[cnt-1] == '\n')
1712 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1713 ((cnt == 17) && (*buf++ != 'x')) ||
1714 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1718 * Allow wwnn to be set many times, as long as the enable is set.
1719 * However, once the wwpn is set, everything locks.
1722 memset(wwnn, 0, sizeof(wwnn));
1724 /* Validate and store the new name */
1725 for (i=0, j=0; i < 16; i++) {
1726 if ((*buf >= 'a') && (*buf <= 'f'))
1727 j = ((j << 4) | ((*buf++ -'a') + 10));
1728 else if ((*buf >= 'A') && (*buf <= 'F'))
1729 j = ((j << 4) | ((*buf++ -'A') + 10));
1730 else if ((*buf >= '0') && (*buf <= '9'))
1731 j = ((j << 4) | (*buf++ -'0'));
1735 wwnn[i/2] = j & 0xff;
1739 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1741 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1742 "lpfc%d: soft_wwnn set. Value will take effect upon "
1743 "setting of the soft_wwpn\n", phba->brd_no);
1747 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1748 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1751 static int lpfc_poll = 0;
1752 module_param(lpfc_poll, int, 0);
1753 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1755 " 1 - poll with interrupts enabled"
1756 " 3 - poll and disable FCP ring interrupts");
1758 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1759 lpfc_poll_show, lpfc_poll_store);
1761 int lpfc_sli_mode = 0;
1762 module_param(lpfc_sli_mode, int, 0);
1763 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1764 " 0 - auto (SLI-3 if supported),"
1765 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1766 " 3 - select SLI-3");
1768 int lpfc_enable_npiv = 0;
1769 module_param(lpfc_enable_npiv, int, 0);
1770 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1771 lpfc_param_show(enable_npiv);
1772 lpfc_param_init(enable_npiv, 0, 0, 1);
1773 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1774 lpfc_enable_npiv_show, NULL);
1777 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1778 # until the timer expires. Value range is [0,255]. Default value is 30.
1780 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1781 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1782 module_param(lpfc_nodev_tmo, int, 0);
1783 MODULE_PARM_DESC(lpfc_nodev_tmo,
1784 "Seconds driver will hold I/O waiting "
1785 "for a device to come back");
1788 * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
1789 * @dev: class converted to a Scsi_host structure.
1790 * @attr: device attribute, not used.
1791 * @buf: on return contains the dev loss timeout in decimal.
1793 * Returns: size of formatted string.
1796 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1799 struct Scsi_Host *shost = class_to_shost(dev);
1800 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1802 val = vport->cfg_devloss_tmo;
1803 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1807 * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
1808 * @vport: lpfc vport structure pointer.
1809 * @val: contains the nodev timeout value.
1812 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1813 * a kernel error message is printed and zero is returned.
1814 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1815 * Otherwise nodev tmo is set to the default value.
1818 * zero if already set or if val is in range
1819 * -EINVAL val out of range
1822 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1824 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1825 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1826 if (val != LPFC_DEF_DEVLOSS_TMO)
1827 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1828 "0407 Ignoring nodev_tmo module "
1829 "parameter because devloss_tmo is "
1834 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1835 vport->cfg_nodev_tmo = val;
1836 vport->cfg_devloss_tmo = val;
1839 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1840 "0400 lpfc_nodev_tmo attribute cannot be set to"
1841 " %d, allowed range is [%d, %d]\n",
1842 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1843 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1848 * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
1849 * @vport: lpfc vport structure pointer.
1852 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1855 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1857 struct Scsi_Host *shost;
1858 struct lpfc_nodelist *ndlp;
1860 shost = lpfc_shost_from_vport(vport);
1861 spin_lock_irq(shost->host_lock);
1862 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1863 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
1864 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1865 spin_unlock_irq(shost->host_lock);
1869 * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
1870 * @vport: lpfc vport structure pointer.
1871 * @val: contains the tmo value.
1874 * If the devloss tmo is already set or the vport dev loss tmo has changed
1875 * then a kernel error message is printed and zero is returned.
1876 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1877 * Otherwise nodev tmo is set to the default value.
1880 * zero if already set or if val is in range
1881 * -EINVAL val out of range
1884 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
1886 if (vport->dev_loss_tmo_changed ||
1887 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
1888 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1889 "0401 Ignoring change to nodev_tmo "
1890 "because devloss_tmo is set.\n");
1893 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1894 vport->cfg_nodev_tmo = val;
1895 vport->cfg_devloss_tmo = val;
1896 lpfc_update_rport_devloss_tmo(vport);
1899 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1900 "0403 lpfc_nodev_tmo attribute cannot be set to"
1901 "%d, allowed range is [%d, %d]\n",
1902 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1906 lpfc_vport_param_store(nodev_tmo)
1908 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1909 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1912 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1913 # disappear until the timer expires. Value range is [0,255]. Default
1916 module_param(lpfc_devloss_tmo, int, 0);
1917 MODULE_PARM_DESC(lpfc_devloss_tmo,
1918 "Seconds driver will hold I/O waiting "
1919 "for a device to come back");
1920 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1921 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1922 lpfc_vport_param_show(devloss_tmo)
1925 * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
1926 * @vport: lpfc vport structure pointer.
1927 * @val: contains the tmo value.
1930 * If val is in a valid range then set the vport nodev tmo,
1931 * devloss tmo, also set the vport dev loss tmo changed flag.
1932 * Else a kernel error message is printed.
1935 * zero if val is in range
1936 * -EINVAL val out of range
1939 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
1941 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1942 vport->cfg_nodev_tmo = val;
1943 vport->cfg_devloss_tmo = val;
1944 vport->dev_loss_tmo_changed = 1;
1945 lpfc_update_rport_devloss_tmo(vport);
1949 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1950 "0404 lpfc_devloss_tmo attribute cannot be set to"
1951 " %d, allowed range is [%d, %d]\n",
1952 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1956 lpfc_vport_param_store(devloss_tmo)
1957 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1958 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1961 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1962 # deluged with LOTS of information.
1963 # You can set a bit mask to record specific types of verbose messages:
1965 # LOG_ELS 0x1 ELS events
1966 # LOG_DISCOVERY 0x2 Link discovery events
1967 # LOG_MBOX 0x4 Mailbox events
1968 # LOG_INIT 0x8 Initialization events
1969 # LOG_LINK_EVENT 0x10 Link events
1970 # LOG_FCP 0x40 FCP traffic history
1971 # LOG_NODE 0x80 Node table events
1972 # LOG_MISC 0x400 Miscellaneous events
1973 # LOG_SLI 0x800 SLI events
1974 # LOG_FCP_ERROR 0x1000 Only log FCP errors
1975 # LOG_LIBDFC 0x2000 LIBDFC events
1976 # LOG_ALL_MSG 0xffff LOG all messages
1978 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1979 "Verbose logging bit-mask");
1982 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1983 # objects that have been registered with the nameserver after login.
1985 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1986 "Deregister nameserver objects before LOGO");
1989 # lun_queue_depth: This parameter is used to limit the number of outstanding
1990 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
1992 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1993 "Max number of FCP commands we can queue to a specific LUN");
1996 # hba_queue_depth: This parameter is used to limit the number of outstanding
1997 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
1998 # value is greater than the maximum number of exchanges supported by the HBA,
1999 # then maximum number of exchanges supported by the HBA is used to determine
2000 # the hba_queue_depth.
2002 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2003 "Max number of FCP commands we can queue to a lpfc HBA");
2006 # peer_port_login: This parameter allows/prevents logins
2007 # between peer ports hosted on the same physical port.
2008 # When this parameter is set 0 peer ports of same physical port
2009 # are not allowed to login to each other.
2010 # When this parameter is set 1 peer ports of same physical port
2011 # are allowed to login to each other.
2012 # Default value of this parameter is 0.
2014 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2015 "Allow peer ports on the same physical port to login to each "
2019 # restrict_login: This parameter allows/prevents logins
2020 # between Virtual Ports and remote initiators.
2021 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2022 # other initiators and will attempt to PLOGI all remote ports.
2023 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2024 # remote ports and will not attempt to PLOGI to other initiators.
2025 # This parameter does not restrict to the physical port.
2026 # This parameter does not restrict logins to Fabric resident remote ports.
2027 # Default value of this parameter is 1.
2029 static int lpfc_restrict_login = 1;
2030 module_param(lpfc_restrict_login, int, 0);
2031 MODULE_PARM_DESC(lpfc_restrict_login,
2032 "Restrict virtual ports login to remote initiators.");
2033 lpfc_vport_param_show(restrict_login);
2036 * lpfc_restrict_login_init: Set the vport restrict login flag.
2037 * @vport: lpfc vport structure pointer.
2038 * @val: contains the restrict login value.
2041 * If val is not in a valid range then log a kernel error message and set
2042 * the vport restrict login to one.
2043 * If the port type is physical clear the restrict login flag and return.
2044 * Else set the restrict login flag to val.
2047 * zero if val is in range
2048 * -EINVAL val out of range
2051 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2053 if (val < 0 || val > 1) {
2054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2055 "0422 lpfc_restrict_login attribute cannot "
2056 "be set to %d, allowed range is [0, 1]\n",
2058 vport->cfg_restrict_login = 1;
2061 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2062 vport->cfg_restrict_login = 0;
2065 vport->cfg_restrict_login = val;
2070 * lpfc_restrict_login_set: Set the vport restrict login flag.
2071 * @vport: lpfc vport structure pointer.
2072 * @val: contains the restrict login value.
2075 * If val is not in a valid range then log a kernel error message and set
2076 * the vport restrict login to one.
2077 * If the port type is physical and the val is not zero log a kernel
2078 * error message, clear the restrict login flag and return zero.
2079 * Else set the restrict login flag to val.
2082 * zero if val is in range
2083 * -EINVAL val out of range
2086 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2088 if (val < 0 || val > 1) {
2089 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2090 "0425 lpfc_restrict_login attribute cannot "
2091 "be set to %d, allowed range is [0, 1]\n",
2093 vport->cfg_restrict_login = 1;
2096 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2097 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2098 "0468 lpfc_restrict_login must be 0 for "
2099 "Physical ports.\n");
2100 vport->cfg_restrict_login = 0;
2103 vport->cfg_restrict_login = val;
2106 lpfc_vport_param_store(restrict_login);
2107 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2108 lpfc_restrict_login_show, lpfc_restrict_login_store);
2111 # Some disk devices have a "select ID" or "select Target" capability.
2112 # From a protocol standpoint "select ID" usually means select the
2113 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2114 # annex" which contains a table that maps a "select ID" (a number
2115 # between 0 and 7F) to an ALPA. By default, for compatibility with
2116 # older drivers, the lpfc driver scans this table from low ALPA to high
2119 # Turning on the scan-down variable (on = 1, off = 0) will
2120 # cause the lpfc driver to use an inverted table, effectively
2121 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2123 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2124 # and will not work across a fabric. Also this parameter will take
2125 # effect only in the case when ALPA map is not available.)
2127 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2128 "Start scanning for devices from highest ALPA to lowest");
2131 # lpfc_topology: link topology for init link
2132 # 0x0 = attempt loop mode then point-to-point
2133 # 0x01 = internal loopback mode
2134 # 0x02 = attempt point-to-point mode only
2135 # 0x04 = attempt loop mode only
2136 # 0x06 = attempt point-to-point mode then loop
2137 # Set point-to-point mode if you want to run as an N_Port.
2138 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2139 # Default value is 0.
2143 * lpfc_topology_set: Set the adapters topology field.
2144 * @phba: lpfc_hba pointer.
2145 * @val: topology value.
2148 * If val is in a valid range then set the adapter's topology field and
2149 * issue a lip; if the lip fails reset the topology to the old value.
2151 * If the value is not in range log a kernel error message and return an error.
2154 * zero if val is in range and lip okay
2155 * non-zero return value from lpfc_issue_lip()
2156 * -EINVAL val out of range
2159 lpfc_topology_set(struct lpfc_hba *phba, int val)
2163 if (val >= 0 && val <= 6) {
2164 prev_val = phba->cfg_topology;
2165 phba->cfg_topology = val;
2166 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2168 phba->cfg_topology = prev_val;
2171 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2172 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2173 "allowed range is [0, 6]\n",
2177 static int lpfc_topology = 0;
2178 module_param(lpfc_topology, int, 0);
2179 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2180 lpfc_param_show(topology)
2181 lpfc_param_init(topology, 0, 0, 6)
2182 lpfc_param_store(topology)
2183 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2184 lpfc_topology_show, lpfc_topology_store);
2187 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2189 # 0 = auto select (default)
2194 # Value range is [0,8]. Default value is 0.
2198 * lpfc_link_speed_set: Set the adapters link speed.
2199 * @phba: lpfc_hba pointer.
2200 * @val: link speed value.
2203 * If val is in a valid range then set the adapter's link speed field and
2204 * issue a lip; if the lip fails reset the link speed to the old value.
2207 * If the value is not in range log a kernel error message and return an error.
2210 * zero if val is in range and lip okay.
2211 * non-zero return value from lpfc_issue_lip()
2212 * -EINVAL val out of range
2215 lpfc_link_speed_set(struct lpfc_hba *phba, int val)
2220 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2221 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2222 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2223 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2224 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2227 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2228 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2229 prev_val = phba->cfg_link_speed;
2230 phba->cfg_link_speed = val;
2231 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2233 phba->cfg_link_speed = prev_val;
2237 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2238 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2239 "allowed range is [0, 8]\n",
2244 static int lpfc_link_speed = 0;
2245 module_param(lpfc_link_speed, int, 0);
2246 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2247 lpfc_param_show(link_speed)
2250 * lpfc_link_speed_init: Set the adapters link speed.
2251 * @phba: lpfc_hba pointer.
2252 * @val: link speed value.
2255 * If val is in a valid range then set the adapter's link speed field.
2258 * If the value is not in range log a kernel error message, clear the link
2259 * speed and return an error.
2262 * zero if val saved.
2263 * -EINVAL val out of range
2266 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2268 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2269 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2270 phba->cfg_link_speed = val;
2273 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2274 "0405 lpfc_link_speed attribute cannot "
2275 "be set to %d, allowed values are "
2276 "["LPFC_LINK_SPEED_STRING"]\n", val);
2277 phba->cfg_link_speed = 0;
2281 lpfc_param_store(link_speed)
2282 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2283 lpfc_link_speed_show, lpfc_link_speed_store);
2286 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2287 # Value range is [2,3]. Default value is 3.
2289 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2290 "Select Fibre Channel class of service for FCP sequences");
2293 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2294 # is [0,1]. Default value is 0.
2296 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2297 "Use ADISC on rediscovery to authenticate FCP devices");
2300 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2301 # range is [0,1]. Default value is 0.
2303 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
2306 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2307 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
2308 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
2309 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2310 # cr_delay is set to 0.
2312 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
2313 "interrupt response is generated");
2315 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
2316 "interrupt response is generated");
2319 # lpfc_multi_ring_support: Determines how many rings to spread available
2320 # cmd/rsp IOCB entries across.
2321 # Value range is [1,2]. Default value is 1.
2323 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
2324 "SLI rings to spread IOCB entries across");
2327 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2328 # identifies what rctl value to configure the additional ring for.
2329 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2331 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
2332 255, "Identifies RCTL for additional ring configuration");
2335 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2336 # identifies what type value to configure the additional ring for.
2337 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2339 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
2340 255, "Identifies TYPE for additional ring configuration");
2343 # lpfc_fdmi_on: controls FDMI support.
2344 # 0 = no FDMI support
2345 # 1 = support FDMI without attribute of hostname
2346 # 2 = support FDMI with attribute of hostname
2347 # Value range [0,2]. Default value is 0.
2349 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
2352 # Specifies the maximum number of ELS cmds we can have outstanding (for
2353 # discovery). Value range is [1,64]. Default value = 32.
2355 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
2356 "during discovery");
2359 # lpfc_max_luns: maximum allowed LUN.
2360 # Value range is [0,65535]. Default value is 255.
2361 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
2363 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
2366 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2367 # Value range is [1,255], default value is 10.
2369 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
2370 "Milliseconds driver will wait between polling FCP ring");
2373 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2374 # support this feature
2375 # 0 = MSI disabled (default)
2378 # Value range is [0,2]. Default value is 0.
2380 LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
2381 "MSI-X (2), if possible");
2384 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2385 # 0 = HBA resets disabled
2386 # 1 = HBA resets enabled (default)
2387 # Value range is [0,1]. Default value is 1.
2389 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
2392 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2393 # 0 = HBA Heartbeat disabled
2394 # 1 = HBA Heartbeat enabled (default)
2395 # Value range is [0,1]. Default value is 1.
2397 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
2400 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
2401 * This value can be set to values between 64 and 256. The default value is
2402 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2403 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2405 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
2406 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
2408 struct device_attribute *lpfc_hba_attrs[] = {
2410 &dev_attr_serialnum,
2411 &dev_attr_modeldesc,
2412 &dev_attr_modelname,
2413 &dev_attr_programtype,
2417 &dev_attr_option_rom_version,
2418 &dev_attr_link_state,
2419 &dev_attr_num_discovered_ports,
2420 &dev_attr_menlo_mgmt_mode,
2421 &dev_attr_lpfc_drvr_version,
2422 &dev_attr_lpfc_temp_sensor,
2423 &dev_attr_lpfc_log_verbose,
2424 &dev_attr_lpfc_lun_queue_depth,
2425 &dev_attr_lpfc_hba_queue_depth,
2426 &dev_attr_lpfc_peer_port_login,
2427 &dev_attr_lpfc_nodev_tmo,
2428 &dev_attr_lpfc_devloss_tmo,
2429 &dev_attr_lpfc_fcp_class,
2430 &dev_attr_lpfc_use_adisc,
2431 &dev_attr_lpfc_ack0,
2432 &dev_attr_lpfc_topology,
2433 &dev_attr_lpfc_scan_down,
2434 &dev_attr_lpfc_link_speed,
2435 &dev_attr_lpfc_cr_delay,
2436 &dev_attr_lpfc_cr_count,
2437 &dev_attr_lpfc_multi_ring_support,
2438 &dev_attr_lpfc_multi_ring_rctl,
2439 &dev_attr_lpfc_multi_ring_type,
2440 &dev_attr_lpfc_fdmi_on,
2441 &dev_attr_lpfc_max_luns,
2442 &dev_attr_lpfc_enable_npiv,
2443 &dev_attr_nport_evt_cnt,
2444 &dev_attr_board_mode,
2451 &dev_attr_npiv_info,
2452 &dev_attr_issue_reset,
2453 &dev_attr_lpfc_poll,
2454 &dev_attr_lpfc_poll_tmo,
2455 &dev_attr_lpfc_use_msi,
2456 &dev_attr_lpfc_soft_wwnn,
2457 &dev_attr_lpfc_soft_wwpn,
2458 &dev_attr_lpfc_soft_wwn_enable,
2459 &dev_attr_lpfc_enable_hba_reset,
2460 &dev_attr_lpfc_enable_hba_heartbeat,
2461 &dev_attr_lpfc_sg_seg_cnt,
2465 struct device_attribute *lpfc_vport_attrs[] = {
2467 &dev_attr_link_state,
2468 &dev_attr_num_discovered_ports,
2469 &dev_attr_lpfc_drvr_version,
2470 &dev_attr_lpfc_log_verbose,
2471 &dev_attr_lpfc_lun_queue_depth,
2472 &dev_attr_lpfc_nodev_tmo,
2473 &dev_attr_lpfc_devloss_tmo,
2474 &dev_attr_lpfc_hba_queue_depth,
2475 &dev_attr_lpfc_peer_port_login,
2476 &dev_attr_lpfc_restrict_login,
2477 &dev_attr_lpfc_fcp_class,
2478 &dev_attr_lpfc_use_adisc,
2479 &dev_attr_lpfc_fdmi_on,
2480 &dev_attr_lpfc_max_luns,
2481 &dev_attr_nport_evt_cnt,
2482 &dev_attr_npiv_info,
2483 &dev_attr_lpfc_enable_da_id,
2488 * sysfs_ctlreg_write: Write method for writing to ctlreg.
2489 * @kobj: kernel kobject that contains the kernel class device.
2490 * @bin_attr: kernel attributes passed to us.
2491 * @buf: contains the data to be written to the adapter IOREG space.
2492 * @off: offset into buffer to beginning of data.
2493 * @count: bytes to transfer.
2496 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2497 * Uses the adapter io control registers to send buf contents to the adapter.
2500 * -ERANGE off and count combo out of range
2501 * -EINVAL off, count or buff address invalid
2502 * -EPERM adapter is offline
2503 * value of count, buf contents written
2506 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2507 char *buf, loff_t off, size_t count)
2510 struct device *dev = container_of(kobj, struct device, kobj);
2511 struct Scsi_Host *shost = class_to_shost(dev);
2512 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2513 struct lpfc_hba *phba = vport->phba;
2515 if ((off + count) > FF_REG_AREA_SIZE)
2518 if (count == 0) return 0;
2520 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2523 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
2527 spin_lock_irq(&phba->hbalock);
2528 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
2529 writel(*((uint32_t *)(buf + buf_off)),
2530 phba->ctrl_regs_memmap_p + off + buf_off);
2532 spin_unlock_irq(&phba->hbalock);
2538 * sysfs_ctlreg_read: Read method for reading from ctlreg.
2539 * @kobj: kernel kobject that contains the kernel class device.
2540 * @bin_attr: kernel attributes passed to us.
2541 * @buf: if succesful contains the data from the adapter IOREG space.
2542 * @off: offset into buffer to beginning of data.
2543 * @count: bytes to transfer.
2546 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2547 * Uses the adapter io control registers to read data into buf.
2550 * -ERANGE off and count combo out of range
2551 * -EINVAL off, count or buff address invalid
2552 * value of count, buf contents read
2555 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2556 char *buf, loff_t off, size_t count)
2560 struct device *dev = container_of(kobj, struct device, kobj);
2561 struct Scsi_Host *shost = class_to_shost(dev);
2562 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2563 struct lpfc_hba *phba = vport->phba;
2565 if (off > FF_REG_AREA_SIZE)
2568 if ((off + count) > FF_REG_AREA_SIZE)
2569 count = FF_REG_AREA_SIZE - off;
2571 if (count == 0) return 0;
2573 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2576 spin_lock_irq(&phba->hbalock);
2578 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
2579 tmp_ptr = (uint32_t *)(buf + buf_off);
2580 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
2583 spin_unlock_irq(&phba->hbalock);
2588 static struct bin_attribute sysfs_ctlreg_attr = {
2591 .mode = S_IRUSR | S_IWUSR,
2594 .read = sysfs_ctlreg_read,
2595 .write = sysfs_ctlreg_write,
2599 * sysfs_mbox_idle: frees the sysfs mailbox.
2600 * @phba: lpfc_hba pointer
2603 sysfs_mbox_idle(struct lpfc_hba *phba)
2605 phba->sysfs_mbox.state = SMBOX_IDLE;
2606 phba->sysfs_mbox.offset = 0;
2608 if (phba->sysfs_mbox.mbox) {
2609 mempool_free(phba->sysfs_mbox.mbox,
2610 phba->mbox_mem_pool);
2611 phba->sysfs_mbox.mbox = NULL;
2616 * sysfs_mbox_write: Write method for writing information via mbox.
2617 * @kobj: kernel kobject that contains the kernel class device.
2618 * @bin_attr: kernel attributes passed to us.
2619 * @buf: contains the data to be written to sysfs mbox.
2620 * @off: offset into buffer to beginning of data.
2621 * @count: bytes to transfer.
2624 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2625 * Uses the sysfs mbox to send buf contents to the adapter.
2628 * -ERANGE off and count combo out of range
2629 * -EINVAL off, count or buff address invalid
2630 * zero if count is zero
2631 * -EPERM adapter is offline
2632 * -ENOMEM failed to allocate memory for the mail box
2633 * -EAGAIN offset, state or mbox is NULL
2634 * count number of bytes transferred
2637 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
2638 char *buf, loff_t off, size_t count)
2640 struct device *dev = container_of(kobj, struct device, kobj);
2641 struct Scsi_Host *shost = class_to_shost(dev);
2642 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2643 struct lpfc_hba *phba = vport->phba;
2644 struct lpfcMboxq *mbox = NULL;
2646 if ((count + off) > MAILBOX_CMD_SIZE)
2649 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2656 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2659 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
2662 spin_lock_irq(&phba->hbalock);
2665 if (phba->sysfs_mbox.mbox)
2666 mempool_free(mbox, phba->mbox_mem_pool);
2668 phba->sysfs_mbox.mbox = mbox;
2669 phba->sysfs_mbox.state = SMBOX_WRITING;
2671 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
2672 phba->sysfs_mbox.offset != off ||
2673 phba->sysfs_mbox.mbox == NULL) {
2674 sysfs_mbox_idle(phba);
2675 spin_unlock_irq(&phba->hbalock);
2680 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
2683 phba->sysfs_mbox.offset = off + count;
2685 spin_unlock_irq(&phba->hbalock);
2691 * sysfs_mbox_read: Read method for reading information via mbox.
2692 * @kobj: kernel kobject that contains the kernel class device.
2693 * @bin_attr: kernel attributes passed to us.
2694 * @buf: contains the data to be read from sysfs mbox.
2695 * @off: offset into buffer to beginning of data.
2696 * @count: bytes to transfer.
2699 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2700 * Uses the sysfs mbox to receive data from to the adapter.
2703 * -ERANGE off greater than mailbox command size
2704 * -EINVAL off, count or buff address invalid
2705 * zero if off and count are zero
2706 * -EACCES adapter over temp
2707 * -EPERM garbage can value to catch a multitude of errors
2708 * -EAGAIN management IO not permitted, state or off error
2709 * -ETIME mailbox timeout
2710 * -ENODEV mailbox error
2711 * count number of bytes transferred
2714 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2715 char *buf, loff_t off, size_t count)
2717 struct device *dev = container_of(kobj, struct device, kobj);
2718 struct Scsi_Host *shost = class_to_shost(dev);
2719 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2720 struct lpfc_hba *phba = vport->phba;
2723 if (off > MAILBOX_CMD_SIZE)
2726 if ((count + off) > MAILBOX_CMD_SIZE)
2727 count = MAILBOX_CMD_SIZE - off;
2729 if (off % 4 || count % 4 || (unsigned long)buf % 4)
2732 if (off && count == 0)
2735 spin_lock_irq(&phba->hbalock);
2737 if (phba->over_temp_state == HBA_OVER_TEMP) {
2738 sysfs_mbox_idle(phba);
2739 spin_unlock_irq(&phba->hbalock);
2744 phba->sysfs_mbox.state == SMBOX_WRITING &&
2745 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
2747 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
2751 case MBX_CONFIG_LINK:
2752 case MBX_CONFIG_RING:
2753 case MBX_RESET_RING:
2754 case MBX_UNREG_LOGIN:
2756 case MBX_DUMP_CONTEXT:
2761 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
2762 printk(KERN_WARNING "mbox_read:Command 0x%x "
2763 "is illegal in on-line state\n",
2764 phba->sysfs_mbox.mbox->mb.mbxCommand);
2765 sysfs_mbox_idle(phba);
2766 spin_unlock_irq(&phba->hbalock);
2770 case MBX_WRITE_VPARMS:
2773 case MBX_READ_CONFIG:
2774 case MBX_READ_RCONFIG:
2775 case MBX_READ_STATUS:
2778 case MBX_READ_LNK_STAT:
2779 case MBX_DUMP_MEMORY:
2781 case MBX_UPDATE_CFG:
2782 case MBX_KILL_BOARD:
2784 case MBX_LOAD_EXP_ROM:
2786 case MBX_DEL_LD_ENTRY:
2787 case MBX_SET_VARIABLE:
2789 case MBX_PORT_CAPABILITIES:
2790 case MBX_PORT_IOV_CONTROL:
2792 case MBX_READ_SPARM64:
2796 case MBX_REG_LOGIN64:
2797 case MBX_CONFIG_PORT:
2798 case MBX_RUN_BIU_DIAG:
2799 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
2800 phba->sysfs_mbox.mbox->mb.mbxCommand);
2801 sysfs_mbox_idle(phba);
2802 spin_unlock_irq(&phba->hbalock);
2805 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
2806 phba->sysfs_mbox.mbox->mb.mbxCommand);
2807 sysfs_mbox_idle(phba);
2808 spin_unlock_irq(&phba->hbalock);
2812 /* If HBA encountered an error attention, allow only DUMP
2813 * or RESTART mailbox commands until the HBA is restarted.
2815 if (phba->pport->stopped &&
2816 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_DUMP_MEMORY &&
2817 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_RESTART &&
2818 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_VPARMS &&
2819 phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_WWN)
2820 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2821 "1259 mbox: Issued mailbox cmd "
2822 "0x%x while in stopped state.\n",
2823 phba->sysfs_mbox.mbox->mb.mbxCommand);
2825 phba->sysfs_mbox.mbox->vport = vport;
2827 /* Don't allow mailbox commands to be sent when blocked
2828 * or when in the middle of discovery
2830 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
2831 sysfs_mbox_idle(phba);
2832 spin_unlock_irq(&phba->hbalock);
2836 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2837 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
2839 spin_unlock_irq(&phba->hbalock);
2840 rc = lpfc_sli_issue_mbox (phba,
2841 phba->sysfs_mbox.mbox,
2843 spin_lock_irq(&phba->hbalock);
2846 spin_unlock_irq(&phba->hbalock);
2847 rc = lpfc_sli_issue_mbox_wait (phba,
2848 phba->sysfs_mbox.mbox,
2849 lpfc_mbox_tmo_val(phba,
2850 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
2851 spin_lock_irq(&phba->hbalock);
2854 if (rc != MBX_SUCCESS) {
2855 if (rc == MBX_TIMEOUT) {
2856 phba->sysfs_mbox.mbox = NULL;
2858 sysfs_mbox_idle(phba);
2859 spin_unlock_irq(&phba->hbalock);
2860 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
2862 phba->sysfs_mbox.state = SMBOX_READING;
2864 else if (phba->sysfs_mbox.offset != off ||
2865 phba->sysfs_mbox.state != SMBOX_READING) {
2866 printk(KERN_WARNING "mbox_read: Bad State\n");
2867 sysfs_mbox_idle(phba);
2868 spin_unlock_irq(&phba->hbalock);
2872 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
2874 phba->sysfs_mbox.offset = off + count;
2876 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
2877 sysfs_mbox_idle(phba);
2879 spin_unlock_irq(&phba->hbalock);
2884 static struct bin_attribute sysfs_mbox_attr = {
2887 .mode = S_IRUSR | S_IWUSR,
2889 .size = MAILBOX_CMD_SIZE,
2890 .read = sysfs_mbox_read,
2891 .write = sysfs_mbox_write,
2895 * lpfc_alloc_sysfs_attr: Creates the ctlreg and mbox entries.
2896 * @vport: address of lpfc vport structure.
2900 * error return code from sysfs_create_bin_file()
2903 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
2905 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2908 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
2909 &sysfs_ctlreg_attr);
2913 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
2916 goto out_remove_ctlreg_attr;
2919 out_remove_ctlreg_attr:
2920 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
2926 * lpfc_free_sysfs_attr: Removes the ctlreg and mbox entries.
2927 * @vport: address of lpfc vport structure.
2930 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
2932 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2934 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
2935 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
2940 * Dynamic FC Host Attributes Support
2944 * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
2945 * @shost: kernel scsi host pointer.
2948 lpfc_get_host_port_id(struct Scsi_Host *shost)
2950 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2952 /* note: fc_myDID already in cpu endianness */
2953 fc_host_port_id(shost) = vport->fc_myDID;
2957 * lpfc_get_host_port_type: Set the value of the scsi host port type.
2958 * @shost: kernel scsi host pointer.
2961 lpfc_get_host_port_type(struct Scsi_Host *shost)
2963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2964 struct lpfc_hba *phba = vport->phba;
2966 spin_lock_irq(shost->host_lock);
2968 if (vport->port_type == LPFC_NPIV_PORT) {
2969 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2970 } else if (lpfc_is_link_up(phba)) {
2971 if (phba->fc_topology == TOPOLOGY_LOOP) {
2972 if (vport->fc_flag & FC_PUBLIC_LOOP)
2973 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2975 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
2977 if (vport->fc_flag & FC_FABRIC)
2978 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2980 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2983 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2985 spin_unlock_irq(shost->host_lock);
2989 * lpfc_get_host_port_state: Set the value of the scsi host port state.
2990 * @shost: kernel scsi host pointer.
2993 lpfc_get_host_port_state(struct Scsi_Host *shost)
2995 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2996 struct lpfc_hba *phba = vport->phba;
2998 spin_lock_irq(shost->host_lock);
3000 if (vport->fc_flag & FC_OFFLINE_MODE)
3001 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3003 switch (phba->link_state) {
3004 case LPFC_LINK_UNKNOWN:
3005 case LPFC_LINK_DOWN:
3006 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3010 case LPFC_HBA_READY:
3011 /* Links up, beyond this port_type reports state */
3012 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3014 case LPFC_HBA_ERROR:
3015 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3018 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3023 spin_unlock_irq(shost->host_lock);
3027 * lpfc_get_host_speed: Set the value of the scsi host speed.
3028 * @shost: kernel scsi host pointer.
3031 lpfc_get_host_speed(struct Scsi_Host *shost)
3033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3034 struct lpfc_hba *phba = vport->phba;
3036 spin_lock_irq(shost->host_lock);
3038 if (lpfc_is_link_up(phba)) {
3039 switch(phba->fc_linkspeed) {
3041 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3044 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3047 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3050 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3053 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3057 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3059 spin_unlock_irq(shost->host_lock);
3063 * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
3064 * @shost: kernel scsi host pointer.
3067 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3069 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3070 struct lpfc_hba *phba = vport->phba;
3073 spin_lock_irq(shost->host_lock);
3075 if ((vport->fc_flag & FC_FABRIC) ||
3076 ((phba->fc_topology == TOPOLOGY_LOOP) &&
3077 (vport->fc_flag & FC_PUBLIC_LOOP)))
3078 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
3080 /* fabric is local port if there is no F/FL_Port */
3083 spin_unlock_irq(shost->host_lock);
3085 fc_host_fabric_name(shost) = node_name;
3089 * lpfc_get_stats: Return statistical information about the adapter.
3090 * @shost: kernel scsi host pointer.
3093 * NULL on error for link down, no mbox pool, sli2 active,
3094 * management not allowed, memory allocation error, or mbox error.
3098 * address of the adapter host statistics
3100 static struct fc_host_statistics *
3101 lpfc_get_stats(struct Scsi_Host *shost)
3103 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3104 struct lpfc_hba *phba = vport->phba;
3105 struct lpfc_sli *psli = &phba->sli;
3106 struct fc_host_statistics *hs = &phba->link_stats;
3107 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
3108 LPFC_MBOXQ_t *pmboxq;
3110 unsigned long seconds;
3114 * prevent udev from issuing mailbox commands until the port is
3117 if (phba->link_state < LPFC_LINK_DOWN ||
3118 !phba->mbox_mem_pool ||
3119 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
3122 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3125 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3128 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3131 pmb->mbxCommand = MBX_READ_STATUS;
3132 pmb->mbxOwner = OWN_HOST;
3133 pmboxq->context1 = NULL;
3134 pmboxq->vport = vport;
3136 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3137 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3138 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3140 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3142 if (rc != MBX_SUCCESS) {
3143 if (rc != MBX_TIMEOUT)
3144 mempool_free(pmboxq, phba->mbox_mem_pool);
3148 memset(hs, 0, sizeof (struct fc_host_statistics));
3150 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3151 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3152 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3153 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3155 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3156 pmb->mbxCommand = MBX_READ_LNK_STAT;
3157 pmb->mbxOwner = OWN_HOST;
3158 pmboxq->context1 = NULL;
3159 pmboxq->vport = vport;
3161 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3162 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3163 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3165 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3167 if (rc != MBX_SUCCESS) {
3168 if (rc != MBX_TIMEOUT)
3169 mempool_free(pmboxq, phba->mbox_mem_pool);
3173 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3174 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3175 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3176 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3177 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3178 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3179 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3181 hs->link_failure_count -= lso->link_failure_count;
3182 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3183 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3184 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3185 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3186 hs->invalid_crc_count -= lso->invalid_crc_count;
3187 hs->error_frames -= lso->error_frames;
3189 if (phba->fc_topology == TOPOLOGY_LOOP) {
3190 hs->lip_count = (phba->fc_eventTag >> 1);
3191 hs->lip_count -= lso->link_events;
3195 hs->nos_count = (phba->fc_eventTag >> 1);
3196 hs->nos_count -= lso->link_events;
3199 hs->dumped_frames = -1;
3201 seconds = get_seconds();
3202 if (seconds < psli->stats_start)
3203 hs->seconds_since_last_reset = seconds +
3204 ((unsigned long)-1 - psli->stats_start);
3206 hs->seconds_since_last_reset = seconds - psli->stats_start;
3208 mempool_free(pmboxq, phba->mbox_mem_pool);
3214 * lpfc_reset_stats: Copy the adapter link stats information.
3215 * @shost: kernel scsi host pointer.
3218 lpfc_reset_stats(struct Scsi_Host *shost)
3220 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3221 struct lpfc_hba *phba = vport->phba;
3222 struct lpfc_sli *psli = &phba->sli;
3223 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
3224 LPFC_MBOXQ_t *pmboxq;
3228 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3231 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3234 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3237 pmb->mbxCommand = MBX_READ_STATUS;
3238 pmb->mbxOwner = OWN_HOST;
3239 pmb->un.varWords[0] = 0x1; /* reset request */
3240 pmboxq->context1 = NULL;
3241 pmboxq->vport = vport;
3243 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3244 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3245 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3247 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3249 if (rc != MBX_SUCCESS) {
3250 if (rc != MBX_TIMEOUT)
3251 mempool_free(pmboxq, phba->mbox_mem_pool);
3255 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
3256 pmb->mbxCommand = MBX_READ_LNK_STAT;
3257 pmb->mbxOwner = OWN_HOST;
3258 pmboxq->context1 = NULL;
3259 pmboxq->vport = vport;
3261 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3262 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
3263 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3265 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3267 if (rc != MBX_SUCCESS) {
3268 if (rc != MBX_TIMEOUT)
3269 mempool_free( pmboxq, phba->mbox_mem_pool);
3273 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3274 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3275 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3276 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3277 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3278 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3279 lso->error_frames = pmb->un.varRdLnk.crcCnt;
3280 lso->link_events = (phba->fc_eventTag >> 1);
3282 psli->stats_start = get_seconds();
3284 mempool_free(pmboxq, phba->mbox_mem_pool);
3290 * The LPFC driver treats linkdown handling as target loss events so there
3291 * are no sysfs handlers for link_down_tmo.
3295 * lpfc_get_node_by_target: Return the nodelist for a target.
3296 * @starget: kernel scsi target pointer.
3299 * address of the node list if found
3300 * NULL target not found
3302 static struct lpfc_nodelist *
3303 lpfc_get_node_by_target(struct scsi_target *starget)
3305 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
3306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3307 struct lpfc_nodelist *ndlp;
3309 spin_lock_irq(shost->host_lock);
3310 /* Search for this, mapped, target ID */
3311 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3312 if (NLP_CHK_NODE_ACT(ndlp) &&
3313 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
3314 starget->id == ndlp->nlp_sid) {
3315 spin_unlock_irq(shost->host_lock);
3319 spin_unlock_irq(shost->host_lock);
3324 * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
3325 * @starget: kernel scsi target pointer.
3328 lpfc_get_starget_port_id(struct scsi_target *starget)
3330 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3332 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
3336 * lpfc_get_starget_node_name: Set the target node name.
3337 * @starget: kernel scsi target pointer.
3339 * Description: Set the target node name to the ndlp node name wwn or zero.
3342 lpfc_get_starget_node_name(struct scsi_target *starget)
3344 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3346 fc_starget_node_name(starget) =
3347 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
3351 * lpfc_get_starget_port_name: Set the target port name.
3352 * @starget: kernel scsi target pointer.
3354 * Description: set the target port name to the ndlp port name wwn or zero.
3357 lpfc_get_starget_port_name(struct scsi_target *starget)
3359 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
3361 fc_starget_port_name(starget) =
3362 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
3366 * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
3367 * @rport: fc rport address.
3368 * @timeout: new value for dev loss tmo.
3371 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3372 * dev_loss_tmo to one.
3375 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
3378 rport->dev_loss_tmo = timeout;
3380 rport->dev_loss_tmo = 1;
3384 * lpfc_rport_show_function: Return rport target information.
3387 * Macro that uses field to generate a function with the name lpfc_show_rport_
3389 * lpfc_show_rport_##field: returns the bytes formatted in buf
3390 * @cdev: class converted to an fc_rport.
3391 * @buf: on return contains the target_field or zero.
3393 * Returns: size of formatted string.
3395 #define lpfc_rport_show_function(field, format_string, sz, cast) \
3397 lpfc_show_rport_##field (struct device *dev, \
3398 struct device_attribute *attr, \
3401 struct fc_rport *rport = transport_class_to_rport(dev); \
3402 struct lpfc_rport_data *rdata = rport->hostdata; \
3403 return snprintf(buf, sz, format_string, \
3404 (rdata->target) ? cast rdata->target->field : 0); \
3407 #define lpfc_rport_rd_attr(field, format_string, sz) \
3408 lpfc_rport_show_function(field, format_string, sz, ) \
3409 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3412 struct fc_function_template lpfc_transport_functions = {
3413 /* fixed attributes the driver supports */
3414 .show_host_node_name = 1,
3415 .show_host_port_name = 1,
3416 .show_host_supported_classes = 1,
3417 .show_host_supported_fc4s = 1,
3418 .show_host_supported_speeds = 1,
3419 .show_host_maxframe_size = 1,
3421 /* dynamic attributes the driver supports */
3422 .get_host_port_id = lpfc_get_host_port_id,
3423 .show_host_port_id = 1,
3425 .get_host_port_type = lpfc_get_host_port_type,
3426 .show_host_port_type = 1,
3428 .get_host_port_state = lpfc_get_host_port_state,
3429 .show_host_port_state = 1,
3431 /* active_fc4s is shown but doesn't change (thus no get function) */
3432 .show_host_active_fc4s = 1,
3434 .get_host_speed = lpfc_get_host_speed,
3435 .show_host_speed = 1,
3437 .get_host_fabric_name = lpfc_get_host_fabric_name,
3438 .show_host_fabric_name = 1,
3441 * The LPFC driver treats linkdown handling as target loss events
3442 * so there are no sysfs handlers for link_down_tmo.
3445 .get_fc_host_stats = lpfc_get_stats,
3446 .reset_fc_host_stats = lpfc_reset_stats,
3448 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3449 .show_rport_maxframe_size = 1,
3450 .show_rport_supported_classes = 1,
3452 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3453 .show_rport_dev_loss_tmo = 1,
3455 .get_starget_port_id = lpfc_get_starget_port_id,
3456 .show_starget_port_id = 1,
3458 .get_starget_node_name = lpfc_get_starget_node_name,
3459 .show_starget_node_name = 1,
3461 .get_starget_port_name = lpfc_get_starget_port_name,
3462 .show_starget_port_name = 1,
3464 .issue_fc_host_lip = lpfc_issue_lip,
3465 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3466 .terminate_rport_io = lpfc_terminate_rport_io,
3468 .dd_fcvport_size = sizeof(struct lpfc_vport *),
3471 struct fc_function_template lpfc_vport_transport_functions = {
3472 /* fixed attributes the driver supports */
3473 .show_host_node_name = 1,
3474 .show_host_port_name = 1,
3475 .show_host_supported_classes = 1,
3476 .show_host_supported_fc4s = 1,
3477 .show_host_supported_speeds = 1,
3478 .show_host_maxframe_size = 1,
3480 /* dynamic attributes the driver supports */
3481 .get_host_port_id = lpfc_get_host_port_id,
3482 .show_host_port_id = 1,
3484 .get_host_port_type = lpfc_get_host_port_type,
3485 .show_host_port_type = 1,
3487 .get_host_port_state = lpfc_get_host_port_state,
3488 .show_host_port_state = 1,
3490 /* active_fc4s is shown but doesn't change (thus no get function) */
3491 .show_host_active_fc4s = 1,
3493 .get_host_speed = lpfc_get_host_speed,
3494 .show_host_speed = 1,
3496 .get_host_fabric_name = lpfc_get_host_fabric_name,
3497 .show_host_fabric_name = 1,
3500 * The LPFC driver treats linkdown handling as target loss events
3501 * so there are no sysfs handlers for link_down_tmo.
3504 .get_fc_host_stats = lpfc_get_stats,
3505 .reset_fc_host_stats = lpfc_reset_stats,
3507 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
3508 .show_rport_maxframe_size = 1,
3509 .show_rport_supported_classes = 1,
3511 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
3512 .show_rport_dev_loss_tmo = 1,
3514 .get_starget_port_id = lpfc_get_starget_port_id,
3515 .show_starget_port_id = 1,
3517 .get_starget_node_name = lpfc_get_starget_node_name,
3518 .show_starget_node_name = 1,
3520 .get_starget_port_name = lpfc_get_starget_port_name,
3521 .show_starget_port_name = 1,
3523 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
3524 .terminate_rport_io = lpfc_terminate_rport_io,
3526 .vport_disable = lpfc_vport_disable,
3530 * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
3531 * @phba: lpfc_hba pointer.
3534 lpfc_get_cfgparam(struct lpfc_hba *phba)
3536 lpfc_cr_delay_init(phba, lpfc_cr_delay);
3537 lpfc_cr_count_init(phba, lpfc_cr_count);
3538 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
3539 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
3540 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
3541 lpfc_ack0_init(phba, lpfc_ack0);
3542 lpfc_topology_init(phba, lpfc_topology);
3543 lpfc_link_speed_init(phba, lpfc_link_speed);
3544 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
3545 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
3546 lpfc_use_msi_init(phba, lpfc_use_msi);
3547 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
3548 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
3549 phba->cfg_poll = lpfc_poll;
3550 phba->cfg_soft_wwnn = 0L;
3551 phba->cfg_soft_wwpn = 0L;
3552 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
3553 /* Also reinitialize the host templates with new values. */
3554 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3555 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
3557 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3558 * used to create the sg_dma_buf_pool must be dynamically calculated.
3559 * 2 segments are added since the IOCB needs a command and response bde.
3561 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
3562 sizeof(struct fcp_rsp) +
3563 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
3564 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
3569 * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
3570 * @vport: lpfc_vport pointer.
3573 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
3575 lpfc_log_verbose_init(vport, lpfc_log_verbose);
3576 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
3577 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
3578 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
3579 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
3580 lpfc_restrict_login_init(vport, lpfc_restrict_login);
3581 lpfc_fcp_class_init(vport, lpfc_fcp_class);
3582 lpfc_use_adisc_init(vport, lpfc_use_adisc);
3583 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
3584 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
3585 lpfc_max_luns_init(vport, lpfc_max_luns);
3586 lpfc_scan_down_init(vport, lpfc_scan_down);
3587 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);