1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/aer.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_tcq.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_version.h"
45 #include "lpfc_compat.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
49 #define LPFC_DEF_DEVLOSS_TMO 30
50 #define LPFC_MIN_DEVLOSS_TMO 1
51 #define LPFC_MAX_DEVLOSS_TMO 255
53 #define LPFC_MAX_LINK_SPEED 8
54 #define LPFC_LINK_SPEED_BITMAP 0x00000117
55 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
58 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
59 * @incr: integer to convert.
60 * @hdw: ascii string holding converted integer plus a string terminator.
63 * JEDEC Joint Electron Device Engineering Council.
64 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
65 * character string. The string is then terminated with a NULL in byte 9.
66 * Hex 0-9 becomes ascii '0' to '9'.
67 * Hex a-f becomes ascii '=' to 'B' capital B.
70 * Coded for 32 bit integers only.
73 lpfc_jedec_to_ascii(int incr, char hdw[])
76 for (i = 0; i < 8; i++) {
79 hdw[7 - i] = 0x30 + j;
81 hdw[7 - i] = 0x61 + j - 10;
89 * lpfc_drvr_version_show - Return the Emulex driver string with version number
90 * @dev: class unused variable.
91 * @attr: device attribute, not used.
92 * @buf: on return contains the module description text.
94 * Returns: size of formatted string.
97 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
100 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
104 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
107 struct Scsi_Host *shost = class_to_shost(dev);
108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
109 struct lpfc_hba *phba = vport->phba;
111 if (phba->cfg_enable_bg)
112 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
113 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
115 return snprintf(buf, PAGE_SIZE,
116 "BlockGuard Not Supported\n");
118 return snprintf(buf, PAGE_SIZE,
119 "BlockGuard Disabled\n");
123 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
126 struct Scsi_Host *shost = class_to_shost(dev);
127 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
128 struct lpfc_hba *phba = vport->phba;
130 return snprintf(buf, PAGE_SIZE, "%llu\n",
131 (unsigned long long)phba->bg_guard_err_cnt);
135 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
138 struct Scsi_Host *shost = class_to_shost(dev);
139 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
140 struct lpfc_hba *phba = vport->phba;
142 return snprintf(buf, PAGE_SIZE, "%llu\n",
143 (unsigned long long)phba->bg_apptag_err_cnt);
147 lpfc_bg_reftag_err_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;
154 return snprintf(buf, PAGE_SIZE, "%llu\n",
155 (unsigned long long)phba->bg_reftag_err_cnt);
159 * lpfc_info_show - Return some pci info about the host in ascii
160 * @dev: class converted to a Scsi_host structure.
161 * @attr: device attribute, not used.
162 * @buf: on return contains the formatted text from lpfc_info().
164 * Returns: size of formatted string.
167 lpfc_info_show(struct device *dev, struct device_attribute *attr,
170 struct Scsi_Host *host = class_to_shost(dev);
172 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
176 * lpfc_serialnum_show - Return the hba serial number in ascii
177 * @dev: class converted to a Scsi_host structure.
178 * @attr: device attribute, not used.
179 * @buf: on return contains the formatted text serial number.
181 * Returns: size of formatted string.
184 lpfc_serialnum_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->SerialNumber);
195 * lpfc_temp_sensor_show - Return the temperature sensor level
196 * @dev: class converted to a Scsi_host structure.
197 * @attr: device attribute, not used.
198 * @buf: on return contains the formatted support level.
201 * Returns a number indicating the temperature sensor level currently
202 * supported, zero or one in ascii.
204 * Returns: size of formatted string.
207 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
210 struct Scsi_Host *shost = class_to_shost(dev);
211 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
212 struct lpfc_hba *phba = vport->phba;
213 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
217 * lpfc_modeldesc_show - Return the model description of the hba
218 * @dev: class converted to a Scsi_host structure.
219 * @attr: device attribute, not used.
220 * @buf: on return contains the scsi vpd model description.
222 * Returns: size of formatted string.
225 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
228 struct Scsi_Host *shost = class_to_shost(dev);
229 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
230 struct lpfc_hba *phba = vport->phba;
232 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
236 * lpfc_modelname_show - Return the model name of the hba
237 * @dev: class converted to a Scsi_host structure.
238 * @attr: device attribute, not used.
239 * @buf: on return contains the scsi vpd model name.
241 * Returns: size of formatted string.
244 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
247 struct Scsi_Host *shost = class_to_shost(dev);
248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
249 struct lpfc_hba *phba = vport->phba;
251 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
255 * lpfc_programtype_show - Return the program type of the hba
256 * @dev: class converted to a Scsi_host structure.
257 * @attr: device attribute, not used.
258 * @buf: on return contains the scsi vpd program type.
260 * Returns: size of formatted string.
263 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
266 struct Scsi_Host *shost = class_to_shost(dev);
267 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
268 struct lpfc_hba *phba = vport->phba;
270 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
274 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
275 * @dev: class converted to a Scsi_host structure.
276 * @attr: device attribute, not used.
277 * @buf: on return contains the Menlo Maintenance sli flag.
279 * Returns: size of formatted string.
282 lpfc_mlomgmt_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;
288 return snprintf(buf, PAGE_SIZE, "%d\n",
289 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
293 * lpfc_vportnum_show - Return the port number in ascii of the hba
294 * @dev: class converted to a Scsi_host structure.
295 * @attr: device attribute, not used.
296 * @buf: on return contains scsi vpd program type.
298 * Returns: size of formatted string.
301 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
308 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
312 * lpfc_fwrev_show - Return the firmware rev running in the hba
313 * @dev: class converted to a Scsi_host structure.
314 * @attr: device attribute, not used.
315 * @buf: on return contains the scsi vpd program type.
317 * Returns: size of formatted string.
320 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
323 struct Scsi_Host *shost = class_to_shost(dev);
324 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
325 struct lpfc_hba *phba = vport->phba;
328 lpfc_decode_firmware_rev(phba, fwrev, 1);
329 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
333 * lpfc_hdw_show - Return the jedec information about the hba
334 * @dev: class converted to a Scsi_host structure.
335 * @attr: device attribute, not used.
336 * @buf: on return contains the scsi vpd program type.
338 * Returns: size of formatted string.
341 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
344 struct Scsi_Host *shost = class_to_shost(dev);
345 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
346 struct lpfc_hba *phba = vport->phba;
347 lpfc_vpd_t *vp = &phba->vpd;
349 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
350 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
354 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
355 * @dev: class converted to a Scsi_host structure.
356 * @attr: device attribute, not used.
357 * @buf: on return contains the ROM and FCode ascii strings.
359 * Returns: size of formatted string.
362 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
365 struct Scsi_Host *shost = class_to_shost(dev);
366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
367 struct lpfc_hba *phba = vport->phba;
369 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
373 * lpfc_state_show - Return the link state of the port
374 * @dev: class converted to a Scsi_host structure.
375 * @attr: device attribute, not used.
376 * @buf: on return contains text describing the state of the link.
379 * The switch statement has no default so zero will be returned.
381 * Returns: size of formatted string.
384 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
387 struct Scsi_Host *shost = class_to_shost(dev);
388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
389 struct lpfc_hba *phba = vport->phba;
392 switch (phba->link_state) {
393 case LPFC_LINK_UNKNOWN:
394 case LPFC_WARM_START:
395 case LPFC_INIT_START:
396 case LPFC_INIT_MBX_CMDS:
399 if (phba->hba_flag & LINK_DISABLED)
400 len += snprintf(buf + len, PAGE_SIZE-len,
401 "Link Down - User disabled\n");
403 len += snprintf(buf + len, PAGE_SIZE-len,
409 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
411 switch (vport->port_state) {
412 case LPFC_LOCAL_CFG_LINK:
413 len += snprintf(buf + len, PAGE_SIZE-len,
414 "Configuring Link\n");
418 case LPFC_FABRIC_CFG_LINK:
421 case LPFC_BUILD_DISC_LIST:
423 len += snprintf(buf + len, PAGE_SIZE - len,
426 case LPFC_VPORT_READY:
427 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
430 case LPFC_VPORT_FAILED:
431 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
434 case LPFC_VPORT_UNKNOWN:
435 len += snprintf(buf + len, PAGE_SIZE - len,
439 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
440 len += snprintf(buf + len, PAGE_SIZE-len,
441 " Menlo Maint Mode\n");
442 else if (phba->fc_topology == TOPOLOGY_LOOP) {
443 if (vport->fc_flag & FC_PUBLIC_LOOP)
444 len += snprintf(buf + len, PAGE_SIZE-len,
447 len += snprintf(buf + len, PAGE_SIZE-len,
450 if (vport->fc_flag & FC_FABRIC)
451 len += snprintf(buf + len, PAGE_SIZE-len,
454 len += snprintf(buf + len, PAGE_SIZE-len,
463 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
464 * @dev: class device that is converted into a Scsi_host.
465 * @attr: device attribute, not used.
466 * @buf: on return contains the sum of fc mapped and unmapped.
469 * Returns the ascii text number of the sum of the fc mapped and unmapped
472 * Returns: size of formatted string.
475 lpfc_num_discovered_ports_show(struct device *dev,
476 struct device_attribute *attr, char *buf)
478 struct Scsi_Host *shost = class_to_shost(dev);
479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
481 return snprintf(buf, PAGE_SIZE, "%d\n",
482 vport->fc_map_cnt + vport->fc_unmap_cnt);
486 * lpfc_issue_lip - Misnomer, name carried over from long ago
487 * @shost: Scsi_Host pointer.
490 * Bring the link down gracefully then re-init the link. The firmware will
491 * re-init the fiber channel interface as required. Does not issue a LIP.
494 * -EPERM port offline or management commands are being blocked
495 * -ENOMEM cannot allocate memory for the mailbox command
496 * -EIO error sending the mailbox command
500 lpfc_issue_lip(struct Scsi_Host *shost)
502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 struct lpfc_hba *phba = vport->phba;
504 LPFC_MBOXQ_t *pmboxq;
505 int mbxstatus = MBXERR_ERROR;
507 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
508 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
511 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
516 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
517 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
518 pmboxq->u.mb.mbxOwner = OWN_HOST;
520 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
522 if ((mbxstatus == MBX_SUCCESS) &&
523 (pmboxq->u.mb.mbxStatus == 0 ||
524 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
525 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
526 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
527 phba->cfg_link_speed);
528 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
532 lpfc_set_loopback_flag(phba);
533 if (mbxstatus != MBX_TIMEOUT)
534 mempool_free(pmboxq, phba->mbox_mem_pool);
536 if (mbxstatus == MBXERR_ERROR)
543 * lpfc_do_offline - Issues a mailbox command to bring the link down
544 * @phba: lpfc_hba pointer.
545 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
548 * Assumes any error from lpfc_do_offline() will be negative.
549 * Can wait up to 5 seconds for the port ring buffers count
550 * to reach zero, prints a warning if it is not zero and continues.
551 * lpfc_workq_post_event() returns a non-zero return code if call fails.
554 * -EIO error posting the event
558 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
560 struct completion online_compl;
561 struct lpfc_sli_ring *pring;
562 struct lpfc_sli *psli;
567 init_completion(&online_compl);
568 lpfc_workq_post_event(phba, &status, &online_compl,
569 LPFC_EVT_OFFLINE_PREP);
570 wait_for_completion(&online_compl);
577 /* Wait a little for things to settle down, but not
578 * long enough for dev loss timeout to expire.
580 for (i = 0; i < psli->num_rings; i++) {
581 pring = &psli->ring[i];
582 while (pring->txcmplq_cnt) {
584 if (cnt++ > 500) { /* 5 secs */
585 lpfc_printf_log(phba,
586 KERN_WARNING, LOG_INIT,
587 "0466 Outstanding IO when "
588 "bringing Adapter offline\n");
594 init_completion(&online_compl);
595 lpfc_workq_post_event(phba, &status, &online_compl, type);
596 wait_for_completion(&online_compl);
605 * lpfc_selective_reset - Offline then onlines the port
606 * @phba: lpfc_hba pointer.
609 * If the port is configured to allow a reset then the hba is brought
610 * offline then online.
613 * Assumes any error from lpfc_do_offline() will be negative.
616 * lpfc_do_offline() return code if not zero
617 * -EIO reset not configured or error posting the event
621 lpfc_selective_reset(struct lpfc_hba *phba)
623 struct completion online_compl;
626 if (!phba->cfg_enable_hba_reset)
629 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
634 init_completion(&online_compl);
635 lpfc_workq_post_event(phba, &status, &online_compl,
637 wait_for_completion(&online_compl);
646 * lpfc_issue_reset - Selectively resets an adapter
647 * @dev: class device that is converted into a Scsi_host.
648 * @attr: device attribute, not used.
649 * @buf: containing the string "selective".
650 * @count: unused variable.
653 * If the buf contains the string "selective" then lpfc_selective_reset()
654 * is called to perform the reset.
657 * Assumes any error from lpfc_selective_reset() will be negative.
658 * If lpfc_selective_reset() returns zero then the length of the buffer
659 * is returned which indicates succcess
662 * -EINVAL if the buffer does not contain the string "selective"
663 * length of buf if lpfc-selective_reset() if the call succeeds
664 * return value of lpfc_selective_reset() if the call fails
667 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
668 const char *buf, size_t count)
670 struct Scsi_Host *shost = class_to_shost(dev);
671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
672 struct lpfc_hba *phba = vport->phba;
674 int status = -EINVAL;
676 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
677 status = lpfc_selective_reset(phba);
686 * lpfc_nport_evt_cnt_show - Return the number of nport events
687 * @dev: class device that is converted into a Scsi_host.
688 * @attr: device attribute, not used.
689 * @buf: on return contains the ascii number of nport events.
691 * Returns: size of formatted string.
694 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
697 struct Scsi_Host *shost = class_to_shost(dev);
698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
699 struct lpfc_hba *phba = vport->phba;
701 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
705 * lpfc_board_mode_show - Return the state of the board
706 * @dev: class device that is converted into a Scsi_host.
707 * @attr: device attribute, not used.
708 * @buf: on return contains the state of the adapter.
710 * Returns: size of formatted string.
713 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
716 struct Scsi_Host *shost = class_to_shost(dev);
717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
718 struct lpfc_hba *phba = vport->phba;
721 if (phba->link_state == LPFC_HBA_ERROR)
723 else if (phba->link_state == LPFC_WARM_START)
724 state = "warm start";
725 else if (phba->link_state == LPFC_INIT_START)
730 return snprintf(buf, PAGE_SIZE, "%s\n", state);
734 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
735 * @dev: class device that is converted into a Scsi_host.
736 * @attr: device attribute, not used.
737 * @buf: containing one of the strings "online", "offline", "warm" or "error".
738 * @count: unused variable.
741 * -EACCES if enable hba reset not enabled
742 * -EINVAL if the buffer does not contain a valid string (see above)
743 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
744 * buf length greater than zero indicates success
747 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
748 const char *buf, size_t count)
750 struct Scsi_Host *shost = class_to_shost(dev);
751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
752 struct lpfc_hba *phba = vport->phba;
753 struct completion online_compl;
756 if (!phba->cfg_enable_hba_reset)
758 init_completion(&online_compl);
760 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
761 lpfc_workq_post_event(phba, &status, &online_compl,
763 wait_for_completion(&online_compl);
764 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
765 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
766 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
767 if (phba->sli_rev == LPFC_SLI_REV4)
770 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
771 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
772 if (phba->sli_rev == LPFC_SLI_REV4)
775 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
786 * lpfc_get_hba_info - Return various bits of informaton about the adapter
787 * @phba: pointer to the adapter structure.
788 * @mxri: max xri count.
789 * @axri: available xri count.
790 * @mrpi: max rpi count.
791 * @arpi: available rpi count.
792 * @mvpi: max vpi count.
793 * @avpi: available vpi count.
796 * If an integer pointer for an count is not null then the value for the
804 lpfc_get_hba_info(struct lpfc_hba *phba,
805 uint32_t *mxri, uint32_t *axri,
806 uint32_t *mrpi, uint32_t *arpi,
807 uint32_t *mvpi, uint32_t *avpi)
809 struct lpfc_sli *psli = &phba->sli;
810 struct lpfc_mbx_read_config *rd_config;
811 LPFC_MBOXQ_t *pmboxq;
816 * prevent udev from issuing mailbox commands until the port is
819 if (phba->link_state < LPFC_LINK_DOWN ||
820 !phba->mbox_mem_pool ||
821 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
824 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
827 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
830 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
833 pmb->mbxCommand = MBX_READ_CONFIG;
834 pmb->mbxOwner = OWN_HOST;
835 pmboxq->context1 = NULL;
837 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
838 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
839 rc = MBX_NOT_FINISHED;
841 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
843 if (rc != MBX_SUCCESS) {
844 if (rc != MBX_TIMEOUT)
845 mempool_free(pmboxq, phba->mbox_mem_pool);
849 if (phba->sli_rev == LPFC_SLI_REV4) {
850 rd_config = &pmboxq->u.mqe.un.rd_config;
852 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
854 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
855 phba->sli4_hba.max_cfg_param.rpi_used;
857 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
859 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
860 phba->sli4_hba.max_cfg_param.xri_used;
862 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
864 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
865 phba->sli4_hba.max_cfg_param.vpi_used;
868 *mrpi = pmb->un.varRdConfig.max_rpi;
870 *arpi = pmb->un.varRdConfig.avail_rpi;
872 *mxri = pmb->un.varRdConfig.max_xri;
874 *axri = pmb->un.varRdConfig.avail_xri;
876 *mvpi = pmb->un.varRdConfig.max_vpi;
878 *avpi = pmb->un.varRdConfig.avail_vpi;
881 mempool_free(pmboxq, phba->mbox_mem_pool);
886 * lpfc_max_rpi_show - Return maximum rpi
887 * @dev: class device that is converted into a Scsi_host.
888 * @attr: device attribute, not used.
889 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
892 * Calls lpfc_get_hba_info() asking for just the mrpi count.
893 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
894 * to "Unknown" and the buffer length is returned, therefore the caller
895 * must check for "Unknown" in the buffer to detect a failure.
897 * Returns: size of formatted string.
900 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
903 struct Scsi_Host *shost = class_to_shost(dev);
904 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
905 struct lpfc_hba *phba = vport->phba;
908 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
909 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
910 return snprintf(buf, PAGE_SIZE, "Unknown\n");
914 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
915 * @dev: class device that is converted into a Scsi_host.
916 * @attr: device attribute, not used.
917 * @buf: containing the used rpi count in decimal or "Unknown".
920 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
921 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
922 * to "Unknown" and the buffer length is returned, therefore the caller
923 * must check for "Unknown" in the buffer to detect a failure.
925 * Returns: size of formatted string.
928 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
931 struct Scsi_Host *shost = class_to_shost(dev);
932 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
933 struct lpfc_hba *phba = vport->phba;
936 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
937 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
938 return snprintf(buf, PAGE_SIZE, "Unknown\n");
942 * lpfc_max_xri_show - Return maximum xri
943 * @dev: class device that is converted into a Scsi_host.
944 * @attr: device attribute, not used.
945 * @buf: on return contains the maximum xri count in decimal or "Unknown".
948 * Calls lpfc_get_hba_info() asking for just the mrpi count.
949 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
950 * to "Unknown" and the buffer length is returned, therefore the caller
951 * must check for "Unknown" in the buffer to detect a failure.
953 * Returns: size of formatted string.
956 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
959 struct Scsi_Host *shost = class_to_shost(dev);
960 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
961 struct lpfc_hba *phba = vport->phba;
964 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
965 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
966 return snprintf(buf, PAGE_SIZE, "Unknown\n");
970 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
971 * @dev: class device that is converted into a Scsi_host.
972 * @attr: device attribute, not used.
973 * @buf: on return contains the used xri count in decimal or "Unknown".
976 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
977 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
978 * to "Unknown" and the buffer length is returned, therefore the caller
979 * must check for "Unknown" in the buffer to detect a failure.
981 * Returns: size of formatted string.
984 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
987 struct Scsi_Host *shost = class_to_shost(dev);
988 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
989 struct lpfc_hba *phba = vport->phba;
992 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
993 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
994 return snprintf(buf, PAGE_SIZE, "Unknown\n");
998 * lpfc_max_vpi_show - Return maximum vpi
999 * @dev: class device that is converted into a Scsi_host.
1000 * @attr: device attribute, not used.
1001 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1004 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1005 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1006 * to "Unknown" and the buffer length is returned, therefore the caller
1007 * must check for "Unknown" in the buffer to detect a failure.
1009 * Returns: size of formatted string.
1012 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1015 struct Scsi_Host *shost = class_to_shost(dev);
1016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1017 struct lpfc_hba *phba = vport->phba;
1020 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1021 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1022 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1026 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1027 * @dev: class device that is converted into a Scsi_host.
1028 * @attr: device attribute, not used.
1029 * @buf: on return contains the used vpi count in decimal or "Unknown".
1032 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1033 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1034 * to "Unknown" and the buffer length is returned, therefore the caller
1035 * must check for "Unknown" in the buffer to detect a failure.
1037 * Returns: size of formatted string.
1040 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1043 struct Scsi_Host *shost = class_to_shost(dev);
1044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1045 struct lpfc_hba *phba = vport->phba;
1048 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1049 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1050 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1054 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1055 * @dev: class device that is converted into a Scsi_host.
1056 * @attr: device attribute, not used.
1057 * @buf: text that must be interpreted to determine if npiv is supported.
1060 * Buffer will contain text indicating npiv is not suppoerted on the port,
1061 * the port is an NPIV physical port, or it is an npiv virtual port with
1062 * the id of the vport.
1064 * Returns: size of formatted string.
1067 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1070 struct Scsi_Host *shost = class_to_shost(dev);
1071 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1072 struct lpfc_hba *phba = vport->phba;
1074 if (!(phba->max_vpi))
1075 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1076 if (vport->port_type == LPFC_PHYSICAL_PORT)
1077 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1078 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1082 * lpfc_poll_show - Return text about poll support for the adapter
1083 * @dev: class device that is converted into a Scsi_host.
1084 * @attr: device attribute, not used.
1085 * @buf: on return contains the cfg_poll in hex.
1088 * cfg_poll should be a lpfc_polling_flags type.
1090 * Returns: size of formatted string.
1093 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1096 struct Scsi_Host *shost = class_to_shost(dev);
1097 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1098 struct lpfc_hba *phba = vport->phba;
1100 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1104 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1105 * @dev: class device that is converted into a Scsi_host.
1106 * @attr: device attribute, not used.
1107 * @buf: one or more lpfc_polling_flags values.
1111 * buf contents converted to integer and checked for a valid value.
1114 * -EINVAL if the buffer connot be converted or is out of range
1115 * length of the buf on success
1118 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1119 const char *buf, size_t count)
1121 struct Scsi_Host *shost = class_to_shost(dev);
1122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1123 struct lpfc_hba *phba = vport->phba;
1128 if (!isdigit(buf[0]))
1131 if (sscanf(buf, "%i", &val) != 1)
1134 if ((val & 0x3) != val)
1137 spin_lock_irq(&phba->hbalock);
1139 old_val = phba->cfg_poll;
1141 if (val & ENABLE_FCP_RING_POLLING) {
1142 if ((val & DISABLE_FCP_RING_INT) &&
1143 !(old_val & DISABLE_FCP_RING_INT)) {
1144 creg_val = readl(phba->HCregaddr);
1145 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1146 writel(creg_val, phba->HCregaddr);
1147 readl(phba->HCregaddr); /* flush */
1149 lpfc_poll_start_timer(phba);
1151 } else if (val != 0x0) {
1152 spin_unlock_irq(&phba->hbalock);
1156 if (!(val & DISABLE_FCP_RING_INT) &&
1157 (old_val & DISABLE_FCP_RING_INT))
1159 spin_unlock_irq(&phba->hbalock);
1160 del_timer(&phba->fcp_poll_timer);
1161 spin_lock_irq(&phba->hbalock);
1162 creg_val = readl(phba->HCregaddr);
1163 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1164 writel(creg_val, phba->HCregaddr);
1165 readl(phba->HCregaddr); /* flush */
1168 phba->cfg_poll = val;
1170 spin_unlock_irq(&phba->hbalock);
1176 * lpfc_param_show - Return a cfg attribute value in decimal
1179 * Macro that given an attr e.g. hba_queue_depth expands
1180 * into a function with the name lpfc_hba_queue_depth_show.
1182 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1183 * @dev: class device that is converted into a Scsi_host.
1184 * @attr: device attribute, not used.
1185 * @buf: on return contains the attribute value in decimal.
1187 * Returns: size of formatted string.
1189 #define lpfc_param_show(attr) \
1191 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1194 struct Scsi_Host *shost = class_to_shost(dev);\
1195 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1196 struct lpfc_hba *phba = vport->phba;\
1198 val = phba->cfg_##attr;\
1199 return snprintf(buf, PAGE_SIZE, "%d\n",\
1204 * lpfc_param_hex_show - Return a cfg attribute value in hex
1207 * Macro that given an attr e.g. hba_queue_depth expands
1208 * into a function with the name lpfc_hba_queue_depth_show
1210 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1211 * @dev: class device that is converted into a Scsi_host.
1212 * @attr: device attribute, not used.
1213 * @buf: on return contains the attribute value in hexadecimal.
1215 * Returns: size of formatted string.
1217 #define lpfc_param_hex_show(attr) \
1219 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1222 struct Scsi_Host *shost = class_to_shost(dev);\
1223 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1224 struct lpfc_hba *phba = vport->phba;\
1226 val = phba->cfg_##attr;\
1227 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1232 * lpfc_param_init - Intializes a cfg attribute
1235 * Macro that given an attr e.g. hba_queue_depth expands
1236 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1237 * takes a default argument, a minimum and maximum argument.
1239 * lpfc_##attr##_init: Initializes an attribute.
1240 * @phba: pointer the the adapter structure.
1241 * @val: integer attribute value.
1243 * Validates the min and max values then sets the adapter config field
1244 * accordingly, or uses the default if out of range and prints an error message.
1248 * -EINVAL if default used
1250 #define lpfc_param_init(attr, default, minval, maxval) \
1252 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1254 if (val >= minval && val <= maxval) {\
1255 phba->cfg_##attr = val;\
1258 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1259 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1260 "allowed range is ["#minval", "#maxval"]\n", val); \
1261 phba->cfg_##attr = default;\
1266 * lpfc_param_set - Set a cfg attribute value
1269 * Macro that given an attr e.g. hba_queue_depth expands
1270 * into a function with the name lpfc_hba_queue_depth_set
1272 * lpfc_##attr##_set: Sets an attribute value.
1273 * @phba: pointer the the adapter structure.
1274 * @val: integer attribute value.
1277 * Validates the min and max values then sets the
1278 * adapter config field if in the valid range. prints error message
1279 * and does not set the parameter if invalid.
1283 * -EINVAL if val is invalid
1285 #define lpfc_param_set(attr, default, minval, maxval) \
1287 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1289 if (val >= minval && val <= maxval) {\
1290 phba->cfg_##attr = val;\
1293 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1294 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1295 "allowed range is ["#minval", "#maxval"]\n", val); \
1300 * lpfc_param_store - Set a vport attribute value
1303 * Macro that given an attr e.g. hba_queue_depth expands
1304 * into a function with the name lpfc_hba_queue_depth_store.
1306 * lpfc_##attr##_store: Set an sttribute value.
1307 * @dev: class device that is converted into a Scsi_host.
1308 * @attr: device attribute, not used.
1309 * @buf: contains the attribute value in ascii.
1313 * Convert the ascii text number to an integer, then
1314 * use the lpfc_##attr##_set function to set the value.
1317 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1318 * length of buffer upon success.
1320 #define lpfc_param_store(attr) \
1322 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1323 const char *buf, size_t count) \
1325 struct Scsi_Host *shost = class_to_shost(dev);\
1326 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1327 struct lpfc_hba *phba = vport->phba;\
1329 if (!isdigit(buf[0]))\
1331 if (sscanf(buf, "%i", &val) != 1)\
1333 if (lpfc_##attr##_set(phba, val) == 0) \
1334 return strlen(buf);\
1340 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1343 * Macro that given an attr e.g. hba_queue_depth expands
1344 * into a function with the name lpfc_hba_queue_depth_show
1346 * lpfc_##attr##_show: prints the attribute value in decimal.
1347 * @dev: class device that is converted into a Scsi_host.
1348 * @attr: device attribute, not used.
1349 * @buf: on return contains the attribute value in decimal.
1351 * Returns: length of formatted string.
1353 #define lpfc_vport_param_show(attr) \
1355 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1358 struct Scsi_Host *shost = class_to_shost(dev);\
1359 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1361 val = vport->cfg_##attr;\
1362 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1366 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1369 * Macro that given an attr e.g.
1370 * hba_queue_depth expands into a function with the name
1371 * lpfc_hba_queue_depth_show
1373 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1374 * @dev: class device that is converted into a Scsi_host.
1375 * @attr: device attribute, not used.
1376 * @buf: on return contains the attribute value in hexadecimal.
1378 * Returns: length of formatted string.
1380 #define lpfc_vport_param_hex_show(attr) \
1382 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1385 struct Scsi_Host *shost = class_to_shost(dev);\
1386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1388 val = vport->cfg_##attr;\
1389 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1393 * lpfc_vport_param_init - Initialize a vport cfg attribute
1396 * Macro that given an attr e.g. hba_queue_depth expands
1397 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1398 * takes a default argument, a minimum and maximum argument.
1400 * lpfc_##attr##_init: validates the min and max values then sets the
1401 * adapter config field accordingly, or uses the default if out of range
1402 * and prints an error message.
1403 * @phba: pointer the the adapter structure.
1404 * @val: integer attribute value.
1408 * -EINVAL if default used
1410 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1412 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1414 if (val >= minval && val <= maxval) {\
1415 vport->cfg_##attr = val;\
1418 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1419 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1420 "allowed range is ["#minval", "#maxval"]\n", val); \
1421 vport->cfg_##attr = default;\
1426 * lpfc_vport_param_set - Set a vport cfg attribute
1429 * Macro that given an attr e.g. hba_queue_depth expands
1430 * into a function with the name lpfc_hba_queue_depth_set
1432 * lpfc_##attr##_set: validates the min and max values then sets the
1433 * adapter config field if in the valid range. prints error message
1434 * and does not set the parameter if invalid.
1435 * @phba: pointer the the adapter structure.
1436 * @val: integer attribute value.
1440 * -EINVAL if val is invalid
1442 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1444 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1446 if (val >= minval && val <= maxval) {\
1447 vport->cfg_##attr = val;\
1450 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1451 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1452 "allowed range is ["#minval", "#maxval"]\n", val); \
1457 * lpfc_vport_param_store - Set a vport attribute
1460 * Macro that given an attr e.g. hba_queue_depth
1461 * expands into a function with the name lpfc_hba_queue_depth_store
1463 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1464 * use the lpfc_##attr##_set function to set the value.
1465 * @cdev: class device that is converted into a Scsi_host.
1466 * @buf: contains the attribute value in decimal.
1470 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1471 * length of buffer upon success.
1473 #define lpfc_vport_param_store(attr) \
1475 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1476 const char *buf, size_t count) \
1478 struct Scsi_Host *shost = class_to_shost(dev);\
1479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1481 if (!isdigit(buf[0]))\
1483 if (sscanf(buf, "%i", &val) != 1)\
1485 if (lpfc_##attr##_set(vport, val) == 0) \
1486 return strlen(buf);\
1492 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1493 static int lpfc_##name = defval;\
1494 module_param(lpfc_##name, int, 0);\
1495 MODULE_PARM_DESC(lpfc_##name, desc);\
1496 lpfc_param_init(name, defval, minval, maxval)
1498 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1499 static int lpfc_##name = defval;\
1500 module_param(lpfc_##name, int, 0);\
1501 MODULE_PARM_DESC(lpfc_##name, desc);\
1502 lpfc_param_show(name)\
1503 lpfc_param_init(name, defval, minval, maxval)\
1504 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1506 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1507 static int lpfc_##name = defval;\
1508 module_param(lpfc_##name, int, 0);\
1509 MODULE_PARM_DESC(lpfc_##name, desc);\
1510 lpfc_param_show(name)\
1511 lpfc_param_init(name, defval, minval, maxval)\
1512 lpfc_param_set(name, defval, minval, maxval)\
1513 lpfc_param_store(name)\
1514 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1515 lpfc_##name##_show, lpfc_##name##_store)
1517 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1518 static int lpfc_##name = defval;\
1519 module_param(lpfc_##name, int, 0);\
1520 MODULE_PARM_DESC(lpfc_##name, desc);\
1521 lpfc_param_hex_show(name)\
1522 lpfc_param_init(name, defval, minval, maxval)\
1523 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1525 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1526 static int lpfc_##name = defval;\
1527 module_param(lpfc_##name, int, 0);\
1528 MODULE_PARM_DESC(lpfc_##name, desc);\
1529 lpfc_param_hex_show(name)\
1530 lpfc_param_init(name, defval, minval, maxval)\
1531 lpfc_param_set(name, defval, minval, maxval)\
1532 lpfc_param_store(name)\
1533 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1534 lpfc_##name##_show, lpfc_##name##_store)
1536 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1537 static int lpfc_##name = defval;\
1538 module_param(lpfc_##name, int, 0);\
1539 MODULE_PARM_DESC(lpfc_##name, desc);\
1540 lpfc_vport_param_init(name, defval, minval, maxval)
1542 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1543 static int lpfc_##name = defval;\
1544 module_param(lpfc_##name, int, 0);\
1545 MODULE_PARM_DESC(lpfc_##name, desc);\
1546 lpfc_vport_param_show(name)\
1547 lpfc_vport_param_init(name, defval, minval, maxval)\
1548 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1550 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1551 static int lpfc_##name = defval;\
1552 module_param(lpfc_##name, int, 0);\
1553 MODULE_PARM_DESC(lpfc_##name, desc);\
1554 lpfc_vport_param_show(name)\
1555 lpfc_vport_param_init(name, defval, minval, maxval)\
1556 lpfc_vport_param_set(name, defval, minval, maxval)\
1557 lpfc_vport_param_store(name)\
1558 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1559 lpfc_##name##_show, lpfc_##name##_store)
1561 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1562 static int lpfc_##name = defval;\
1563 module_param(lpfc_##name, int, 0);\
1564 MODULE_PARM_DESC(lpfc_##name, desc);\
1565 lpfc_vport_param_hex_show(name)\
1566 lpfc_vport_param_init(name, defval, minval, maxval)\
1567 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1569 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1570 static int lpfc_##name = defval;\
1571 module_param(lpfc_##name, int, 0);\
1572 MODULE_PARM_DESC(lpfc_##name, desc);\
1573 lpfc_vport_param_hex_show(name)\
1574 lpfc_vport_param_init(name, defval, minval, maxval)\
1575 lpfc_vport_param_set(name, defval, minval, maxval)\
1576 lpfc_vport_param_store(name)\
1577 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1578 lpfc_##name##_show, lpfc_##name##_store)
1580 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1581 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1582 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1583 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1584 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1585 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1586 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1587 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1588 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1589 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1590 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1591 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1592 static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
1593 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1594 lpfc_option_rom_version_show, NULL);
1595 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1596 lpfc_num_discovered_ports_show, NULL);
1597 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1598 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1599 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1600 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1601 lpfc_board_mode_show, lpfc_board_mode_store);
1602 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1603 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1604 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1605 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1606 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1607 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1608 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1609 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1610 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1613 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1616 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1617 * @dev: class device that is converted into a Scsi_host.
1618 * @attr: device attribute, not used.
1619 * @buf: containing the string lpfc_soft_wwn_key.
1620 * @count: must be size of lpfc_soft_wwn_key.
1623 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1624 * length of buf indicates success
1627 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1628 const char *buf, size_t count)
1630 struct Scsi_Host *shost = class_to_shost(dev);
1631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1632 struct lpfc_hba *phba = vport->phba;
1633 unsigned int cnt = count;
1636 * We're doing a simple sanity check for soft_wwpn setting.
1637 * We require that the user write a specific key to enable
1638 * the soft_wwpn attribute to be settable. Once the attribute
1639 * is written, the enable key resets. If further updates are
1640 * desired, the key must be written again to re-enable the
1643 * The "key" is not secret - it is a hardcoded string shown
1644 * here. The intent is to protect against the random user or
1645 * application that is just writing attributes.
1648 /* count may include a LF at end of string */
1649 if (buf[cnt-1] == '\n')
1652 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1653 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1656 phba->soft_wwn_enable = 1;
1659 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1660 lpfc_soft_wwn_enable_store);
1663 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1664 * @dev: class device that is converted into a Scsi_host.
1665 * @attr: device attribute, not used.
1666 * @buf: on return contains the wwpn in hexadecimal.
1668 * Returns: size of formatted string.
1671 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1674 struct Scsi_Host *shost = class_to_shost(dev);
1675 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1676 struct lpfc_hba *phba = vport->phba;
1678 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1679 (unsigned long long)phba->cfg_soft_wwpn);
1683 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1684 * @dev class device that is converted into a Scsi_host.
1685 * @attr: device attribute, not used.
1686 * @buf: contains the wwpn in hexadecimal.
1687 * @count: number of wwpn bytes in buf
1690 * -EACCES hba reset not enabled, adapter over temp
1691 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1692 * -EIO error taking adapter offline or online
1693 * value of count on success
1696 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1697 const char *buf, size_t count)
1699 struct Scsi_Host *shost = class_to_shost(dev);
1700 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1701 struct lpfc_hba *phba = vport->phba;
1702 struct completion online_compl;
1703 int stat1=0, stat2=0;
1704 unsigned int i, j, cnt=count;
1707 if (!phba->cfg_enable_hba_reset)
1709 spin_lock_irq(&phba->hbalock);
1710 if (phba->over_temp_state == HBA_OVER_TEMP) {
1711 spin_unlock_irq(&phba->hbalock);
1714 spin_unlock_irq(&phba->hbalock);
1715 /* count may include a LF at end of string */
1716 if (buf[cnt-1] == '\n')
1719 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1720 ((cnt == 17) && (*buf++ != 'x')) ||
1721 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1724 phba->soft_wwn_enable = 0;
1726 memset(wwpn, 0, sizeof(wwpn));
1728 /* Validate and store the new name */
1729 for (i=0, j=0; i < 16; i++) {
1730 if ((*buf >= 'a') && (*buf <= 'f'))
1731 j = ((j << 4) | ((*buf++ -'a') + 10));
1732 else if ((*buf >= 'A') && (*buf <= 'F'))
1733 j = ((j << 4) | ((*buf++ -'A') + 10));
1734 else if ((*buf >= '0') && (*buf <= '9'))
1735 j = ((j << 4) | (*buf++ -'0'));
1739 wwpn[i/2] = j & 0xff;
1743 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1744 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1745 if (phba->cfg_soft_wwnn)
1746 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1748 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1749 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1751 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1753 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1754 "0463 lpfc_soft_wwpn attribute set failed to "
1755 "reinit adapter - %d\n", stat1);
1756 init_completion(&online_compl);
1757 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1758 wait_for_completion(&online_compl);
1760 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1761 "0464 lpfc_soft_wwpn attribute set failed to "
1762 "reinit adapter - %d\n", stat2);
1763 return (stat1 || stat2) ? -EIO : count;
1765 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1766 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1769 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1770 * @dev: class device that is converted into a Scsi_host.
1771 * @attr: device attribute, not used.
1772 * @buf: on return contains the wwnn in hexadecimal.
1774 * Returns: size of formatted string.
1777 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1780 struct Scsi_Host *shost = class_to_shost(dev);
1781 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1782 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1783 (unsigned long long)phba->cfg_soft_wwnn);
1787 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1788 * @cdev: class device that is converted into a Scsi_host.
1789 * @buf: contains the ww node name in hexadecimal.
1790 * @count: number of wwnn bytes in buf.
1793 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1794 * value of count on success
1797 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1798 const char *buf, size_t count)
1800 struct Scsi_Host *shost = class_to_shost(dev);
1801 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1802 unsigned int i, j, cnt=count;
1805 /* count may include a LF at end of string */
1806 if (buf[cnt-1] == '\n')
1809 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1810 ((cnt == 17) && (*buf++ != 'x')) ||
1811 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1815 * Allow wwnn to be set many times, as long as the enable is set.
1816 * However, once the wwpn is set, everything locks.
1819 memset(wwnn, 0, sizeof(wwnn));
1821 /* Validate and store the new name */
1822 for (i=0, j=0; i < 16; i++) {
1823 if ((*buf >= 'a') && (*buf <= 'f'))
1824 j = ((j << 4) | ((*buf++ -'a') + 10));
1825 else if ((*buf >= 'A') && (*buf <= 'F'))
1826 j = ((j << 4) | ((*buf++ -'A') + 10));
1827 else if ((*buf >= '0') && (*buf <= '9'))
1828 j = ((j << 4) | (*buf++ -'0'));
1832 wwnn[i/2] = j & 0xff;
1836 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1838 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1839 "lpfc%d: soft_wwnn set. Value will take effect upon "
1840 "setting of the soft_wwpn\n", phba->brd_no);
1844 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1845 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1848 static int lpfc_poll = 0;
1849 module_param(lpfc_poll, int, 0);
1850 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1852 " 1 - poll with interrupts enabled"
1853 " 3 - poll and disable FCP ring interrupts");
1855 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1856 lpfc_poll_show, lpfc_poll_store);
1858 int lpfc_sli_mode = 0;
1859 module_param(lpfc_sli_mode, int, 0);
1860 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1861 " 0 - auto (SLI-3 if supported),"
1862 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1863 " 3 - select SLI-3");
1865 int lpfc_enable_npiv = 0;
1866 module_param(lpfc_enable_npiv, int, 0);
1867 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1868 lpfc_param_show(enable_npiv);
1869 lpfc_param_init(enable_npiv, 0, 0, 1);
1870 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1871 lpfc_enable_npiv_show, NULL);
1874 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1875 # until the timer expires. Value range is [0,255]. Default value is 30.
1877 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1878 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1879 module_param(lpfc_nodev_tmo, int, 0);
1880 MODULE_PARM_DESC(lpfc_nodev_tmo,
1881 "Seconds driver will hold I/O waiting "
1882 "for a device to come back");
1885 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
1886 * @dev: class converted to a Scsi_host structure.
1887 * @attr: device attribute, not used.
1888 * @buf: on return contains the dev loss timeout in decimal.
1890 * Returns: size of formatted string.
1893 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1896 struct Scsi_Host *shost = class_to_shost(dev);
1897 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1899 val = vport->cfg_devloss_tmo;
1900 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1904 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
1905 * @vport: lpfc vport structure pointer.
1906 * @val: contains the nodev timeout value.
1909 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1910 * a kernel error message is printed and zero is returned.
1911 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1912 * Otherwise nodev tmo is set to the default value.
1915 * zero if already set or if val is in range
1916 * -EINVAL val out of range
1919 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1921 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1922 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1923 if (val != LPFC_DEF_DEVLOSS_TMO)
1924 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1925 "0407 Ignoring nodev_tmo module "
1926 "parameter because devloss_tmo is "
1931 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1932 vport->cfg_nodev_tmo = val;
1933 vport->cfg_devloss_tmo = val;
1936 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1937 "0400 lpfc_nodev_tmo attribute cannot be set to"
1938 " %d, allowed range is [%d, %d]\n",
1939 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1940 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1945 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
1946 * @vport: lpfc vport structure pointer.
1949 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1952 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1954 struct Scsi_Host *shost;
1955 struct lpfc_nodelist *ndlp;
1957 shost = lpfc_shost_from_vport(vport);
1958 spin_lock_irq(shost->host_lock);
1959 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1960 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
1961 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1962 spin_unlock_irq(shost->host_lock);
1966 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
1967 * @vport: lpfc vport structure pointer.
1968 * @val: contains the tmo value.
1971 * If the devloss tmo is already set or the vport dev loss tmo has changed
1972 * then a kernel error message is printed and zero is returned.
1973 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1974 * Otherwise nodev tmo is set to the default value.
1977 * zero if already set or if val is in range
1978 * -EINVAL val out of range
1981 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
1983 if (vport->dev_loss_tmo_changed ||
1984 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
1985 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1986 "0401 Ignoring change to nodev_tmo "
1987 "because devloss_tmo is set.\n");
1990 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1991 vport->cfg_nodev_tmo = val;
1992 vport->cfg_devloss_tmo = val;
1993 lpfc_update_rport_devloss_tmo(vport);
1996 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1997 "0403 lpfc_nodev_tmo attribute cannot be set to"
1998 "%d, allowed range is [%d, %d]\n",
1999 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2003 lpfc_vport_param_store(nodev_tmo)
2005 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2006 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2009 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2010 # disappear until the timer expires. Value range is [0,255]. Default
2013 module_param(lpfc_devloss_tmo, int, 0);
2014 MODULE_PARM_DESC(lpfc_devloss_tmo,
2015 "Seconds driver will hold I/O waiting "
2016 "for a device to come back");
2017 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2018 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2019 lpfc_vport_param_show(devloss_tmo)
2022 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2023 * @vport: lpfc vport structure pointer.
2024 * @val: contains the tmo value.
2027 * If val is in a valid range then set the vport nodev tmo,
2028 * devloss tmo, also set the vport dev loss tmo changed flag.
2029 * Else a kernel error message is printed.
2032 * zero if val is in range
2033 * -EINVAL val out of range
2036 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2038 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2039 vport->cfg_nodev_tmo = val;
2040 vport->cfg_devloss_tmo = val;
2041 vport->dev_loss_tmo_changed = 1;
2042 lpfc_update_rport_devloss_tmo(vport);
2046 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2047 "0404 lpfc_devloss_tmo attribute cannot be set to"
2048 " %d, allowed range is [%d, %d]\n",
2049 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2053 lpfc_vport_param_store(devloss_tmo)
2054 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2055 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2058 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2059 # deluged with LOTS of information.
2060 # You can set a bit mask to record specific types of verbose messages:
2061 # See lpfc_logmsh.h for definitions.
2063 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2064 "Verbose logging bit-mask");
2067 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2068 # objects that have been registered with the nameserver after login.
2070 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2071 "Deregister nameserver objects before LOGO");
2074 # lun_queue_depth: This parameter is used to limit the number of outstanding
2075 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2077 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2078 "Max number of FCP commands we can queue to a specific LUN");
2081 # hba_queue_depth: This parameter is used to limit the number of outstanding
2082 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2083 # value is greater than the maximum number of exchanges supported by the HBA,
2084 # then maximum number of exchanges supported by the HBA is used to determine
2085 # the hba_queue_depth.
2087 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2088 "Max number of FCP commands we can queue to a lpfc HBA");
2091 # peer_port_login: This parameter allows/prevents logins
2092 # between peer ports hosted on the same physical port.
2093 # When this parameter is set 0 peer ports of same physical port
2094 # are not allowed to login to each other.
2095 # When this parameter is set 1 peer ports of same physical port
2096 # are allowed to login to each other.
2097 # Default value of this parameter is 0.
2099 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2100 "Allow peer ports on the same physical port to login to each "
2104 # restrict_login: This parameter allows/prevents logins
2105 # between Virtual Ports and remote initiators.
2106 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2107 # other initiators and will attempt to PLOGI all remote ports.
2108 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2109 # remote ports and will not attempt to PLOGI to other initiators.
2110 # This parameter does not restrict to the physical port.
2111 # This parameter does not restrict logins to Fabric resident remote ports.
2112 # Default value of this parameter is 1.
2114 static int lpfc_restrict_login = 1;
2115 module_param(lpfc_restrict_login, int, 0);
2116 MODULE_PARM_DESC(lpfc_restrict_login,
2117 "Restrict virtual ports login to remote initiators.");
2118 lpfc_vport_param_show(restrict_login);
2121 * lpfc_restrict_login_init - Set the vport restrict login flag
2122 * @vport: lpfc vport structure pointer.
2123 * @val: contains the restrict login value.
2126 * If val is not in a valid range then log a kernel error message and set
2127 * the vport restrict login to one.
2128 * If the port type is physical clear the restrict login flag and return.
2129 * Else set the restrict login flag to val.
2132 * zero if val is in range
2133 * -EINVAL val out of range
2136 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2138 if (val < 0 || val > 1) {
2139 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2140 "0422 lpfc_restrict_login attribute cannot "
2141 "be set to %d, allowed range is [0, 1]\n",
2143 vport->cfg_restrict_login = 1;
2146 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2147 vport->cfg_restrict_login = 0;
2150 vport->cfg_restrict_login = val;
2155 * lpfc_restrict_login_set - Set the vport restrict login flag
2156 * @vport: lpfc vport structure pointer.
2157 * @val: contains the restrict login value.
2160 * If val is not in a valid range then log a kernel error message and set
2161 * the vport restrict login to one.
2162 * If the port type is physical and the val is not zero log a kernel
2163 * error message, clear the restrict login flag and return zero.
2164 * Else set the restrict login flag to val.
2167 * zero if val is in range
2168 * -EINVAL val out of range
2171 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2173 if (val < 0 || val > 1) {
2174 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2175 "0425 lpfc_restrict_login attribute cannot "
2176 "be set to %d, allowed range is [0, 1]\n",
2178 vport->cfg_restrict_login = 1;
2181 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2182 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2183 "0468 lpfc_restrict_login must be 0 for "
2184 "Physical ports.\n");
2185 vport->cfg_restrict_login = 0;
2188 vport->cfg_restrict_login = val;
2191 lpfc_vport_param_store(restrict_login);
2192 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2193 lpfc_restrict_login_show, lpfc_restrict_login_store);
2196 # Some disk devices have a "select ID" or "select Target" capability.
2197 # From a protocol standpoint "select ID" usually means select the
2198 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2199 # annex" which contains a table that maps a "select ID" (a number
2200 # between 0 and 7F) to an ALPA. By default, for compatibility with
2201 # older drivers, the lpfc driver scans this table from low ALPA to high
2204 # Turning on the scan-down variable (on = 1, off = 0) will
2205 # cause the lpfc driver to use an inverted table, effectively
2206 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2208 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2209 # and will not work across a fabric. Also this parameter will take
2210 # effect only in the case when ALPA map is not available.)
2212 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2213 "Start scanning for devices from highest ALPA to lowest");
2216 # lpfc_topology: link topology for init link
2217 # 0x0 = attempt loop mode then point-to-point
2218 # 0x01 = internal loopback mode
2219 # 0x02 = attempt point-to-point mode only
2220 # 0x04 = attempt loop mode only
2221 # 0x06 = attempt point-to-point mode then loop
2222 # Set point-to-point mode if you want to run as an N_Port.
2223 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2224 # Default value is 0.
2228 * lpfc_topology_set - Set the adapters topology field
2229 * @phba: lpfc_hba pointer.
2230 * @val: topology value.
2233 * If val is in a valid range then set the adapter's topology field and
2234 * issue a lip; if the lip fails reset the topology to the old value.
2236 * If the value is not in range log a kernel error message and return an error.
2239 * zero if val is in range and lip okay
2240 * non-zero return value from lpfc_issue_lip()
2241 * -EINVAL val out of range
2244 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2245 const char *buf, size_t count)
2247 struct Scsi_Host *shost = class_to_shost(dev);
2248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2249 struct lpfc_hba *phba = vport->phba;
2252 const char *val_buf = buf;
2256 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2258 val_buf = &buf[strlen("nolip ")];
2261 if (!isdigit(val_buf[0]))
2263 if (sscanf(val_buf, "%i", &val) != 1)
2266 if (val >= 0 && val <= 6) {
2267 prev_val = phba->cfg_topology;
2268 phba->cfg_topology = val;
2272 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2274 phba->cfg_topology = prev_val;
2279 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2280 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2281 "allowed range is [0, 6]\n",
2285 static int lpfc_topology = 0;
2286 module_param(lpfc_topology, int, 0);
2287 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2288 lpfc_param_show(topology)
2289 lpfc_param_init(topology, 0, 0, 6)
2290 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2291 lpfc_topology_show, lpfc_topology_store);
2294 * lpfc_static_vport_show: Read callback function for
2295 * lpfc_static_vport sysfs file.
2296 * @dev: Pointer to class device object.
2297 * @attr: device attribute structure.
2298 * @buf: Data buffer.
2300 * This function is the read call back function for
2301 * lpfc_static_vport sysfs file. The lpfc_static_vport
2302 * sysfs file report the mageability of the vport.
2305 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2308 struct Scsi_Host *shost = class_to_shost(dev);
2309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2310 if (vport->vport_flag & STATIC_VPORT)
2311 sprintf(buf, "1\n");
2313 sprintf(buf, "0\n");
2319 * Sysfs attribute to control the statistical data collection.
2321 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2322 lpfc_static_vport_show, NULL);
2325 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2326 * @dev: Pointer to class device.
2327 * @buf: Data buffer.
2328 * @count: Size of the data buffer.
2330 * This function get called when an user write to the lpfc_stat_data_ctrl
2331 * sysfs file. This function parse the command written to the sysfs file
2332 * and take appropriate action. These commands are used for controlling
2333 * driver statistical data collection.
2334 * Following are the command this function handles.
2336 * setbucket <bucket_type> <base> <step>
2337 * = Set the latency buckets.
2338 * destroybucket = destroy all the buckets.
2339 * start = start data collection
2340 * stop = stop data collection
2341 * reset = reset the collected data
2344 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2345 const char *buf, size_t count)
2347 struct Scsi_Host *shost = class_to_shost(dev);
2348 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2349 struct lpfc_hba *phba = vport->phba;
2350 #define LPFC_MAX_DATA_CTRL_LEN 1024
2351 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2353 char *str_ptr, *token;
2354 struct lpfc_vport **vports;
2355 struct Scsi_Host *v_shost;
2356 char *bucket_type_str, *base_str, *step_str;
2357 unsigned long base, step, bucket_type;
2359 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2360 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2363 strcpy(bucket_data, buf);
2364 str_ptr = &bucket_data[0];
2365 /* Ignore this token - this is command token */
2366 token = strsep(&str_ptr, "\t ");
2370 bucket_type_str = strsep(&str_ptr, "\t ");
2371 if (!bucket_type_str)
2374 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2375 bucket_type = LPFC_LINEAR_BUCKET;
2376 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2377 bucket_type = LPFC_POWER2_BUCKET;
2381 base_str = strsep(&str_ptr, "\t ");
2384 base = simple_strtoul(base_str, NULL, 0);
2386 step_str = strsep(&str_ptr, "\t ");
2389 step = simple_strtoul(step_str, NULL, 0);
2393 /* Block the data collection for every vport */
2394 vports = lpfc_create_vport_work_array(phba);
2398 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2399 v_shost = lpfc_shost_from_vport(vports[i]);
2400 spin_lock_irq(v_shost->host_lock);
2401 /* Block and reset data collection */
2402 vports[i]->stat_data_blocked = 1;
2403 if (vports[i]->stat_data_enabled)
2404 lpfc_vport_reset_stat_data(vports[i]);
2405 spin_unlock_irq(v_shost->host_lock);
2408 /* Set the bucket attributes */
2409 phba->bucket_type = bucket_type;
2410 phba->bucket_base = base;
2411 phba->bucket_step = step;
2413 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2414 v_shost = lpfc_shost_from_vport(vports[i]);
2416 /* Unblock data collection */
2417 spin_lock_irq(v_shost->host_lock);
2418 vports[i]->stat_data_blocked = 0;
2419 spin_unlock_irq(v_shost->host_lock);
2421 lpfc_destroy_vport_work_array(phba, vports);
2425 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2426 vports = lpfc_create_vport_work_array(phba);
2430 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2431 v_shost = lpfc_shost_from_vport(vports[i]);
2432 spin_lock_irq(shost->host_lock);
2433 vports[i]->stat_data_blocked = 1;
2434 lpfc_free_bucket(vport);
2435 vport->stat_data_enabled = 0;
2436 vports[i]->stat_data_blocked = 0;
2437 spin_unlock_irq(shost->host_lock);
2439 lpfc_destroy_vport_work_array(phba, vports);
2440 phba->bucket_type = LPFC_NO_BUCKET;
2441 phba->bucket_base = 0;
2442 phba->bucket_step = 0;
2446 if (!strncmp(buf, "start", strlen("start"))) {
2447 /* If no buckets configured return error */
2448 if (phba->bucket_type == LPFC_NO_BUCKET)
2450 spin_lock_irq(shost->host_lock);
2451 if (vport->stat_data_enabled) {
2452 spin_unlock_irq(shost->host_lock);
2455 lpfc_alloc_bucket(vport);
2456 vport->stat_data_enabled = 1;
2457 spin_unlock_irq(shost->host_lock);
2461 if (!strncmp(buf, "stop", strlen("stop"))) {
2462 spin_lock_irq(shost->host_lock);
2463 if (vport->stat_data_enabled == 0) {
2464 spin_unlock_irq(shost->host_lock);
2467 lpfc_free_bucket(vport);
2468 vport->stat_data_enabled = 0;
2469 spin_unlock_irq(shost->host_lock);
2473 if (!strncmp(buf, "reset", strlen("reset"))) {
2474 if ((phba->bucket_type == LPFC_NO_BUCKET)
2475 || !vport->stat_data_enabled)
2477 spin_lock_irq(shost->host_lock);
2478 vport->stat_data_blocked = 1;
2479 lpfc_vport_reset_stat_data(vport);
2480 vport->stat_data_blocked = 0;
2481 spin_unlock_irq(shost->host_lock);
2489 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2490 * @dev: Pointer to class device object.
2491 * @buf: Data buffer.
2493 * This function is the read call back function for
2494 * lpfc_stat_data_ctrl sysfs file. This function report the
2495 * current statistical data collection state.
2498 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2501 struct Scsi_Host *shost = class_to_shost(dev);
2502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2503 struct lpfc_hba *phba = vport->phba;
2507 unsigned long bucket_value;
2509 switch (phba->bucket_type) {
2510 case LPFC_LINEAR_BUCKET:
2511 bucket_type = "linear";
2513 case LPFC_POWER2_BUCKET:
2514 bucket_type = "power2";
2517 bucket_type = "No Bucket";
2521 sprintf(&buf[index], "Statistical Data enabled :%d, "
2522 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2523 " Bucket step :%d\nLatency Ranges :",
2524 vport->stat_data_enabled, vport->stat_data_blocked,
2525 bucket_type, phba->bucket_base, phba->bucket_step);
2526 index = strlen(buf);
2527 if (phba->bucket_type != LPFC_NO_BUCKET) {
2528 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2529 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2530 bucket_value = phba->bucket_base +
2531 phba->bucket_step * i;
2533 bucket_value = phba->bucket_base +
2534 (1 << i) * phba->bucket_step;
2536 if (index + 10 > PAGE_SIZE)
2538 sprintf(&buf[index], "%08ld ", bucket_value);
2539 index = strlen(buf);
2542 sprintf(&buf[index], "\n");
2547 * Sysfs attribute to control the statistical data collection.
2549 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2550 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2553 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2557 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2560 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2561 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2562 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2566 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2567 * @kobj: Pointer to the kernel object
2568 * @bin_attr: Attribute object
2569 * @buff: Buffer pointer
2571 * @count: Buffer size
2573 * This function is the read call back function for lpfc_drvr_stat_data
2574 * sysfs file. This function export the statistical data to user
2578 sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2579 char *buf, loff_t off, size_t count)
2581 struct device *dev = container_of(kobj, struct device,
2583 struct Scsi_Host *shost = class_to_shost(dev);
2584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2585 struct lpfc_hba *phba = vport->phba;
2586 int i = 0, index = 0;
2587 unsigned long nport_index;
2588 struct lpfc_nodelist *ndlp = NULL;
2589 nport_index = (unsigned long)off /
2590 MAX_STAT_DATA_SIZE_PER_TARGET;
2592 if (!vport->stat_data_enabled || vport->stat_data_blocked
2593 || (phba->bucket_type == LPFC_NO_BUCKET))
2596 spin_lock_irq(shost->host_lock);
2597 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2598 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2601 if (nport_index > 0) {
2606 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2610 if (!ndlp->lat_data)
2614 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2615 ndlp->nlp_portname.u.wwn[0],
2616 ndlp->nlp_portname.u.wwn[1],
2617 ndlp->nlp_portname.u.wwn[2],
2618 ndlp->nlp_portname.u.wwn[3],
2619 ndlp->nlp_portname.u.wwn[4],
2620 ndlp->nlp_portname.u.wwn[5],
2621 ndlp->nlp_portname.u.wwn[6],
2622 ndlp->nlp_portname.u.wwn[7]);
2624 index = strlen(buf);
2626 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2627 sprintf(&buf[index], "%010u,",
2628 ndlp->lat_data[i].cmd_count);
2629 index = strlen(buf);
2631 sprintf(&buf[index], "\n");
2632 index = strlen(buf);
2634 spin_unlock_irq(shost->host_lock);
2638 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2640 .name = "lpfc_drvr_stat_data",
2642 .owner = THIS_MODULE,
2644 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2645 .read = sysfs_drvr_stat_data_read,
2650 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2652 # 0 = auto select (default)
2657 # Value range is [0,8]. Default value is 0.
2661 * lpfc_link_speed_set - Set the adapters link speed
2662 * @phba: lpfc_hba pointer.
2663 * @val: link speed value.
2666 * If val is in a valid range then set the adapter's link speed field and
2667 * issue a lip; if the lip fails reset the link speed to the old value.
2670 * If the value is not in range log a kernel error message and return an error.
2673 * zero if val is in range and lip okay.
2674 * non-zero return value from lpfc_issue_lip()
2675 * -EINVAL val out of range
2678 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2679 const char *buf, size_t count)
2681 struct Scsi_Host *shost = class_to_shost(dev);
2682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2683 struct lpfc_hba *phba = vport->phba;
2686 const char *val_buf = buf;
2690 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2692 val_buf = &buf[strlen("nolip ")];
2695 if (!isdigit(val_buf[0]))
2697 if (sscanf(val_buf, "%i", &val) != 1)
2700 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2701 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2702 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2703 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2704 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2707 if ((val >= 0 && val <= 8)
2708 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2709 prev_val = phba->cfg_link_speed;
2710 phba->cfg_link_speed = val;
2714 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2716 phba->cfg_link_speed = prev_val;
2722 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2723 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2724 "allowed range is [0, 8]\n",
2729 static int lpfc_link_speed = 0;
2730 module_param(lpfc_link_speed, int, 0);
2731 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2732 lpfc_param_show(link_speed)
2735 * lpfc_link_speed_init - Set the adapters link speed
2736 * @phba: lpfc_hba pointer.
2737 * @val: link speed value.
2740 * If val is in a valid range then set the adapter's link speed field.
2743 * If the value is not in range log a kernel error message, clear the link
2744 * speed and return an error.
2747 * zero if val saved.
2748 * -EINVAL val out of range
2751 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2753 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2754 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2755 phba->cfg_link_speed = val;
2758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2759 "0405 lpfc_link_speed attribute cannot "
2760 "be set to %d, allowed values are "
2761 "["LPFC_LINK_SPEED_STRING"]\n", val);
2762 phba->cfg_link_speed = 0;
2766 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2767 lpfc_link_speed_show, lpfc_link_speed_store);
2770 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2771 # 0 = aer disabled or not supported
2772 # 1 = aer supported and enabled (default)
2773 # Value range is [0,1]. Default value is 1.
2777 * lpfc_aer_support_store - Set the adapter for aer support
2779 * @dev: class device that is converted into a Scsi_host.
2780 * @attr: device attribute, not used.
2781 * @buf: containing the string "selective".
2782 * @count: unused variable.
2785 * If the val is 1 and currently the device's AER capability was not
2786 * enabled, invoke the kernel's enable AER helper routine, trying to
2787 * enable the device's AER capability. If the helper routine enabling
2788 * AER returns success, update the device's cfg_aer_support flag to
2789 * indicate AER is supported by the device; otherwise, if the device
2790 * AER capability is already enabled to support AER, then do nothing.
2792 * If the val is 0 and currently the device's AER support was enabled,
2793 * invoke the kernel's disable AER helper routine. After that, update
2794 * the device's cfg_aer_support flag to indicate AER is not supported
2795 * by the device; otherwise, if the device AER capability is already
2796 * disabled from supporting AER, then do nothing.
2799 * length of the buf on success if val is in range the intended mode
2801 * -EINVAL if val out of range or intended mode is not supported.
2804 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2805 const char *buf, size_t count)
2807 struct Scsi_Host *shost = class_to_shost(dev);
2808 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2809 struct lpfc_hba *phba = vport->phba;
2810 int val = 0, rc = -EINVAL;
2812 if (!isdigit(buf[0]))
2814 if (sscanf(buf, "%i", &val) != 1)
2819 if (phba->hba_flag & HBA_AER_ENABLED) {
2820 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2822 spin_lock_irq(&phba->hbalock);
2823 phba->hba_flag &= ~HBA_AER_ENABLED;
2824 spin_unlock_irq(&phba->hbalock);
2825 phba->cfg_aer_support = 0;
2830 phba->cfg_aer_support = 0;
2834 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2835 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2837 spin_lock_irq(&phba->hbalock);
2838 phba->hba_flag |= HBA_AER_ENABLED;
2839 spin_unlock_irq(&phba->hbalock);
2840 phba->cfg_aer_support = 1;
2845 phba->cfg_aer_support = 1;
2855 static int lpfc_aer_support = 1;
2856 module_param(lpfc_aer_support, int, 1);
2857 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2858 lpfc_param_show(aer_support)
2861 * lpfc_aer_support_init - Set the initial adapters aer support flag
2862 * @phba: lpfc_hba pointer.
2863 * @val: link speed value.
2866 * If val is in a valid range [0,1], then set the adapter's initial
2867 * cfg_aer_support field. It will be up to the driver's probe_one
2868 * routine to determine whether the device's AER support can be set
2872 * If the value is not in range log a kernel error message, and
2873 * choose the default value of setting AER support and return.
2876 * zero if val saved.
2877 * -EINVAL val out of range
2880 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
2882 if (val == 0 || val == 1) {
2883 phba->cfg_aer_support = val;
2886 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2887 "2712 lpfc_aer_support attribute value %d out "
2888 "of range, allowed values are 0|1, setting it "
2889 "to default value of 1\n", val);
2890 phba->cfg_aer_support = 1;
2894 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
2895 lpfc_aer_support_show, lpfc_aer_support_store);
2898 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
2899 * @dev: class device that is converted into a Scsi_host.
2900 * @attr: device attribute, not used.
2901 * @buf: containing the string "selective".
2902 * @count: unused variable.
2905 * If the @buf contains 1 and the device currently has the AER support
2906 * enabled, then invokes the kernel AER helper routine
2907 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
2908 * error status register.
2913 * -EINVAL if the buf does not contain the 1 or the device is not currently
2914 * enabled with the AER support.
2917 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
2918 const char *buf, size_t count)
2920 struct Scsi_Host *shost = class_to_shost(dev);
2921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2922 struct lpfc_hba *phba = vport->phba;
2925 if (!isdigit(buf[0]))
2927 if (sscanf(buf, "%i", &val) != 1)
2930 if (val == 1 && phba->hba_flag & HBA_AER_ENABLED)
2931 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
2939 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
2940 lpfc_aer_cleanup_state);
2943 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2944 # Value range is [2,3]. Default value is 3.
2946 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2947 "Select Fibre Channel class of service for FCP sequences");
2950 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2951 # is [0,1]. Default value is 0.
2953 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2954 "Use ADISC on rediscovery to authenticate FCP devices");
2957 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
2958 # depth. Default value is 0. When the value of this parameter is zero the
2959 # SCSI command completion time is not used for controlling I/O queue depth. When
2960 # the parameter is set to a non-zero value, the I/O queue depth is controlled
2961 # to limit the I/O completion time to the parameter value.
2962 # The value is set in milliseconds.
2964 static int lpfc_max_scsicmpl_time;
2965 module_param(lpfc_max_scsicmpl_time, int, 0);
2966 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
2967 "Use command completion time to control queue depth");
2968 lpfc_vport_param_show(max_scsicmpl_time);
2969 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
2971 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
2973 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2974 struct lpfc_nodelist *ndlp, *next_ndlp;
2976 if (val == vport->cfg_max_scsicmpl_time)
2978 if ((val < 0) || (val > 60000))
2980 vport->cfg_max_scsicmpl_time = val;
2982 spin_lock_irq(shost->host_lock);
2983 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2984 if (!NLP_CHK_NODE_ACT(ndlp))
2986 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2988 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
2990 spin_unlock_irq(shost->host_lock);
2993 lpfc_vport_param_store(max_scsicmpl_time);
2994 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
2995 lpfc_max_scsicmpl_time_show,
2996 lpfc_max_scsicmpl_time_store);
2999 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3000 # range is [0,1]. Default value is 0.
3002 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3005 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3006 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3007 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3008 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3009 # cr_delay is set to 0.
3011 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3012 "interrupt response is generated");
3014 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3015 "interrupt response is generated");
3018 # lpfc_multi_ring_support: Determines how many rings to spread available
3019 # cmd/rsp IOCB entries across.
3020 # Value range is [1,2]. Default value is 1.
3022 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3023 "SLI rings to spread IOCB entries across");
3026 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3027 # identifies what rctl value to configure the additional ring for.
3028 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3030 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3031 255, "Identifies RCTL for additional ring configuration");
3034 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3035 # identifies what type value to configure the additional ring for.
3036 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3038 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3039 255, "Identifies TYPE for additional ring configuration");
3042 # lpfc_fdmi_on: controls FDMI support.
3043 # 0 = no FDMI support
3044 # 1 = support FDMI without attribute of hostname
3045 # 2 = support FDMI with attribute of hostname
3046 # Value range [0,2]. Default value is 0.
3048 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3051 # Specifies the maximum number of ELS cmds we can have outstanding (for
3052 # discovery). Value range is [1,64]. Default value = 32.
3054 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3055 "during discovery");
3058 # lpfc_max_luns: maximum allowed LUN.
3059 # Value range is [0,65535]. Default value is 255.
3060 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3062 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3065 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3066 # Value range is [1,255], default value is 10.
3068 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3069 "Milliseconds driver will wait between polling FCP ring");
3072 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3073 # support this feature
3074 # 0 = MSI disabled (default)
3077 # Value range is [0,2]. Default value is 0.
3079 LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
3080 "MSI-X (2), if possible");
3083 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3085 # Value range is [636,651042]. Default value is 10000.
3087 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3088 "Set the maximum number of fast-path FCP interrupts per second");
3091 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3093 # Value range is [1,31]. Default value is 4.
3095 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3096 "Set the number of fast-path FCP work queues, if possible");
3099 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3101 # Value range is [1,7]. Default value is 1.
3103 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3104 "Set the number of fast-path FCP event queues, if possible");
3107 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3108 # 0 = HBA resets disabled
3109 # 1 = HBA resets enabled (default)
3110 # Value range is [0,1]. Default value is 1.
3112 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3115 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3116 # 0 = HBA Heartbeat disabled
3117 # 1 = HBA Heartbeat enabled (default)
3118 # Value range is [0,1]. Default value is 1.
3120 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
3123 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3124 # 0 = BlockGuard disabled (default)
3125 # 1 = BlockGuard enabled
3126 # Value range is [0,1]. Default value is 0.
3128 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3131 # lpfc_enable_fip: When set, FIP is required to start discovery. If not
3132 # set, the driver will add an FCF record manually if the port has no
3133 # FCF records available and start discovery.
3134 # Value range is [0,1]. Default value is 1 (enabled)
3136 LPFC_ATTR_RW(enable_fip, 0, 0, 1, "Enable FIP Discovery");
3141 # - Bit mask of host protection capabilities used to register with the
3143 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3144 # - Allows you to ultimately specify which profiles to use
3145 # - Default will result in registering capabilities for all profiles.
3148 unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3150 module_param(lpfc_prot_mask, uint, 0);
3151 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3154 # lpfc_prot_guard: i
3155 # - Bit mask of protection guard types to register with the SCSI mid-layer
3156 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3157 # - Allows you to ultimately specify which profiles to use
3158 # - Default will result in registering capabilities for all guard types
3161 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3162 module_param(lpfc_prot_guard, byte, 0);
3163 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3167 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3168 * This value can be set to values between 64 and 256. The default value is
3169 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3170 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3172 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3173 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3175 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3176 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3177 "Max Protection Scatter Gather Segment Count");
3179 struct device_attribute *lpfc_hba_attrs[] = {
3181 &dev_attr_bg_guard_err,
3182 &dev_attr_bg_apptag_err,
3183 &dev_attr_bg_reftag_err,
3185 &dev_attr_serialnum,
3186 &dev_attr_modeldesc,
3187 &dev_attr_modelname,
3188 &dev_attr_programtype,
3192 &dev_attr_option_rom_version,
3193 &dev_attr_link_state,
3194 &dev_attr_num_discovered_ports,
3195 &dev_attr_menlo_mgmt_mode,
3196 &dev_attr_lpfc_drvr_version,
3197 &dev_attr_lpfc_temp_sensor,
3198 &dev_attr_lpfc_log_verbose,
3199 &dev_attr_lpfc_lun_queue_depth,
3200 &dev_attr_lpfc_hba_queue_depth,
3201 &dev_attr_lpfc_peer_port_login,
3202 &dev_attr_lpfc_nodev_tmo,
3203 &dev_attr_lpfc_devloss_tmo,
3204 &dev_attr_lpfc_enable_fip,
3205 &dev_attr_lpfc_fcp_class,
3206 &dev_attr_lpfc_use_adisc,
3207 &dev_attr_lpfc_ack0,
3208 &dev_attr_lpfc_topology,
3209 &dev_attr_lpfc_scan_down,
3210 &dev_attr_lpfc_link_speed,
3211 &dev_attr_lpfc_cr_delay,
3212 &dev_attr_lpfc_cr_count,
3213 &dev_attr_lpfc_multi_ring_support,
3214 &dev_attr_lpfc_multi_ring_rctl,
3215 &dev_attr_lpfc_multi_ring_type,
3216 &dev_attr_lpfc_fdmi_on,
3217 &dev_attr_lpfc_max_luns,
3218 &dev_attr_lpfc_enable_npiv,
3219 &dev_attr_nport_evt_cnt,
3220 &dev_attr_board_mode,
3227 &dev_attr_npiv_info,
3228 &dev_attr_issue_reset,
3229 &dev_attr_lpfc_poll,
3230 &dev_attr_lpfc_poll_tmo,
3231 &dev_attr_lpfc_use_msi,
3232 &dev_attr_lpfc_fcp_imax,
3233 &dev_attr_lpfc_fcp_wq_count,
3234 &dev_attr_lpfc_fcp_eq_count,
3235 &dev_attr_lpfc_enable_bg,
3236 &dev_attr_lpfc_soft_wwnn,
3237 &dev_attr_lpfc_soft_wwpn,
3238 &dev_attr_lpfc_soft_wwn_enable,
3239 &dev_attr_lpfc_enable_hba_reset,
3240 &dev_attr_lpfc_enable_hba_heartbeat,
3241 &dev_attr_lpfc_sg_seg_cnt,
3242 &dev_attr_lpfc_max_scsicmpl_time,
3243 &dev_attr_lpfc_stat_data_ctrl,
3244 &dev_attr_lpfc_prot_sg_seg_cnt,
3245 &dev_attr_lpfc_aer_support,
3246 &dev_attr_lpfc_aer_state_cleanup,
3250 struct device_attribute *lpfc_vport_attrs[] = {
3252 &dev_attr_link_state,
3253 &dev_attr_num_discovered_ports,
3254 &dev_attr_lpfc_drvr_version,
3255 &dev_attr_lpfc_log_verbose,
3256 &dev_attr_lpfc_lun_queue_depth,
3257 &dev_attr_lpfc_nodev_tmo,
3258 &dev_attr_lpfc_devloss_tmo,
3259 &dev_attr_lpfc_enable_fip,
3260 &dev_attr_lpfc_hba_queue_depth,
3261 &dev_attr_lpfc_peer_port_login,
3262 &dev_attr_lpfc_restrict_login,
3263 &dev_attr_lpfc_fcp_class,
3264 &dev_attr_lpfc_use_adisc,
3265 &dev_attr_lpfc_fdmi_on,
3266 &dev_attr_lpfc_max_luns,
3267 &dev_attr_nport_evt_cnt,
3268 &dev_attr_npiv_info,
3269 &dev_attr_lpfc_enable_da_id,
3270 &dev_attr_lpfc_max_scsicmpl_time,
3271 &dev_attr_lpfc_stat_data_ctrl,
3272 &dev_attr_lpfc_static_vport,
3277 * sysfs_ctlreg_write - Write method for writing to ctlreg
3278 * @kobj: kernel kobject that contains the kernel class device.
3279 * @bin_attr: kernel attributes passed to us.
3280 * @buf: contains the data to be written to the adapter IOREG space.
3281 * @off: offset into buffer to beginning of data.
3282 * @count: bytes to transfer.
3285 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3286 * Uses the adapter io control registers to send buf contents to the adapter.
3289 * -ERANGE off and count combo out of range
3290 * -EINVAL off, count or buff address invalid
3291 * -EPERM adapter is offline
3292 * value of count, buf contents written
3295 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3296 char *buf, loff_t off, size_t count)
3299 struct device *dev = container_of(kobj, struct device, kobj);
3300 struct Scsi_Host *shost = class_to_shost(dev);
3301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3302 struct lpfc_hba *phba = vport->phba;
3304 if (phba->sli_rev >= LPFC_SLI_REV4)
3307 if ((off + count) > FF_REG_AREA_SIZE)
3310 if (count == 0) return 0;
3312 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3315 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3319 spin_lock_irq(&phba->hbalock);
3320 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3321 writel(*((uint32_t *)(buf + buf_off)),
3322 phba->ctrl_regs_memmap_p + off + buf_off);
3324 spin_unlock_irq(&phba->hbalock);
3330 * sysfs_ctlreg_read - Read method for reading from ctlreg
3331 * @kobj: kernel kobject that contains the kernel class device.
3332 * @bin_attr: kernel attributes passed to us.
3333 * @buf: if succesful contains the data from the adapter IOREG space.
3334 * @off: offset into buffer to beginning of data.
3335 * @count: bytes to transfer.
3338 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3339 * Uses the adapter io control registers to read data into buf.
3342 * -ERANGE off and count combo out of range
3343 * -EINVAL off, count or buff address invalid
3344 * value of count, buf contents read
3347 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3348 char *buf, loff_t off, size_t count)
3352 struct device *dev = container_of(kobj, struct device, kobj);
3353 struct Scsi_Host *shost = class_to_shost(dev);
3354 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3355 struct lpfc_hba *phba = vport->phba;
3357 if (phba->sli_rev >= LPFC_SLI_REV4)
3360 if (off > FF_REG_AREA_SIZE)
3363 if ((off + count) > FF_REG_AREA_SIZE)
3364 count = FF_REG_AREA_SIZE - off;
3366 if (count == 0) return 0;
3368 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3371 spin_lock_irq(&phba->hbalock);
3373 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3374 tmp_ptr = (uint32_t *)(buf + buf_off);
3375 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3378 spin_unlock_irq(&phba->hbalock);
3383 static struct bin_attribute sysfs_ctlreg_attr = {
3386 .mode = S_IRUSR | S_IWUSR,
3389 .read = sysfs_ctlreg_read,
3390 .write = sysfs_ctlreg_write,
3394 * sysfs_mbox_idle - frees the sysfs mailbox
3395 * @phba: lpfc_hba pointer
3398 sysfs_mbox_idle(struct lpfc_hba *phba)
3400 phba->sysfs_mbox.state = SMBOX_IDLE;
3401 phba->sysfs_mbox.offset = 0;
3403 if (phba->sysfs_mbox.mbox) {
3404 mempool_free(phba->sysfs_mbox.mbox,
3405 phba->mbox_mem_pool);
3406 phba->sysfs_mbox.mbox = NULL;
3411 * sysfs_mbox_write - Write method for writing information via mbox
3412 * @kobj: kernel kobject that contains the kernel class device.
3413 * @bin_attr: kernel attributes passed to us.
3414 * @buf: contains the data to be written to sysfs mbox.
3415 * @off: offset into buffer to beginning of data.
3416 * @count: bytes to transfer.
3419 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3420 * Uses the sysfs mbox to send buf contents to the adapter.
3423 * -ERANGE off and count combo out of range
3424 * -EINVAL off, count or buff address invalid
3425 * zero if count is zero
3426 * -EPERM adapter is offline
3427 * -ENOMEM failed to allocate memory for the mail box
3428 * -EAGAIN offset, state or mbox is NULL
3429 * count number of bytes transferred
3432 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3433 char *buf, loff_t off, size_t count)
3435 struct device *dev = container_of(kobj, struct device, kobj);
3436 struct Scsi_Host *shost = class_to_shost(dev);
3437 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3438 struct lpfc_hba *phba = vport->phba;
3439 struct lpfcMboxq *mbox = NULL;
3441 if ((count + off) > MAILBOX_CMD_SIZE)
3444 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3451 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3454 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3457 spin_lock_irq(&phba->hbalock);
3460 if (phba->sysfs_mbox.mbox)
3461 mempool_free(mbox, phba->mbox_mem_pool);
3463 phba->sysfs_mbox.mbox = mbox;
3464 phba->sysfs_mbox.state = SMBOX_WRITING;
3466 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3467 phba->sysfs_mbox.offset != off ||
3468 phba->sysfs_mbox.mbox == NULL) {
3469 sysfs_mbox_idle(phba);
3470 spin_unlock_irq(&phba->hbalock);
3475 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3478 phba->sysfs_mbox.offset = off + count;
3480 spin_unlock_irq(&phba->hbalock);
3486 * sysfs_mbox_read - Read method for reading information via mbox
3487 * @kobj: kernel kobject that contains the kernel class device.
3488 * @bin_attr: kernel attributes passed to us.
3489 * @buf: contains the data to be read from sysfs mbox.
3490 * @off: offset into buffer to beginning of data.
3491 * @count: bytes to transfer.
3494 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3495 * Uses the sysfs mbox to receive data from to the adapter.
3498 * -ERANGE off greater than mailbox command size
3499 * -EINVAL off, count or buff address invalid
3500 * zero if off and count are zero
3501 * -EACCES adapter over temp
3502 * -EPERM garbage can value to catch a multitude of errors
3503 * -EAGAIN management IO not permitted, state or off error
3504 * -ETIME mailbox timeout
3505 * -ENODEV mailbox error
3506 * count number of bytes transferred
3509 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3510 char *buf, loff_t off, size_t count)
3512 struct device *dev = container_of(kobj, struct device, kobj);
3513 struct Scsi_Host *shost = class_to_shost(dev);
3514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3515 struct lpfc_hba *phba = vport->phba;
3519 if (off > MAILBOX_CMD_SIZE)
3522 if ((count + off) > MAILBOX_CMD_SIZE)
3523 count = MAILBOX_CMD_SIZE - off;
3525 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3528 if (off && count == 0)
3531 spin_lock_irq(&phba->hbalock);
3533 if (phba->over_temp_state == HBA_OVER_TEMP) {
3534 sysfs_mbox_idle(phba);
3535 spin_unlock_irq(&phba->hbalock);
3540 phba->sysfs_mbox.state == SMBOX_WRITING &&
3541 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3542 pmb = &phba->sysfs_mbox.mbox->u.mb;
3543 switch (pmb->mbxCommand) {
3547 case MBX_CONFIG_LINK:
3548 case MBX_CONFIG_RING:
3549 case MBX_RESET_RING:
3550 case MBX_UNREG_LOGIN:
3552 case MBX_DUMP_CONTEXT:
3557 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3558 printk(KERN_WARNING "mbox_read:Command 0x%x "
3559 "is illegal in on-line state\n",
3561 sysfs_mbox_idle(phba);
3562 spin_unlock_irq(&phba->hbalock);
3566 case MBX_WRITE_VPARMS:
3569 case MBX_READ_CONFIG:
3570 case MBX_READ_RCONFIG:
3571 case MBX_READ_STATUS:
3574 case MBX_READ_LNK_STAT:
3575 case MBX_DUMP_MEMORY:
3577 case MBX_UPDATE_CFG:
3578 case MBX_KILL_BOARD:
3580 case MBX_LOAD_EXP_ROM:
3582 case MBX_DEL_LD_ENTRY:
3583 case MBX_SET_VARIABLE:
3585 case MBX_PORT_CAPABILITIES:
3586 case MBX_PORT_IOV_CONTROL:
3588 case MBX_READ_SPARM64:
3592 case MBX_REG_LOGIN64:
3593 case MBX_CONFIG_PORT:
3594 case MBX_RUN_BIU_DIAG:
3595 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3597 sysfs_mbox_idle(phba);
3598 spin_unlock_irq(&phba->hbalock);
3601 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3603 sysfs_mbox_idle(phba);
3604 spin_unlock_irq(&phba->hbalock);
3608 /* If HBA encountered an error attention, allow only DUMP
3609 * or RESTART mailbox commands until the HBA is restarted.
3611 if (phba->pport->stopped &&
3612 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3613 pmb->mbxCommand != MBX_RESTART &&
3614 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3615 pmb->mbxCommand != MBX_WRITE_WWN)
3616 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3617 "1259 mbox: Issued mailbox cmd "
3618 "0x%x while in stopped state.\n",
3621 phba->sysfs_mbox.mbox->vport = vport;
3623 /* Don't allow mailbox commands to be sent when blocked
3624 * or when in the middle of discovery
3626 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3627 sysfs_mbox_idle(phba);
3628 spin_unlock_irq(&phba->hbalock);
3632 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3633 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3635 spin_unlock_irq(&phba->hbalock);
3636 rc = lpfc_sli_issue_mbox (phba,
3637 phba->sysfs_mbox.mbox,
3639 spin_lock_irq(&phba->hbalock);
3642 spin_unlock_irq(&phba->hbalock);
3643 rc = lpfc_sli_issue_mbox_wait (phba,
3644 phba->sysfs_mbox.mbox,
3645 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3646 spin_lock_irq(&phba->hbalock);
3649 if (rc != MBX_SUCCESS) {
3650 if (rc == MBX_TIMEOUT) {
3651 phba->sysfs_mbox.mbox = NULL;
3653 sysfs_mbox_idle(phba);
3654 spin_unlock_irq(&phba->hbalock);
3655 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3657 phba->sysfs_mbox.state = SMBOX_READING;
3659 else if (phba->sysfs_mbox.offset != off ||
3660 phba->sysfs_mbox.state != SMBOX_READING) {
3661 printk(KERN_WARNING "mbox_read: Bad State\n");
3662 sysfs_mbox_idle(phba);
3663 spin_unlock_irq(&phba->hbalock);
3667 memcpy(buf, (uint8_t *) &pmb + off, count);
3669 phba->sysfs_mbox.offset = off + count;
3671 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3672 sysfs_mbox_idle(phba);
3674 spin_unlock_irq(&phba->hbalock);
3679 static struct bin_attribute sysfs_mbox_attr = {
3682 .mode = S_IRUSR | S_IWUSR,
3684 .size = MAILBOX_CMD_SIZE,
3685 .read = sysfs_mbox_read,
3686 .write = sysfs_mbox_write,
3690 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3691 * @vport: address of lpfc vport structure.
3695 * error return code from sysfs_create_bin_file()
3698 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3700 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3703 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3704 &sysfs_drvr_stat_data_attr);
3706 /* Virtual ports do not need ctrl_reg and mbox */
3707 if (error || vport->port_type == LPFC_NPIV_PORT)
3710 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3711 &sysfs_ctlreg_attr);
3713 goto out_remove_stat_attr;
3715 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3718 goto out_remove_ctlreg_attr;
3721 out_remove_ctlreg_attr:
3722 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3723 out_remove_stat_attr:
3724 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3725 &sysfs_drvr_stat_data_attr);
3731 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
3732 * @vport: address of lpfc vport structure.
3735 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
3737 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3738 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3739 &sysfs_drvr_stat_data_attr);
3740 /* Virtual ports do not need ctrl_reg and mbox */
3741 if (vport->port_type == LPFC_NPIV_PORT)
3743 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3744 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3749 * Dynamic FC Host Attributes Support
3753 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
3754 * @shost: kernel scsi host pointer.
3757 lpfc_get_host_port_id(struct Scsi_Host *shost)
3759 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3761 /* note: fc_myDID already in cpu endianness */
3762 fc_host_port_id(shost) = vport->fc_myDID;
3766 * lpfc_get_host_port_type - Set the value of the scsi host port type
3767 * @shost: kernel scsi host pointer.
3770 lpfc_get_host_port_type(struct Scsi_Host *shost)
3772 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3773 struct lpfc_hba *phba = vport->phba;
3775 spin_lock_irq(shost->host_lock);
3777 if (vport->port_type == LPFC_NPIV_PORT) {
3778 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3779 } else if (lpfc_is_link_up(phba)) {
3780 if (phba->fc_topology == TOPOLOGY_LOOP) {
3781 if (vport->fc_flag & FC_PUBLIC_LOOP)
3782 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3784 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3786 if (vport->fc_flag & FC_FABRIC)
3787 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3789 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3792 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3794 spin_unlock_irq(shost->host_lock);
3798 * lpfc_get_host_port_state - Set the value of the scsi host port state
3799 * @shost: kernel scsi host pointer.
3802 lpfc_get_host_port_state(struct Scsi_Host *shost)
3804 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3805 struct lpfc_hba *phba = vport->phba;
3807 spin_lock_irq(shost->host_lock);
3809 if (vport->fc_flag & FC_OFFLINE_MODE)
3810 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3812 switch (phba->link_state) {
3813 case LPFC_LINK_UNKNOWN:
3814 case LPFC_LINK_DOWN:
3815 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3819 case LPFC_HBA_READY:
3820 /* Links up, beyond this port_type reports state */
3821 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3823 case LPFC_HBA_ERROR:
3824 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3827 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3832 spin_unlock_irq(shost->host_lock);
3836 * lpfc_get_host_speed - Set the value of the scsi host speed
3837 * @shost: kernel scsi host pointer.
3840 lpfc_get_host_speed(struct Scsi_Host *shost)
3842 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3843 struct lpfc_hba *phba = vport->phba;
3845 spin_lock_irq(shost->host_lock);
3847 if (lpfc_is_link_up(phba)) {
3848 switch(phba->fc_linkspeed) {
3850 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3853 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3856 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3859 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3862 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3865 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3869 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3871 spin_unlock_irq(shost->host_lock);
3875 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
3876 * @shost: kernel scsi host pointer.
3879 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3882 struct lpfc_hba *phba = vport->phba;
3885 spin_lock_irq(shost->host_lock);
3887 if ((vport->fc_flag & FC_FABRIC) ||
3888 ((phba->fc_topology == TOPOLOGY_LOOP) &&
3889 (vport->fc_flag & FC_PUBLIC_LOOP)))
3890 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
3892 /* fabric is local port if there is no F/FL_Port */
3895 spin_unlock_irq(shost->host_lock);
3897 fc_host_fabric_name(shost) = node_name;
3901 * lpfc_get_stats - Return statistical information about the adapter
3902 * @shost: kernel scsi host pointer.
3905 * NULL on error for link down, no mbox pool, sli2 active,
3906 * management not allowed, memory allocation error, or mbox error.
3910 * address of the adapter host statistics
3912 static struct fc_host_statistics *
3913 lpfc_get_stats(struct Scsi_Host *shost)
3915 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3916 struct lpfc_hba *phba = vport->phba;
3917 struct lpfc_sli *psli = &phba->sli;
3918 struct fc_host_statistics *hs = &phba->link_stats;
3919 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
3920 LPFC_MBOXQ_t *pmboxq;
3922 unsigned long seconds;
3926 * prevent udev from issuing mailbox commands until the port is
3929 if (phba->link_state < LPFC_LINK_DOWN ||
3930 !phba->mbox_mem_pool ||
3931 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
3934 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3937 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3940 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3942 pmb = &pmboxq->u.mb;
3943 pmb->mbxCommand = MBX_READ_STATUS;
3944 pmb->mbxOwner = OWN_HOST;
3945 pmboxq->context1 = NULL;
3946 pmboxq->vport = vport;
3948 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3949 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
3950 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3952 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3954 if (rc != MBX_SUCCESS) {
3955 if (rc != MBX_TIMEOUT)
3956 mempool_free(pmboxq, phba->mbox_mem_pool);
3960 memset(hs, 0, sizeof (struct fc_host_statistics));
3962 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3963 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3964 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3965 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
3967 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3968 pmb->mbxCommand = MBX_READ_LNK_STAT;
3969 pmb->mbxOwner = OWN_HOST;
3970 pmboxq->context1 = NULL;
3971 pmboxq->vport = vport;
3973 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3974 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
3975 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3977 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3979 if (rc != MBX_SUCCESS) {
3980 if (rc != MBX_TIMEOUT)
3981 mempool_free(pmboxq, phba->mbox_mem_pool);
3985 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
3986 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
3987 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
3988 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
3989 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
3990 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
3991 hs->error_frames = pmb->un.varRdLnk.crcCnt;
3993 hs->link_failure_count -= lso->link_failure_count;
3994 hs->loss_of_sync_count -= lso->loss_of_sync_count;
3995 hs->loss_of_signal_count -= lso->loss_of_signal_count;
3996 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
3997 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
3998 hs->invalid_crc_count -= lso->invalid_crc_count;
3999 hs->error_frames -= lso->error_frames;
4001 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4003 hs->nos_count = (phba->link_events >> 1);
4004 hs->nos_count -= lso->link_events;
4005 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
4006 hs->lip_count = (phba->fc_eventTag >> 1);
4007 hs->lip_count -= lso->link_events;
4011 hs->nos_count = (phba->fc_eventTag >> 1);
4012 hs->nos_count -= lso->link_events;
4015 hs->dumped_frames = -1;
4017 seconds = get_seconds();
4018 if (seconds < psli->stats_start)
4019 hs->seconds_since_last_reset = seconds +
4020 ((unsigned long)-1 - psli->stats_start);
4022 hs->seconds_since_last_reset = seconds - psli->stats_start;
4024 mempool_free(pmboxq, phba->mbox_mem_pool);
4030 * lpfc_reset_stats - Copy the adapter link stats information
4031 * @shost: kernel scsi host pointer.
4034 lpfc_reset_stats(struct Scsi_Host *shost)
4036 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4037 struct lpfc_hba *phba = vport->phba;
4038 struct lpfc_sli *psli = &phba->sli;
4039 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4040 LPFC_MBOXQ_t *pmboxq;
4044 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4047 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4050 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4052 pmb = &pmboxq->u.mb;
4053 pmb->mbxCommand = MBX_READ_STATUS;
4054 pmb->mbxOwner = OWN_HOST;
4055 pmb->un.varWords[0] = 0x1; /* reset request */
4056 pmboxq->context1 = NULL;
4057 pmboxq->vport = vport;
4059 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4060 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4061 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4063 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4065 if (rc != MBX_SUCCESS) {
4066 if (rc != MBX_TIMEOUT)
4067 mempool_free(pmboxq, phba->mbox_mem_pool);
4071 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4072 pmb->mbxCommand = MBX_READ_LNK_STAT;
4073 pmb->mbxOwner = OWN_HOST;
4074 pmboxq->context1 = NULL;
4075 pmboxq->vport = vport;
4077 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4078 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4079 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4081 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4083 if (rc != MBX_SUCCESS) {
4084 if (rc != MBX_TIMEOUT)
4085 mempool_free( pmboxq, phba->mbox_mem_pool);
4089 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4090 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4091 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4092 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4093 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4094 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4095 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4096 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4097 lso->link_events = (phba->link_events >> 1);
4099 lso->link_events = (phba->fc_eventTag >> 1);
4101 psli->stats_start = get_seconds();
4103 mempool_free(pmboxq, phba->mbox_mem_pool);
4109 * The LPFC driver treats linkdown handling as target loss events so there
4110 * are no sysfs handlers for link_down_tmo.
4114 * lpfc_get_node_by_target - Return the nodelist for a target
4115 * @starget: kernel scsi target pointer.
4118 * address of the node list if found
4119 * NULL target not found
4121 static struct lpfc_nodelist *
4122 lpfc_get_node_by_target(struct scsi_target *starget)
4124 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4126 struct lpfc_nodelist *ndlp;
4128 spin_lock_irq(shost->host_lock);
4129 /* Search for this, mapped, target ID */
4130 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4131 if (NLP_CHK_NODE_ACT(ndlp) &&
4132 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4133 starget->id == ndlp->nlp_sid) {
4134 spin_unlock_irq(shost->host_lock);
4138 spin_unlock_irq(shost->host_lock);
4143 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4144 * @starget: kernel scsi target pointer.
4147 lpfc_get_starget_port_id(struct scsi_target *starget)
4149 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4151 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4155 * lpfc_get_starget_node_name - Set the target node name
4156 * @starget: kernel scsi target pointer.
4158 * Description: Set the target node name to the ndlp node name wwn or zero.
4161 lpfc_get_starget_node_name(struct scsi_target *starget)
4163 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4165 fc_starget_node_name(starget) =
4166 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4170 * lpfc_get_starget_port_name - Set the target port name
4171 * @starget: kernel scsi target pointer.
4173 * Description: set the target port name to the ndlp port name wwn or zero.
4176 lpfc_get_starget_port_name(struct scsi_target *starget)
4178 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4180 fc_starget_port_name(starget) =
4181 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4185 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4186 * @rport: fc rport address.
4187 * @timeout: new value for dev loss tmo.
4190 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4191 * dev_loss_tmo to one.
4194 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4197 rport->dev_loss_tmo = timeout;
4199 rport->dev_loss_tmo = 1;
4203 * lpfc_rport_show_function - Return rport target information
4206 * Macro that uses field to generate a function with the name lpfc_show_rport_
4208 * lpfc_show_rport_##field: returns the bytes formatted in buf
4209 * @cdev: class converted to an fc_rport.
4210 * @buf: on return contains the target_field or zero.
4212 * Returns: size of formatted string.
4214 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4216 lpfc_show_rport_##field (struct device *dev, \
4217 struct device_attribute *attr, \
4220 struct fc_rport *rport = transport_class_to_rport(dev); \
4221 struct lpfc_rport_data *rdata = rport->hostdata; \
4222 return snprintf(buf, sz, format_string, \
4223 (rdata->target) ? cast rdata->target->field : 0); \
4226 #define lpfc_rport_rd_attr(field, format_string, sz) \
4227 lpfc_rport_show_function(field, format_string, sz, ) \
4228 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4231 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4232 * @fc_vport: The fc_vport who's symbolic name has been changed.
4235 * This function is called by the transport after the @fc_vport's symbolic name
4236 * has been changed. This function re-registers the symbolic name with the
4237 * switch to propogate the change into the fabric if the vport is active.
4240 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4242 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4244 if (vport->port_state == LPFC_VPORT_READY)
4245 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4249 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4250 * @phba: Pointer to lpfc_hba struct.
4252 * This function is called by the lpfc_get_cfgparam() routine to set the
4253 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4254 * log messsage according to the module's lpfc_log_verbose parameter setting
4255 * before hba port or vport created.
4258 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4260 phba->cfg_log_verbose = verbose;
4263 struct fc_function_template lpfc_transport_functions = {
4264 /* fixed attributes the driver supports */
4265 .show_host_node_name = 1,
4266 .show_host_port_name = 1,
4267 .show_host_supported_classes = 1,
4268 .show_host_supported_fc4s = 1,
4269 .show_host_supported_speeds = 1,
4270 .show_host_maxframe_size = 1,
4271 .show_host_symbolic_name = 1,
4273 /* dynamic attributes the driver supports */
4274 .get_host_port_id = lpfc_get_host_port_id,
4275 .show_host_port_id = 1,
4277 .get_host_port_type = lpfc_get_host_port_type,
4278 .show_host_port_type = 1,
4280 .get_host_port_state = lpfc_get_host_port_state,
4281 .show_host_port_state = 1,
4283 /* active_fc4s is shown but doesn't change (thus no get function) */
4284 .show_host_active_fc4s = 1,
4286 .get_host_speed = lpfc_get_host_speed,
4287 .show_host_speed = 1,
4289 .get_host_fabric_name = lpfc_get_host_fabric_name,
4290 .show_host_fabric_name = 1,
4293 * The LPFC driver treats linkdown handling as target loss events
4294 * so there are no sysfs handlers for link_down_tmo.
4297 .get_fc_host_stats = lpfc_get_stats,
4298 .reset_fc_host_stats = lpfc_reset_stats,
4300 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4301 .show_rport_maxframe_size = 1,
4302 .show_rport_supported_classes = 1,
4304 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4305 .show_rport_dev_loss_tmo = 1,
4307 .get_starget_port_id = lpfc_get_starget_port_id,
4308 .show_starget_port_id = 1,
4310 .get_starget_node_name = lpfc_get_starget_node_name,
4311 .show_starget_node_name = 1,
4313 .get_starget_port_name = lpfc_get_starget_port_name,
4314 .show_starget_port_name = 1,
4316 .issue_fc_host_lip = lpfc_issue_lip,
4317 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4318 .terminate_rport_io = lpfc_terminate_rport_io,
4320 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4322 .vport_disable = lpfc_vport_disable,
4324 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4326 .bsg_request = lpfc_bsg_request,
4327 .bsg_timeout = lpfc_bsg_timeout,
4330 struct fc_function_template lpfc_vport_transport_functions = {
4331 /* fixed attributes the driver supports */
4332 .show_host_node_name = 1,
4333 .show_host_port_name = 1,
4334 .show_host_supported_classes = 1,
4335 .show_host_supported_fc4s = 1,
4336 .show_host_supported_speeds = 1,
4337 .show_host_maxframe_size = 1,
4338 .show_host_symbolic_name = 1,
4340 /* dynamic attributes the driver supports */
4341 .get_host_port_id = lpfc_get_host_port_id,
4342 .show_host_port_id = 1,
4344 .get_host_port_type = lpfc_get_host_port_type,
4345 .show_host_port_type = 1,
4347 .get_host_port_state = lpfc_get_host_port_state,
4348 .show_host_port_state = 1,
4350 /* active_fc4s is shown but doesn't change (thus no get function) */
4351 .show_host_active_fc4s = 1,
4353 .get_host_speed = lpfc_get_host_speed,
4354 .show_host_speed = 1,
4356 .get_host_fabric_name = lpfc_get_host_fabric_name,
4357 .show_host_fabric_name = 1,
4360 * The LPFC driver treats linkdown handling as target loss events
4361 * so there are no sysfs handlers for link_down_tmo.
4364 .get_fc_host_stats = lpfc_get_stats,
4365 .reset_fc_host_stats = lpfc_reset_stats,
4367 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4368 .show_rport_maxframe_size = 1,
4369 .show_rport_supported_classes = 1,
4371 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4372 .show_rport_dev_loss_tmo = 1,
4374 .get_starget_port_id = lpfc_get_starget_port_id,
4375 .show_starget_port_id = 1,
4377 .get_starget_node_name = lpfc_get_starget_node_name,
4378 .show_starget_node_name = 1,
4380 .get_starget_port_name = lpfc_get_starget_port_name,
4381 .show_starget_port_name = 1,
4383 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4384 .terminate_rport_io = lpfc_terminate_rport_io,
4386 .vport_disable = lpfc_vport_disable,
4388 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4392 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4393 * @phba: lpfc_hba pointer.
4396 lpfc_get_cfgparam(struct lpfc_hba *phba)
4398 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4399 lpfc_cr_count_init(phba, lpfc_cr_count);
4400 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4401 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4402 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4403 lpfc_ack0_init(phba, lpfc_ack0);
4404 lpfc_topology_init(phba, lpfc_topology);
4405 lpfc_link_speed_init(phba, lpfc_link_speed);
4406 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4407 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4408 lpfc_use_msi_init(phba, lpfc_use_msi);
4409 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4410 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4411 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4412 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4413 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4414 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4415 phba->cfg_poll = lpfc_poll;
4416 phba->cfg_soft_wwnn = 0L;
4417 phba->cfg_soft_wwpn = 0L;
4418 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4419 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4420 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4421 lpfc_enable_fip_init(phba, lpfc_enable_fip);
4422 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4423 lpfc_aer_support_init(phba, lpfc_aer_support);
4429 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4430 * @vport: lpfc_vport pointer.
4433 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4435 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4436 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4437 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4438 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4439 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4440 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4441 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4442 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4443 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4444 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4445 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4446 lpfc_max_luns_init(vport, lpfc_max_luns);
4447 lpfc_scan_down_init(vport, lpfc_scan_down);
4448 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);