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>
27 #include <linux/gfp.h>
28 #include <linux/kernel.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_tcq.h>
34 #include <scsi/scsi_transport_fc.h>
35 #include <scsi/fc/fc_fs.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_version.h"
47 #include "lpfc_compat.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_vport.h"
51 #define LPFC_DEF_DEVLOSS_TMO 30
52 #define LPFC_MIN_DEVLOSS_TMO 1
53 #define LPFC_MAX_DEVLOSS_TMO 255
56 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
57 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
68 * Coded for 32 bit integers only.
71 lpfc_jedec_to_ascii(int incr, char hdw[])
74 for (i = 0; i < 8; i++) {
77 hdw[7 - i] = 0x30 + j;
79 hdw[7 - i] = 0x61 + j - 10;
87 * lpfc_drvr_version_show - Return the Emulex driver string with version number
88 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
92 * Returns: size of formatted string.
95 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
107 * Returns: size of formatted string.
110 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
120 return snprintf(buf, PAGE_SIZE, "0\n");
124 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
143 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
155 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
167 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
179 * lpfc_info_show - Return some pci info about the host in ascii
180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
184 * Returns: size of formatted string.
187 lpfc_info_show(struct device *dev, struct device_attribute *attr,
190 struct Scsi_Host *host = class_to_shost(dev);
192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
196 * lpfc_serialnum_show - Return the hba serial number in ascii
197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
201 * Returns: size of formatted string.
204 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
207 struct Scsi_Host *shost = class_to_shost(dev);
208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
215 * lpfc_temp_sensor_show - Return the temperature sensor level
216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
224 * Returns: size of formatted string.
227 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
230 struct Scsi_Host *shost = class_to_shost(dev);
231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
237 * lpfc_modeldesc_show - Return the model description of the hba
238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
242 * Returns: size of formatted string.
245 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
248 struct Scsi_Host *shost = class_to_shost(dev);
249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
256 * lpfc_modelname_show - Return the model name of the hba
257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
261 * Returns: size of formatted string.
264 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
267 struct Scsi_Host *shost = class_to_shost(dev);
268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
275 * lpfc_programtype_show - Return the program type of the hba
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
280 * Returns: size of formatted string.
283 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
286 struct Scsi_Host *shost = class_to_shost(dev);
287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
299 * Returns: size of formatted string.
302 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
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, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
313 * lpfc_vportnum_show - Return the port number in ascii of the hba
314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
318 * Returns: size of formatted string.
321 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
324 struct Scsi_Host *shost = class_to_shost(dev);
325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
332 * lpfc_fwrev_show - Return the firmware rev running in the hba
333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
337 * Returns: size of formatted string.
340 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
343 struct Scsi_Host *shost = class_to_shost(dev);
344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
348 lpfc_decode_firmware_rev(phba, fwrev, 1);
349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
353 * lpfc_hdw_show - Return the jedec information about the hba
354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
358 * Returns: size of formatted string.
361 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
364 struct Scsi_Host *shost = class_to_shost(dev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367 lpfc_vpd_t *vp = &phba->vpd;
369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
379 * Returns: size of formatted string.
382 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
385 struct Scsi_Host *shost = class_to_shost(dev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
393 * lpfc_state_show - Return the link state of the port
394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
399 * The switch statement has no default so zero will be returned.
401 * Returns: size of formatted string.
404 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
407 struct Scsi_Host *shost = class_to_shost(dev);
408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
414 case LPFC_WARM_START:
415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
423 len += snprintf(buf + len, PAGE_SIZE-len,
429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
431 switch (vport->port_state) {
432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
434 "Configuring Link\n");
438 case LPFC_FABRIC_CFG_LINK:
441 case LPFC_BUILD_DISC_LIST:
443 len += snprintf(buf + len, PAGE_SIZE - len,
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
454 case LPFC_VPORT_UNKNOWN:
455 len += snprintf(buf + len, PAGE_SIZE - len,
459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
463 if (vport->fc_flag & FC_PUBLIC_LOOP)
464 len += snprintf(buf + len, PAGE_SIZE-len,
467 len += snprintf(buf + len, PAGE_SIZE-len,
470 if (vport->fc_flag & FC_FABRIC)
471 len += snprintf(buf + len, PAGE_SIZE-len,
474 len += snprintf(buf + len, PAGE_SIZE-len,
483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
495 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
502 int status = -EINVAL;
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
527 * Returns: size of formatted string.
530 lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
533 struct Scsi_Host *shost = class_to_shost(dev);
534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
541 * lpfc_issue_lip - Misnomer, name carried over from long ago
542 * @shost: Scsi_Host pointer.
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
555 lpfc_issue_lip(struct Scsi_Host *shost)
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
592 lpfc_set_loopback_flag(phba);
593 if (mbxstatus != MBX_TIMEOUT)
594 mempool_free(pmboxq, phba->mbox_mem_pool);
596 if (mbxstatus == MBXERR_ERROR)
603 * lpfc_do_offline - Issues a mailbox command to bring the link down
604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
614 * -EIO error posting the event
618 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
627 init_completion(&online_compl);
628 lpfc_workq_post_event(phba, &status, &online_compl,
629 LPFC_EVT_OFFLINE_PREP);
630 wait_for_completion(&online_compl);
637 /* Wait a little for things to settle down, but not
638 * long enough for dev loss timeout to expire.
640 for (i = 0; i < psli->num_rings; i++) {
641 pring = &psli->ring[i];
642 while (pring->txcmplq_cnt) {
644 if (cnt++ > 500) { /* 5 secs */
645 lpfc_printf_log(phba,
646 KERN_WARNING, LOG_INIT,
647 "0466 Outstanding IO when "
648 "bringing Adapter offline\n");
654 init_completion(&online_compl);
655 lpfc_workq_post_event(phba, &status, &online_compl, type);
656 wait_for_completion(&online_compl);
665 * lpfc_selective_reset - Offline then onlines the port
666 * @phba: lpfc_hba pointer.
669 * If the port is configured to allow a reset then the hba is brought
670 * offline then online.
673 * Assumes any error from lpfc_do_offline() will be negative.
676 * lpfc_do_offline() return code if not zero
677 * -EIO reset not configured or error posting the event
681 lpfc_selective_reset(struct lpfc_hba *phba)
683 struct completion online_compl;
686 if (!phba->cfg_enable_hba_reset)
689 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
694 init_completion(&online_compl);
695 lpfc_workq_post_event(phba, &status, &online_compl,
697 wait_for_completion(&online_compl);
706 * lpfc_issue_reset - Selectively resets an adapter
707 * @dev: class device that is converted into a Scsi_host.
708 * @attr: device attribute, not used.
709 * @buf: containing the string "selective".
710 * @count: unused variable.
713 * If the buf contains the string "selective" then lpfc_selective_reset()
714 * is called to perform the reset.
717 * Assumes any error from lpfc_selective_reset() will be negative.
718 * If lpfc_selective_reset() returns zero then the length of the buffer
719 * is returned which indicates success
722 * -EINVAL if the buffer does not contain the string "selective"
723 * length of buf if lpfc-selective_reset() if the call succeeds
724 * return value of lpfc_selective_reset() if the call fails
727 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
728 const char *buf, size_t count)
730 struct Scsi_Host *shost = class_to_shost(dev);
731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
732 struct lpfc_hba *phba = vport->phba;
734 int status = -EINVAL;
736 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
737 status = lpfc_selective_reset(phba);
746 * lpfc_nport_evt_cnt_show - Return the number of nport events
747 * @dev: class device that is converted into a Scsi_host.
748 * @attr: device attribute, not used.
749 * @buf: on return contains the ascii number of nport events.
751 * Returns: size of formatted string.
754 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
757 struct Scsi_Host *shost = class_to_shost(dev);
758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 struct lpfc_hba *phba = vport->phba;
761 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
765 * lpfc_board_mode_show - Return the state of the board
766 * @dev: class device that is converted into a Scsi_host.
767 * @attr: device attribute, not used.
768 * @buf: on return contains the state of the adapter.
770 * Returns: size of formatted string.
773 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
776 struct Scsi_Host *shost = class_to_shost(dev);
777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
778 struct lpfc_hba *phba = vport->phba;
781 if (phba->link_state == LPFC_HBA_ERROR)
783 else if (phba->link_state == LPFC_WARM_START)
784 state = "warm start";
785 else if (phba->link_state == LPFC_INIT_START)
790 return snprintf(buf, PAGE_SIZE, "%s\n", state);
794 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
795 * @dev: class device that is converted into a Scsi_host.
796 * @attr: device attribute, not used.
797 * @buf: containing one of the strings "online", "offline", "warm" or "error".
798 * @count: unused variable.
801 * -EACCES if enable hba reset not enabled
802 * -EINVAL if the buffer does not contain a valid string (see above)
803 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
804 * buf length greater than zero indicates success
807 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
808 const char *buf, size_t count)
810 struct Scsi_Host *shost = class_to_shost(dev);
811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
813 struct completion online_compl;
816 if (!phba->cfg_enable_hba_reset)
818 init_completion(&online_compl);
820 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
821 lpfc_workq_post_event(phba, &status, &online_compl,
823 wait_for_completion(&online_compl);
824 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
825 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
826 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
827 if (phba->sli_rev == LPFC_SLI_REV4)
830 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
831 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
832 if (phba->sli_rev == LPFC_SLI_REV4)
835 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
846 * lpfc_get_hba_info - Return various bits of informaton about the adapter
847 * @phba: pointer to the adapter structure.
848 * @mxri: max xri count.
849 * @axri: available xri count.
850 * @mrpi: max rpi count.
851 * @arpi: available rpi count.
852 * @mvpi: max vpi count.
853 * @avpi: available vpi count.
856 * If an integer pointer for an count is not null then the value for the
864 lpfc_get_hba_info(struct lpfc_hba *phba,
865 uint32_t *mxri, uint32_t *axri,
866 uint32_t *mrpi, uint32_t *arpi,
867 uint32_t *mvpi, uint32_t *avpi)
869 struct lpfc_mbx_read_config *rd_config;
870 LPFC_MBOXQ_t *pmboxq;
876 * prevent udev from issuing mailbox commands until the port is
879 if (phba->link_state < LPFC_LINK_DOWN ||
880 !phba->mbox_mem_pool ||
881 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
884 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
887 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
890 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
893 pmb->mbxCommand = MBX_READ_CONFIG;
894 pmb->mbxOwner = OWN_HOST;
895 pmboxq->context1 = NULL;
897 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
898 rc = MBX_NOT_FINISHED;
900 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
902 if (rc != MBX_SUCCESS) {
903 if (rc != MBX_TIMEOUT)
904 mempool_free(pmboxq, phba->mbox_mem_pool);
908 if (phba->sli_rev == LPFC_SLI_REV4) {
909 rd_config = &pmboxq->u.mqe.un.rd_config;
911 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
913 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
914 phba->sli4_hba.max_cfg_param.rpi_used;
916 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
918 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
919 phba->sli4_hba.max_cfg_param.xri_used;
921 /* Account for differences with SLI-3. Get vpi count from
922 * mailbox data and subtract one for max vpi value.
924 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
925 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
930 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
933 *mrpi = pmb->un.varRdConfig.max_rpi;
935 *arpi = pmb->un.varRdConfig.avail_rpi;
937 *mxri = pmb->un.varRdConfig.max_xri;
939 *axri = pmb->un.varRdConfig.avail_xri;
941 *mvpi = pmb->un.varRdConfig.max_vpi;
943 *avpi = pmb->un.varRdConfig.avail_vpi;
946 mempool_free(pmboxq, phba->mbox_mem_pool);
951 * lpfc_max_rpi_show - Return maximum rpi
952 * @dev: class device that is converted into a Scsi_host.
953 * @attr: device attribute, not used.
954 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
957 * Calls lpfc_get_hba_info() asking for just the mrpi count.
958 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
959 * to "Unknown" and the buffer length is returned, therefore the caller
960 * must check for "Unknown" in the buffer to detect a failure.
962 * Returns: size of formatted string.
965 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
968 struct Scsi_Host *shost = class_to_shost(dev);
969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
970 struct lpfc_hba *phba = vport->phba;
973 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
974 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
975 return snprintf(buf, PAGE_SIZE, "Unknown\n");
979 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
980 * @dev: class device that is converted into a Scsi_host.
981 * @attr: device attribute, not used.
982 * @buf: containing the used rpi count in decimal or "Unknown".
985 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
986 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
987 * to "Unknown" and the buffer length is returned, therefore the caller
988 * must check for "Unknown" in the buffer to detect a failure.
990 * Returns: size of formatted string.
993 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
996 struct Scsi_Host *shost = class_to_shost(dev);
997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
998 struct lpfc_hba *phba = vport->phba;
1001 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1002 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1003 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1007 * lpfc_max_xri_show - Return maximum xri
1008 * @dev: class device that is converted into a Scsi_host.
1009 * @attr: device attribute, not used.
1010 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1013 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1014 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1015 * to "Unknown" and the buffer length is returned, therefore the caller
1016 * must check for "Unknown" in the buffer to detect a failure.
1018 * Returns: size of formatted string.
1021 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1024 struct Scsi_Host *shost = class_to_shost(dev);
1025 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1026 struct lpfc_hba *phba = vport->phba;
1029 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1030 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1031 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1035 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1036 * @dev: class device that is converted into a Scsi_host.
1037 * @attr: device attribute, not used.
1038 * @buf: on return contains the used xri count in decimal or "Unknown".
1041 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1042 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1043 * to "Unknown" and the buffer length is returned, therefore the caller
1044 * must check for "Unknown" in the buffer to detect a failure.
1046 * Returns: size of formatted string.
1049 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1052 struct Scsi_Host *shost = class_to_shost(dev);
1053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1054 struct lpfc_hba *phba = vport->phba;
1057 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1058 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1059 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1063 * lpfc_max_vpi_show - Return maximum vpi
1064 * @dev: class device that is converted into a Scsi_host.
1065 * @attr: device attribute, not used.
1066 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1069 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1070 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1071 * to "Unknown" and the buffer length is returned, therefore the caller
1072 * must check for "Unknown" in the buffer to detect a failure.
1074 * Returns: size of formatted string.
1077 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1080 struct Scsi_Host *shost = class_to_shost(dev);
1081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1082 struct lpfc_hba *phba = vport->phba;
1085 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1086 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1087 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1091 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1092 * @dev: class device that is converted into a Scsi_host.
1093 * @attr: device attribute, not used.
1094 * @buf: on return contains the used vpi count in decimal or "Unknown".
1097 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1098 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1099 * to "Unknown" and the buffer length is returned, therefore the caller
1100 * must check for "Unknown" in the buffer to detect a failure.
1102 * Returns: size of formatted string.
1105 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1108 struct Scsi_Host *shost = class_to_shost(dev);
1109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1110 struct lpfc_hba *phba = vport->phba;
1113 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1114 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1115 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1119 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1120 * @dev: class device that is converted into a Scsi_host.
1121 * @attr: device attribute, not used.
1122 * @buf: text that must be interpreted to determine if npiv is supported.
1125 * Buffer will contain text indicating npiv is not suppoerted on the port,
1126 * the port is an NPIV physical port, or it is an npiv virtual port with
1127 * the id of the vport.
1129 * Returns: size of formatted string.
1132 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1135 struct Scsi_Host *shost = class_to_shost(dev);
1136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1137 struct lpfc_hba *phba = vport->phba;
1139 if (!(phba->max_vpi))
1140 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1141 if (vport->port_type == LPFC_PHYSICAL_PORT)
1142 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1143 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1147 * lpfc_poll_show - Return text about poll support for the adapter
1148 * @dev: class device that is converted into a Scsi_host.
1149 * @attr: device attribute, not used.
1150 * @buf: on return contains the cfg_poll in hex.
1153 * cfg_poll should be a lpfc_polling_flags type.
1155 * Returns: size of formatted string.
1158 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1161 struct Scsi_Host *shost = class_to_shost(dev);
1162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1163 struct lpfc_hba *phba = vport->phba;
1165 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1169 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1170 * @dev: class device that is converted into a Scsi_host.
1171 * @attr: device attribute, not used.
1172 * @buf: one or more lpfc_polling_flags values.
1176 * buf contents converted to integer and checked for a valid value.
1179 * -EINVAL if the buffer connot be converted or is out of range
1180 * length of the buf on success
1183 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1184 const char *buf, size_t count)
1186 struct Scsi_Host *shost = class_to_shost(dev);
1187 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1188 struct lpfc_hba *phba = vport->phba;
1193 if (!isdigit(buf[0]))
1196 if (sscanf(buf, "%i", &val) != 1)
1199 if ((val & 0x3) != val)
1202 if (phba->sli_rev == LPFC_SLI_REV4)
1205 spin_lock_irq(&phba->hbalock);
1207 old_val = phba->cfg_poll;
1209 if (val & ENABLE_FCP_RING_POLLING) {
1210 if ((val & DISABLE_FCP_RING_INT) &&
1211 !(old_val & DISABLE_FCP_RING_INT)) {
1212 creg_val = readl(phba->HCregaddr);
1213 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1214 writel(creg_val, phba->HCregaddr);
1215 readl(phba->HCregaddr); /* flush */
1217 lpfc_poll_start_timer(phba);
1219 } else if (val != 0x0) {
1220 spin_unlock_irq(&phba->hbalock);
1224 if (!(val & DISABLE_FCP_RING_INT) &&
1225 (old_val & DISABLE_FCP_RING_INT))
1227 spin_unlock_irq(&phba->hbalock);
1228 del_timer(&phba->fcp_poll_timer);
1229 spin_lock_irq(&phba->hbalock);
1230 creg_val = readl(phba->HCregaddr);
1231 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1232 writel(creg_val, phba->HCregaddr);
1233 readl(phba->HCregaddr); /* flush */
1236 phba->cfg_poll = val;
1238 spin_unlock_irq(&phba->hbalock);
1244 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1245 * @dev: class unused variable.
1246 * @attr: device attribute, not used.
1247 * @buf: on return contains the module description text.
1249 * Returns: size of formatted string.
1252 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1255 struct Scsi_Host *shost = class_to_shost(dev);
1256 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1257 struct lpfc_hba *phba = vport->phba;
1259 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1263 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1264 * @dev: class unused variable.
1265 * @attr: device attribute, not used.
1266 * @buf: on return contains the module description text.
1268 * Returns: size of formatted string.
1271 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1274 struct Scsi_Host *shost = class_to_shost(dev);
1275 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1276 struct lpfc_hba *phba = vport->phba;
1278 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1282 * lpfc_param_show - Return a cfg attribute value in decimal
1285 * Macro that given an attr e.g. hba_queue_depth expands
1286 * into a function with the name lpfc_hba_queue_depth_show.
1288 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1289 * @dev: class device that is converted into a Scsi_host.
1290 * @attr: device attribute, not used.
1291 * @buf: on return contains the attribute value in decimal.
1293 * Returns: size of formatted string.
1295 #define lpfc_param_show(attr) \
1297 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1300 struct Scsi_Host *shost = class_to_shost(dev);\
1301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1302 struct lpfc_hba *phba = vport->phba;\
1304 val = phba->cfg_##attr;\
1305 return snprintf(buf, PAGE_SIZE, "%d\n",\
1310 * lpfc_param_hex_show - Return a cfg attribute value in hex
1313 * Macro that given an attr e.g. hba_queue_depth expands
1314 * into a function with the name lpfc_hba_queue_depth_show
1316 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1317 * @dev: class device that is converted into a Scsi_host.
1318 * @attr: device attribute, not used.
1319 * @buf: on return contains the attribute value in hexadecimal.
1321 * Returns: size of formatted string.
1323 #define lpfc_param_hex_show(attr) \
1325 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1328 struct Scsi_Host *shost = class_to_shost(dev);\
1329 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1330 struct lpfc_hba *phba = vport->phba;\
1332 val = phba->cfg_##attr;\
1333 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1338 * lpfc_param_init - Initializes a cfg attribute
1341 * Macro that given an attr e.g. hba_queue_depth expands
1342 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1343 * takes a default argument, a minimum and maximum argument.
1345 * lpfc_##attr##_init: Initializes an attribute.
1346 * @phba: pointer the the adapter structure.
1347 * @val: integer attribute value.
1349 * Validates the min and max values then sets the adapter config field
1350 * accordingly, or uses the default if out of range and prints an error message.
1354 * -EINVAL if default used
1356 #define lpfc_param_init(attr, default, minval, maxval) \
1358 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1360 if (val >= minval && val <= maxval) {\
1361 phba->cfg_##attr = val;\
1364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1365 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1366 "allowed range is ["#minval", "#maxval"]\n", val); \
1367 phba->cfg_##attr = default;\
1372 * lpfc_param_set - Set a cfg attribute value
1375 * Macro that given an attr e.g. hba_queue_depth expands
1376 * into a function with the name lpfc_hba_queue_depth_set
1378 * lpfc_##attr##_set: Sets an attribute value.
1379 * @phba: pointer the the adapter structure.
1380 * @val: integer attribute value.
1383 * Validates the min and max values then sets the
1384 * adapter config field if in the valid range. prints error message
1385 * and does not set the parameter if invalid.
1389 * -EINVAL if val is invalid
1391 #define lpfc_param_set(attr, default, minval, maxval) \
1393 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1395 if (val >= minval && val <= maxval) {\
1396 phba->cfg_##attr = val;\
1399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1400 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1401 "allowed range is ["#minval", "#maxval"]\n", val); \
1406 * lpfc_param_store - Set a vport attribute value
1409 * Macro that given an attr e.g. hba_queue_depth expands
1410 * into a function with the name lpfc_hba_queue_depth_store.
1412 * lpfc_##attr##_store: Set an sttribute value.
1413 * @dev: class device that is converted into a Scsi_host.
1414 * @attr: device attribute, not used.
1415 * @buf: contains the attribute value in ascii.
1419 * Convert the ascii text number to an integer, then
1420 * use the lpfc_##attr##_set function to set the value.
1423 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1424 * length of buffer upon success.
1426 #define lpfc_param_store(attr) \
1428 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1429 const char *buf, size_t count) \
1431 struct Scsi_Host *shost = class_to_shost(dev);\
1432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1433 struct lpfc_hba *phba = vport->phba;\
1435 if (!isdigit(buf[0]))\
1437 if (sscanf(buf, "%i", &val) != 1)\
1439 if (lpfc_##attr##_set(phba, val) == 0) \
1440 return strlen(buf);\
1446 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1449 * Macro that given an attr e.g. hba_queue_depth expands
1450 * into a function with the name lpfc_hba_queue_depth_show
1452 * lpfc_##attr##_show: prints the attribute value in decimal.
1453 * @dev: class device that is converted into a Scsi_host.
1454 * @attr: device attribute, not used.
1455 * @buf: on return contains the attribute value in decimal.
1457 * Returns: length of formatted string.
1459 #define lpfc_vport_param_show(attr) \
1461 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1464 struct Scsi_Host *shost = class_to_shost(dev);\
1465 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1467 val = vport->cfg_##attr;\
1468 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1472 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1475 * Macro that given an attr e.g.
1476 * hba_queue_depth expands into a function with the name
1477 * lpfc_hba_queue_depth_show
1479 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1480 * @dev: class device that is converted into a Scsi_host.
1481 * @attr: device attribute, not used.
1482 * @buf: on return contains the attribute value in hexadecimal.
1484 * Returns: length of formatted string.
1486 #define lpfc_vport_param_hex_show(attr) \
1488 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1491 struct Scsi_Host *shost = class_to_shost(dev);\
1492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1494 val = vport->cfg_##attr;\
1495 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1499 * lpfc_vport_param_init - Initialize a vport cfg attribute
1502 * Macro that given an attr e.g. hba_queue_depth expands
1503 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1504 * takes a default argument, a minimum and maximum argument.
1506 * lpfc_##attr##_init: validates the min and max values then sets the
1507 * adapter config field accordingly, or uses the default if out of range
1508 * and prints an error message.
1509 * @phba: pointer the the adapter structure.
1510 * @val: integer attribute value.
1514 * -EINVAL if default used
1516 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1518 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1520 if (val >= minval && val <= maxval) {\
1521 vport->cfg_##attr = val;\
1524 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1525 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1526 "allowed range is ["#minval", "#maxval"]\n", val); \
1527 vport->cfg_##attr = default;\
1532 * lpfc_vport_param_set - Set a vport cfg attribute
1535 * Macro that given an attr e.g. hba_queue_depth expands
1536 * into a function with the name lpfc_hba_queue_depth_set
1538 * lpfc_##attr##_set: validates the min and max values then sets the
1539 * adapter config field if in the valid range. prints error message
1540 * and does not set the parameter if invalid.
1541 * @phba: pointer the the adapter structure.
1542 * @val: integer attribute value.
1546 * -EINVAL if val is invalid
1548 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1550 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1552 if (val >= minval && val <= maxval) {\
1553 vport->cfg_##attr = val;\
1556 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1557 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1558 "allowed range is ["#minval", "#maxval"]\n", val); \
1563 * lpfc_vport_param_store - Set a vport attribute
1566 * Macro that given an attr e.g. hba_queue_depth
1567 * expands into a function with the name lpfc_hba_queue_depth_store
1569 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1570 * use the lpfc_##attr##_set function to set the value.
1571 * @cdev: class device that is converted into a Scsi_host.
1572 * @buf: contains the attribute value in decimal.
1576 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1577 * length of buffer upon success.
1579 #define lpfc_vport_param_store(attr) \
1581 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1582 const char *buf, size_t count) \
1584 struct Scsi_Host *shost = class_to_shost(dev);\
1585 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1587 if (!isdigit(buf[0]))\
1589 if (sscanf(buf, "%i", &val) != 1)\
1591 if (lpfc_##attr##_set(vport, val) == 0) \
1592 return strlen(buf);\
1598 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1599 static uint lpfc_##name = defval;\
1600 module_param(lpfc_##name, uint, 0);\
1601 MODULE_PARM_DESC(lpfc_##name, desc);\
1602 lpfc_param_init(name, defval, minval, maxval)
1604 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1605 static uint lpfc_##name = defval;\
1606 module_param(lpfc_##name, uint, 0);\
1607 MODULE_PARM_DESC(lpfc_##name, desc);\
1608 lpfc_param_show(name)\
1609 lpfc_param_init(name, defval, minval, maxval)\
1610 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1612 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1613 static uint lpfc_##name = defval;\
1614 module_param(lpfc_##name, uint, 0);\
1615 MODULE_PARM_DESC(lpfc_##name, desc);\
1616 lpfc_param_show(name)\
1617 lpfc_param_init(name, defval, minval, maxval)\
1618 lpfc_param_set(name, defval, minval, maxval)\
1619 lpfc_param_store(name)\
1620 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1621 lpfc_##name##_show, lpfc_##name##_store)
1623 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1624 static uint lpfc_##name = defval;\
1625 module_param(lpfc_##name, uint, 0);\
1626 MODULE_PARM_DESC(lpfc_##name, desc);\
1627 lpfc_param_hex_show(name)\
1628 lpfc_param_init(name, defval, minval, maxval)\
1629 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1631 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1632 static uint lpfc_##name = defval;\
1633 module_param(lpfc_##name, uint, 0);\
1634 MODULE_PARM_DESC(lpfc_##name, desc);\
1635 lpfc_param_hex_show(name)\
1636 lpfc_param_init(name, defval, minval, maxval)\
1637 lpfc_param_set(name, defval, minval, maxval)\
1638 lpfc_param_store(name)\
1639 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1640 lpfc_##name##_show, lpfc_##name##_store)
1642 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1643 static uint lpfc_##name = defval;\
1644 module_param(lpfc_##name, uint, 0);\
1645 MODULE_PARM_DESC(lpfc_##name, desc);\
1646 lpfc_vport_param_init(name, defval, minval, maxval)
1648 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1649 static uint lpfc_##name = defval;\
1650 module_param(lpfc_##name, uint, 0);\
1651 MODULE_PARM_DESC(lpfc_##name, desc);\
1652 lpfc_vport_param_show(name)\
1653 lpfc_vport_param_init(name, defval, minval, maxval)\
1654 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1656 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1657 static uint lpfc_##name = defval;\
1658 module_param(lpfc_##name, uint, 0);\
1659 MODULE_PARM_DESC(lpfc_##name, desc);\
1660 lpfc_vport_param_show(name)\
1661 lpfc_vport_param_init(name, defval, minval, maxval)\
1662 lpfc_vport_param_set(name, defval, minval, maxval)\
1663 lpfc_vport_param_store(name)\
1664 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1665 lpfc_##name##_show, lpfc_##name##_store)
1667 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1668 static uint lpfc_##name = defval;\
1669 module_param(lpfc_##name, uint, 0);\
1670 MODULE_PARM_DESC(lpfc_##name, desc);\
1671 lpfc_vport_param_hex_show(name)\
1672 lpfc_vport_param_init(name, defval, minval, maxval)\
1673 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1675 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1676 static uint lpfc_##name = defval;\
1677 module_param(lpfc_##name, uint, 0);\
1678 MODULE_PARM_DESC(lpfc_##name, desc);\
1679 lpfc_vport_param_hex_show(name)\
1680 lpfc_vport_param_init(name, defval, minval, maxval)\
1681 lpfc_vport_param_set(name, defval, minval, maxval)\
1682 lpfc_vport_param_store(name)\
1683 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1684 lpfc_##name##_show, lpfc_##name##_store)
1686 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1687 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1688 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1689 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1690 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1691 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1692 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1693 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1694 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1695 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1696 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1697 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1698 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1699 lpfc_link_state_store);
1700 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1701 lpfc_option_rom_version_show, NULL);
1702 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1703 lpfc_num_discovered_ports_show, NULL);
1704 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1705 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1706 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1707 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1708 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1709 lpfc_board_mode_show, lpfc_board_mode_store);
1710 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1711 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1712 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1713 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1714 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1715 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1716 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1717 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1718 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1719 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1720 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1723 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1726 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1727 * @dev: class device that is converted into a Scsi_host.
1728 * @attr: device attribute, not used.
1729 * @buf: containing the string lpfc_soft_wwn_key.
1730 * @count: must be size of lpfc_soft_wwn_key.
1733 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1734 * length of buf indicates success
1737 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1738 const char *buf, size_t count)
1740 struct Scsi_Host *shost = class_to_shost(dev);
1741 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1742 struct lpfc_hba *phba = vport->phba;
1743 unsigned int cnt = count;
1746 * We're doing a simple sanity check for soft_wwpn setting.
1747 * We require that the user write a specific key to enable
1748 * the soft_wwpn attribute to be settable. Once the attribute
1749 * is written, the enable key resets. If further updates are
1750 * desired, the key must be written again to re-enable the
1753 * The "key" is not secret - it is a hardcoded string shown
1754 * here. The intent is to protect against the random user or
1755 * application that is just writing attributes.
1758 /* count may include a LF at end of string */
1759 if (buf[cnt-1] == '\n')
1762 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1763 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1766 phba->soft_wwn_enable = 1;
1769 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1770 lpfc_soft_wwn_enable_store);
1773 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1774 * @dev: class device that is converted into a Scsi_host.
1775 * @attr: device attribute, not used.
1776 * @buf: on return contains the wwpn in hexadecimal.
1778 * Returns: size of formatted string.
1781 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1784 struct Scsi_Host *shost = class_to_shost(dev);
1785 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1786 struct lpfc_hba *phba = vport->phba;
1788 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1789 (unsigned long long)phba->cfg_soft_wwpn);
1793 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1794 * @dev class device that is converted into a Scsi_host.
1795 * @attr: device attribute, not used.
1796 * @buf: contains the wwpn in hexadecimal.
1797 * @count: number of wwpn bytes in buf
1800 * -EACCES hba reset not enabled, adapter over temp
1801 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1802 * -EIO error taking adapter offline or online
1803 * value of count on success
1806 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1807 const char *buf, size_t count)
1809 struct Scsi_Host *shost = class_to_shost(dev);
1810 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1811 struct lpfc_hba *phba = vport->phba;
1812 struct completion online_compl;
1813 int stat1=0, stat2=0;
1814 unsigned int i, j, cnt=count;
1817 if (!phba->cfg_enable_hba_reset)
1819 spin_lock_irq(&phba->hbalock);
1820 if (phba->over_temp_state == HBA_OVER_TEMP) {
1821 spin_unlock_irq(&phba->hbalock);
1824 spin_unlock_irq(&phba->hbalock);
1825 /* count may include a LF at end of string */
1826 if (buf[cnt-1] == '\n')
1829 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1830 ((cnt == 17) && (*buf++ != 'x')) ||
1831 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1834 phba->soft_wwn_enable = 0;
1836 memset(wwpn, 0, sizeof(wwpn));
1838 /* Validate and store the new name */
1839 for (i=0, j=0; i < 16; i++) {
1842 value = hex_to_bin(*buf++);
1844 j = (j << 4) | value;
1848 wwpn[i/2] = j & 0xff;
1852 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1853 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1854 if (phba->cfg_soft_wwnn)
1855 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1857 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1858 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1860 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1863 "0463 lpfc_soft_wwpn attribute set failed to "
1864 "reinit adapter - %d\n", stat1);
1865 init_completion(&online_compl);
1866 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1867 wait_for_completion(&online_compl);
1869 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1870 "0464 lpfc_soft_wwpn attribute set failed to "
1871 "reinit adapter - %d\n", stat2);
1872 return (stat1 || stat2) ? -EIO : count;
1874 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1875 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1878 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1879 * @dev: class device that is converted into a Scsi_host.
1880 * @attr: device attribute, not used.
1881 * @buf: on return contains the wwnn in hexadecimal.
1883 * Returns: size of formatted string.
1886 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1889 struct Scsi_Host *shost = class_to_shost(dev);
1890 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1891 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1892 (unsigned long long)phba->cfg_soft_wwnn);
1896 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1897 * @cdev: class device that is converted into a Scsi_host.
1898 * @buf: contains the ww node name in hexadecimal.
1899 * @count: number of wwnn bytes in buf.
1902 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1903 * value of count on success
1906 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1907 const char *buf, size_t count)
1909 struct Scsi_Host *shost = class_to_shost(dev);
1910 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1911 unsigned int i, j, cnt=count;
1914 /* count may include a LF at end of string */
1915 if (buf[cnt-1] == '\n')
1918 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1919 ((cnt == 17) && (*buf++ != 'x')) ||
1920 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1924 * Allow wwnn to be set many times, as long as the enable is set.
1925 * However, once the wwpn is set, everything locks.
1928 memset(wwnn, 0, sizeof(wwnn));
1930 /* Validate and store the new name */
1931 for (i=0, j=0; i < 16; i++) {
1934 value = hex_to_bin(*buf++);
1936 j = (j << 4) | value;
1940 wwnn[i/2] = j & 0xff;
1944 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1946 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1947 "lpfc%d: soft_wwnn set. Value will take effect upon "
1948 "setting of the soft_wwpn\n", phba->brd_no);
1952 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1953 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1956 static int lpfc_poll = 0;
1957 module_param(lpfc_poll, int, 0);
1958 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1960 " 1 - poll with interrupts enabled"
1961 " 3 - poll and disable FCP ring interrupts");
1963 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1964 lpfc_poll_show, lpfc_poll_store);
1966 int lpfc_sli_mode = 0;
1967 module_param(lpfc_sli_mode, int, 0);
1968 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1969 " 0 - auto (SLI-3 if supported),"
1970 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1971 " 3 - select SLI-3");
1973 int lpfc_enable_npiv = 1;
1974 module_param(lpfc_enable_npiv, int, 0);
1975 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1976 lpfc_param_show(enable_npiv);
1977 lpfc_param_init(enable_npiv, 1, 0, 1);
1978 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
1980 int lpfc_enable_rrq;
1981 module_param(lpfc_enable_rrq, int, 0);
1982 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
1983 lpfc_param_show(enable_rrq);
1984 lpfc_param_init(enable_rrq, 0, 0, 1);
1985 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
1988 # lpfc_suppress_link_up: Bring link up at initialization
1989 # 0x0 = bring link up (issue MBX_INIT_LINK)
1990 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1991 # 0x2 = never bring up link
1992 # Default value is 0.
1994 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1995 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1996 "Suppress Link Up at initialization");
1998 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2006 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2008 struct Scsi_Host *shost = class_to_shost(dev);
2009 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2011 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2014 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2015 lpfc_iocb_hw_show, NULL);
2017 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2019 struct Scsi_Host *shost = class_to_shost(dev);
2020 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2022 return snprintf(buf, PAGE_SIZE, "%d\n",
2023 phba->sli.ring[LPFC_ELS_RING].txq_max);
2026 static DEVICE_ATTR(txq_hw, S_IRUGO,
2027 lpfc_txq_hw_show, NULL);
2029 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2032 struct Scsi_Host *shost = class_to_shost(dev);
2033 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2035 return snprintf(buf, PAGE_SIZE, "%d\n",
2036 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2039 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2040 lpfc_txcmplq_hw_show, NULL);
2042 int lpfc_iocb_cnt = 2;
2043 module_param(lpfc_iocb_cnt, int, 1);
2044 MODULE_PARM_DESC(lpfc_iocb_cnt,
2045 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2046 lpfc_param_show(iocb_cnt);
2047 lpfc_param_init(iocb_cnt, 2, 1, 5);
2048 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2049 lpfc_iocb_cnt_show, NULL);
2052 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2053 # until the timer expires. Value range is [0,255]. Default value is 30.
2055 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2056 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2057 module_param(lpfc_nodev_tmo, int, 0);
2058 MODULE_PARM_DESC(lpfc_nodev_tmo,
2059 "Seconds driver will hold I/O waiting "
2060 "for a device to come back");
2063 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2064 * @dev: class converted to a Scsi_host structure.
2065 * @attr: device attribute, not used.
2066 * @buf: on return contains the dev loss timeout in decimal.
2068 * Returns: size of formatted string.
2071 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2074 struct Scsi_Host *shost = class_to_shost(dev);
2075 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2077 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2081 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2082 * @vport: lpfc vport structure pointer.
2083 * @val: contains the nodev timeout value.
2086 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2087 * a kernel error message is printed and zero is returned.
2088 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2089 * Otherwise nodev tmo is set to the default value.
2092 * zero if already set or if val is in range
2093 * -EINVAL val out of range
2096 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2098 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2099 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2100 if (val != LPFC_DEF_DEVLOSS_TMO)
2101 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2102 "0407 Ignoring nodev_tmo module "
2103 "parameter because devloss_tmo is "
2108 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2109 vport->cfg_nodev_tmo = val;
2110 vport->cfg_devloss_tmo = val;
2113 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2114 "0400 lpfc_nodev_tmo attribute cannot be set to"
2115 " %d, allowed range is [%d, %d]\n",
2116 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2117 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2122 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2123 * @vport: lpfc vport structure pointer.
2126 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2129 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2131 struct Scsi_Host *shost;
2132 struct lpfc_nodelist *ndlp;
2134 shost = lpfc_shost_from_vport(vport);
2135 spin_lock_irq(shost->host_lock);
2136 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2137 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2138 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2139 spin_unlock_irq(shost->host_lock);
2143 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2144 * @vport: lpfc vport structure pointer.
2145 * @val: contains the tmo value.
2148 * If the devloss tmo is already set or the vport dev loss tmo has changed
2149 * then a kernel error message is printed and zero is returned.
2150 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2151 * Otherwise nodev tmo is set to the default value.
2154 * zero if already set or if val is in range
2155 * -EINVAL val out of range
2158 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2160 if (vport->dev_loss_tmo_changed ||
2161 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2162 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2163 "0401 Ignoring change to nodev_tmo "
2164 "because devloss_tmo is set.\n");
2167 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2168 vport->cfg_nodev_tmo = val;
2169 vport->cfg_devloss_tmo = val;
2171 * For compat: set the fc_host dev loss so new rports
2172 * will get the value.
2174 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2175 lpfc_update_rport_devloss_tmo(vport);
2178 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2179 "0403 lpfc_nodev_tmo attribute cannot be set to"
2180 "%d, allowed range is [%d, %d]\n",
2181 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2185 lpfc_vport_param_store(nodev_tmo)
2187 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2188 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2191 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2192 # disappear until the timer expires. Value range is [0,255]. Default
2195 module_param(lpfc_devloss_tmo, int, 0);
2196 MODULE_PARM_DESC(lpfc_devloss_tmo,
2197 "Seconds driver will hold I/O waiting "
2198 "for a device to come back");
2199 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2200 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2201 lpfc_vport_param_show(devloss_tmo)
2204 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2205 * @vport: lpfc vport structure pointer.
2206 * @val: contains the tmo value.
2209 * If val is in a valid range then set the vport nodev tmo,
2210 * devloss tmo, also set the vport dev loss tmo changed flag.
2211 * Else a kernel error message is printed.
2214 * zero if val is in range
2215 * -EINVAL val out of range
2218 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2220 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2221 vport->cfg_nodev_tmo = val;
2222 vport->cfg_devloss_tmo = val;
2223 vport->dev_loss_tmo_changed = 1;
2224 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2225 lpfc_update_rport_devloss_tmo(vport);
2229 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2230 "0404 lpfc_devloss_tmo attribute cannot be set to"
2231 " %d, allowed range is [%d, %d]\n",
2232 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2236 lpfc_vport_param_store(devloss_tmo)
2237 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2238 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2241 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2242 # deluged with LOTS of information.
2243 # You can set a bit mask to record specific types of verbose messages:
2244 # See lpfc_logmsh.h for definitions.
2246 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2247 "Verbose logging bit-mask");
2250 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2251 # objects that have been registered with the nameserver after login.
2253 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2254 "Deregister nameserver objects before LOGO");
2257 # lun_queue_depth: This parameter is used to limit the number of outstanding
2258 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2260 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2261 "Max number of FCP commands we can queue to a specific LUN");
2264 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2265 # commands per target port. Value range is [10,65535]. Default value is 65535.
2267 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2268 "Max number of FCP commands we can queue to a specific target port");
2271 # hba_queue_depth: This parameter is used to limit the number of outstanding
2272 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2273 # value is greater than the maximum number of exchanges supported by the HBA,
2274 # then maximum number of exchanges supported by the HBA is used to determine
2275 # the hba_queue_depth.
2277 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2278 "Max number of FCP commands we can queue to a lpfc HBA");
2281 # peer_port_login: This parameter allows/prevents logins
2282 # between peer ports hosted on the same physical port.
2283 # When this parameter is set 0 peer ports of same physical port
2284 # are not allowed to login to each other.
2285 # When this parameter is set 1 peer ports of same physical port
2286 # are allowed to login to each other.
2287 # Default value of this parameter is 0.
2289 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2290 "Allow peer ports on the same physical port to login to each "
2294 # restrict_login: This parameter allows/prevents logins
2295 # between Virtual Ports and remote initiators.
2296 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2297 # other initiators and will attempt to PLOGI all remote ports.
2298 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2299 # remote ports and will not attempt to PLOGI to other initiators.
2300 # This parameter does not restrict to the physical port.
2301 # This parameter does not restrict logins to Fabric resident remote ports.
2302 # Default value of this parameter is 1.
2304 static int lpfc_restrict_login = 1;
2305 module_param(lpfc_restrict_login, int, 0);
2306 MODULE_PARM_DESC(lpfc_restrict_login,
2307 "Restrict virtual ports login to remote initiators.");
2308 lpfc_vport_param_show(restrict_login);
2311 * lpfc_restrict_login_init - Set the vport restrict login flag
2312 * @vport: lpfc vport structure pointer.
2313 * @val: contains the restrict login value.
2316 * If val is not in a valid range then log a kernel error message and set
2317 * the vport restrict login to one.
2318 * If the port type is physical clear the restrict login flag and return.
2319 * Else set the restrict login flag to val.
2322 * zero if val is in range
2323 * -EINVAL val out of range
2326 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2328 if (val < 0 || val > 1) {
2329 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2330 "0422 lpfc_restrict_login attribute cannot "
2331 "be set to %d, allowed range is [0, 1]\n",
2333 vport->cfg_restrict_login = 1;
2336 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2337 vport->cfg_restrict_login = 0;
2340 vport->cfg_restrict_login = val;
2345 * lpfc_restrict_login_set - Set the vport restrict login flag
2346 * @vport: lpfc vport structure pointer.
2347 * @val: contains the restrict login value.
2350 * If val is not in a valid range then log a kernel error message and set
2351 * the vport restrict login to one.
2352 * If the port type is physical and the val is not zero log a kernel
2353 * error message, clear the restrict login flag and return zero.
2354 * Else set the restrict login flag to val.
2357 * zero if val is in range
2358 * -EINVAL val out of range
2361 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2363 if (val < 0 || val > 1) {
2364 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2365 "0425 lpfc_restrict_login attribute cannot "
2366 "be set to %d, allowed range is [0, 1]\n",
2368 vport->cfg_restrict_login = 1;
2371 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2372 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2373 "0468 lpfc_restrict_login must be 0 for "
2374 "Physical ports.\n");
2375 vport->cfg_restrict_login = 0;
2378 vport->cfg_restrict_login = val;
2381 lpfc_vport_param_store(restrict_login);
2382 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2383 lpfc_restrict_login_show, lpfc_restrict_login_store);
2386 # Some disk devices have a "select ID" or "select Target" capability.
2387 # From a protocol standpoint "select ID" usually means select the
2388 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2389 # annex" which contains a table that maps a "select ID" (a number
2390 # between 0 and 7F) to an ALPA. By default, for compatibility with
2391 # older drivers, the lpfc driver scans this table from low ALPA to high
2394 # Turning on the scan-down variable (on = 1, off = 0) will
2395 # cause the lpfc driver to use an inverted table, effectively
2396 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2398 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2399 # and will not work across a fabric. Also this parameter will take
2400 # effect only in the case when ALPA map is not available.)
2402 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2403 "Start scanning for devices from highest ALPA to lowest");
2406 # lpfc_topology: link topology for init link
2407 # 0x0 = attempt loop mode then point-to-point
2408 # 0x01 = internal loopback mode
2409 # 0x02 = attempt point-to-point mode only
2410 # 0x04 = attempt loop mode only
2411 # 0x06 = attempt point-to-point mode then loop
2412 # Set point-to-point mode if you want to run as an N_Port.
2413 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2414 # Default value is 0.
2418 * lpfc_topology_set - Set the adapters topology field
2419 * @phba: lpfc_hba pointer.
2420 * @val: topology value.
2423 * If val is in a valid range then set the adapter's topology field and
2424 * issue a lip; if the lip fails reset the topology to the old value.
2426 * If the value is not in range log a kernel error message and return an error.
2429 * zero if val is in range and lip okay
2430 * non-zero return value from lpfc_issue_lip()
2431 * -EINVAL val out of range
2434 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2435 const char *buf, size_t count)
2437 struct Scsi_Host *shost = class_to_shost(dev);
2438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2439 struct lpfc_hba *phba = vport->phba;
2442 const char *val_buf = buf;
2446 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2448 val_buf = &buf[strlen("nolip ")];
2451 if (!isdigit(val_buf[0]))
2453 if (sscanf(val_buf, "%i", &val) != 1)
2456 if (val >= 0 && val <= 6) {
2457 prev_val = phba->cfg_topology;
2458 phba->cfg_topology = val;
2462 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2464 phba->cfg_topology = prev_val;
2469 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2470 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2471 "allowed range is [0, 6]\n",
2475 static int lpfc_topology = 0;
2476 module_param(lpfc_topology, int, 0);
2477 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2478 lpfc_param_show(topology)
2479 lpfc_param_init(topology, 0, 0, 6)
2480 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2481 lpfc_topology_show, lpfc_topology_store);
2484 * lpfc_static_vport_show: Read callback function for
2485 * lpfc_static_vport sysfs file.
2486 * @dev: Pointer to class device object.
2487 * @attr: device attribute structure.
2488 * @buf: Data buffer.
2490 * This function is the read call back function for
2491 * lpfc_static_vport sysfs file. The lpfc_static_vport
2492 * sysfs file report the mageability of the vport.
2495 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2498 struct Scsi_Host *shost = class_to_shost(dev);
2499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2500 if (vport->vport_flag & STATIC_VPORT)
2501 sprintf(buf, "1\n");
2503 sprintf(buf, "0\n");
2509 * Sysfs attribute to control the statistical data collection.
2511 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2512 lpfc_static_vport_show, NULL);
2515 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2516 * @dev: Pointer to class device.
2517 * @buf: Data buffer.
2518 * @count: Size of the data buffer.
2520 * This function get called when an user write to the lpfc_stat_data_ctrl
2521 * sysfs file. This function parse the command written to the sysfs file
2522 * and take appropriate action. These commands are used for controlling
2523 * driver statistical data collection.
2524 * Following are the command this function handles.
2526 * setbucket <bucket_type> <base> <step>
2527 * = Set the latency buckets.
2528 * destroybucket = destroy all the buckets.
2529 * start = start data collection
2530 * stop = stop data collection
2531 * reset = reset the collected data
2534 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2535 const char *buf, size_t count)
2537 struct Scsi_Host *shost = class_to_shost(dev);
2538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2539 struct lpfc_hba *phba = vport->phba;
2540 #define LPFC_MAX_DATA_CTRL_LEN 1024
2541 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2543 char *str_ptr, *token;
2544 struct lpfc_vport **vports;
2545 struct Scsi_Host *v_shost;
2546 char *bucket_type_str, *base_str, *step_str;
2547 unsigned long base, step, bucket_type;
2549 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2550 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2553 strcpy(bucket_data, buf);
2554 str_ptr = &bucket_data[0];
2555 /* Ignore this token - this is command token */
2556 token = strsep(&str_ptr, "\t ");
2560 bucket_type_str = strsep(&str_ptr, "\t ");
2561 if (!bucket_type_str)
2564 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2565 bucket_type = LPFC_LINEAR_BUCKET;
2566 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2567 bucket_type = LPFC_POWER2_BUCKET;
2571 base_str = strsep(&str_ptr, "\t ");
2574 base = simple_strtoul(base_str, NULL, 0);
2576 step_str = strsep(&str_ptr, "\t ");
2579 step = simple_strtoul(step_str, NULL, 0);
2583 /* Block the data collection for every vport */
2584 vports = lpfc_create_vport_work_array(phba);
2588 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2589 v_shost = lpfc_shost_from_vport(vports[i]);
2590 spin_lock_irq(v_shost->host_lock);
2591 /* Block and reset data collection */
2592 vports[i]->stat_data_blocked = 1;
2593 if (vports[i]->stat_data_enabled)
2594 lpfc_vport_reset_stat_data(vports[i]);
2595 spin_unlock_irq(v_shost->host_lock);
2598 /* Set the bucket attributes */
2599 phba->bucket_type = bucket_type;
2600 phba->bucket_base = base;
2601 phba->bucket_step = step;
2603 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2604 v_shost = lpfc_shost_from_vport(vports[i]);
2606 /* Unblock data collection */
2607 spin_lock_irq(v_shost->host_lock);
2608 vports[i]->stat_data_blocked = 0;
2609 spin_unlock_irq(v_shost->host_lock);
2611 lpfc_destroy_vport_work_array(phba, vports);
2615 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2616 vports = lpfc_create_vport_work_array(phba);
2620 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2621 v_shost = lpfc_shost_from_vport(vports[i]);
2622 spin_lock_irq(shost->host_lock);
2623 vports[i]->stat_data_blocked = 1;
2624 lpfc_free_bucket(vport);
2625 vport->stat_data_enabled = 0;
2626 vports[i]->stat_data_blocked = 0;
2627 spin_unlock_irq(shost->host_lock);
2629 lpfc_destroy_vport_work_array(phba, vports);
2630 phba->bucket_type = LPFC_NO_BUCKET;
2631 phba->bucket_base = 0;
2632 phba->bucket_step = 0;
2636 if (!strncmp(buf, "start", strlen("start"))) {
2637 /* If no buckets configured return error */
2638 if (phba->bucket_type == LPFC_NO_BUCKET)
2640 spin_lock_irq(shost->host_lock);
2641 if (vport->stat_data_enabled) {
2642 spin_unlock_irq(shost->host_lock);
2645 lpfc_alloc_bucket(vport);
2646 vport->stat_data_enabled = 1;
2647 spin_unlock_irq(shost->host_lock);
2651 if (!strncmp(buf, "stop", strlen("stop"))) {
2652 spin_lock_irq(shost->host_lock);
2653 if (vport->stat_data_enabled == 0) {
2654 spin_unlock_irq(shost->host_lock);
2657 lpfc_free_bucket(vport);
2658 vport->stat_data_enabled = 0;
2659 spin_unlock_irq(shost->host_lock);
2663 if (!strncmp(buf, "reset", strlen("reset"))) {
2664 if ((phba->bucket_type == LPFC_NO_BUCKET)
2665 || !vport->stat_data_enabled)
2667 spin_lock_irq(shost->host_lock);
2668 vport->stat_data_blocked = 1;
2669 lpfc_vport_reset_stat_data(vport);
2670 vport->stat_data_blocked = 0;
2671 spin_unlock_irq(shost->host_lock);
2679 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2680 * @dev: Pointer to class device object.
2681 * @buf: Data buffer.
2683 * This function is the read call back function for
2684 * lpfc_stat_data_ctrl sysfs file. This function report the
2685 * current statistical data collection state.
2688 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2691 struct Scsi_Host *shost = class_to_shost(dev);
2692 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2693 struct lpfc_hba *phba = vport->phba;
2697 unsigned long bucket_value;
2699 switch (phba->bucket_type) {
2700 case LPFC_LINEAR_BUCKET:
2701 bucket_type = "linear";
2703 case LPFC_POWER2_BUCKET:
2704 bucket_type = "power2";
2707 bucket_type = "No Bucket";
2711 sprintf(&buf[index], "Statistical Data enabled :%d, "
2712 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2713 " Bucket step :%d\nLatency Ranges :",
2714 vport->stat_data_enabled, vport->stat_data_blocked,
2715 bucket_type, phba->bucket_base, phba->bucket_step);
2716 index = strlen(buf);
2717 if (phba->bucket_type != LPFC_NO_BUCKET) {
2718 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2719 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2720 bucket_value = phba->bucket_base +
2721 phba->bucket_step * i;
2723 bucket_value = phba->bucket_base +
2724 (1 << i) * phba->bucket_step;
2726 if (index + 10 > PAGE_SIZE)
2728 sprintf(&buf[index], "%08ld ", bucket_value);
2729 index = strlen(buf);
2732 sprintf(&buf[index], "\n");
2737 * Sysfs attribute to control the statistical data collection.
2739 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2740 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2743 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2747 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2750 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2751 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2752 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2756 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2758 * @kobj: Pointer to the kernel object
2759 * @bin_attr: Attribute object
2760 * @buff: Buffer pointer
2762 * @count: Buffer size
2764 * This function is the read call back function for lpfc_drvr_stat_data
2765 * sysfs file. This function export the statistical data to user
2769 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2770 struct bin_attribute *bin_attr,
2771 char *buf, loff_t off, size_t count)
2773 struct device *dev = container_of(kobj, struct device,
2775 struct Scsi_Host *shost = class_to_shost(dev);
2776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2777 struct lpfc_hba *phba = vport->phba;
2778 int i = 0, index = 0;
2779 unsigned long nport_index;
2780 struct lpfc_nodelist *ndlp = NULL;
2781 nport_index = (unsigned long)off /
2782 MAX_STAT_DATA_SIZE_PER_TARGET;
2784 if (!vport->stat_data_enabled || vport->stat_data_blocked
2785 || (phba->bucket_type == LPFC_NO_BUCKET))
2788 spin_lock_irq(shost->host_lock);
2789 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2790 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2793 if (nport_index > 0) {
2798 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2802 if (!ndlp->lat_data)
2806 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2807 ndlp->nlp_portname.u.wwn[0],
2808 ndlp->nlp_portname.u.wwn[1],
2809 ndlp->nlp_portname.u.wwn[2],
2810 ndlp->nlp_portname.u.wwn[3],
2811 ndlp->nlp_portname.u.wwn[4],
2812 ndlp->nlp_portname.u.wwn[5],
2813 ndlp->nlp_portname.u.wwn[6],
2814 ndlp->nlp_portname.u.wwn[7]);
2816 index = strlen(buf);
2818 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2819 sprintf(&buf[index], "%010u,",
2820 ndlp->lat_data[i].cmd_count);
2821 index = strlen(buf);
2823 sprintf(&buf[index], "\n");
2824 index = strlen(buf);
2826 spin_unlock_irq(shost->host_lock);
2830 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2832 .name = "lpfc_drvr_stat_data",
2835 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2836 .read = sysfs_drvr_stat_data_read,
2841 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2843 # Value range is [0,16]. Default value is 0.
2846 * lpfc_link_speed_set - Set the adapters link speed
2847 * @phba: lpfc_hba pointer.
2848 * @val: link speed value.
2851 * If val is in a valid range then set the adapter's link speed field and
2852 * issue a lip; if the lip fails reset the link speed to the old value.
2855 * If the value is not in range log a kernel error message and return an error.
2858 * zero if val is in range and lip okay.
2859 * non-zero return value from lpfc_issue_lip()
2860 * -EINVAL val out of range
2863 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2864 const char *buf, size_t count)
2866 struct Scsi_Host *shost = class_to_shost(dev);
2867 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2868 struct lpfc_hba *phba = vport->phba;
2869 int val = LPFC_USER_LINK_SPEED_AUTO;
2871 const char *val_buf = buf;
2875 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2877 val_buf = &buf[strlen("nolip ")];
2880 if (!isdigit(val_buf[0]))
2882 if (sscanf(val_buf, "%i", &val) != 1)
2885 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2886 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2887 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2888 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2889 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2890 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2892 "2879 lpfc_link_speed attribute cannot be set "
2893 "to %d. Speed is not supported by this port.\n",
2897 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2898 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2899 prev_val = phba->cfg_link_speed;
2900 phba->cfg_link_speed = val;
2904 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2906 phba->cfg_link_speed = prev_val;
2911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2912 "0469 lpfc_link_speed attribute cannot be set to %d, "
2913 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
2917 static int lpfc_link_speed = 0;
2918 module_param(lpfc_link_speed, int, 0);
2919 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2920 lpfc_param_show(link_speed)
2923 * lpfc_link_speed_init - Set the adapters link speed
2924 * @phba: lpfc_hba pointer.
2925 * @val: link speed value.
2928 * If val is in a valid range then set the adapter's link speed field.
2931 * If the value is not in range log a kernel error message, clear the link
2932 * speed and return an error.
2935 * zero if val saved.
2936 * -EINVAL val out of range
2939 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2941 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2942 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2943 phba->cfg_link_speed = val;
2946 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2947 "0405 lpfc_link_speed attribute cannot "
2948 "be set to %d, allowed values are "
2949 "["LPFC_LINK_SPEED_STRING"]\n", val);
2950 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
2954 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2955 lpfc_link_speed_show, lpfc_link_speed_store);
2958 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2959 # 0 = aer disabled or not supported
2960 # 1 = aer supported and enabled (default)
2961 # Value range is [0,1]. Default value is 1.
2965 * lpfc_aer_support_store - Set the adapter for aer support
2967 * @dev: class device that is converted into a Scsi_host.
2968 * @attr: device attribute, not used.
2969 * @buf: containing the string "selective".
2970 * @count: unused variable.
2973 * If the val is 1 and currently the device's AER capability was not
2974 * enabled, invoke the kernel's enable AER helper routine, trying to
2975 * enable the device's AER capability. If the helper routine enabling
2976 * AER returns success, update the device's cfg_aer_support flag to
2977 * indicate AER is supported by the device; otherwise, if the device
2978 * AER capability is already enabled to support AER, then do nothing.
2980 * If the val is 0 and currently the device's AER support was enabled,
2981 * invoke the kernel's disable AER helper routine. After that, update
2982 * the device's cfg_aer_support flag to indicate AER is not supported
2983 * by the device; otherwise, if the device AER capability is already
2984 * disabled from supporting AER, then do nothing.
2987 * length of the buf on success if val is in range the intended mode
2989 * -EINVAL if val out of range or intended mode is not supported.
2992 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2993 const char *buf, size_t count)
2995 struct Scsi_Host *shost = class_to_shost(dev);
2996 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2997 struct lpfc_hba *phba = vport->phba;
2998 int val = 0, rc = -EINVAL;
3000 if (!isdigit(buf[0]))
3002 if (sscanf(buf, "%i", &val) != 1)
3007 if (phba->hba_flag & HBA_AER_ENABLED) {
3008 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3010 spin_lock_irq(&phba->hbalock);
3011 phba->hba_flag &= ~HBA_AER_ENABLED;
3012 spin_unlock_irq(&phba->hbalock);
3013 phba->cfg_aer_support = 0;
3018 phba->cfg_aer_support = 0;
3023 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3024 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3026 spin_lock_irq(&phba->hbalock);
3027 phba->hba_flag |= HBA_AER_ENABLED;
3028 spin_unlock_irq(&phba->hbalock);
3029 phba->cfg_aer_support = 1;
3034 phba->cfg_aer_support = 1;
3045 static int lpfc_aer_support = 1;
3046 module_param(lpfc_aer_support, int, 1);
3047 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3048 lpfc_param_show(aer_support)
3051 * lpfc_aer_support_init - Set the initial adapters aer support flag
3052 * @phba: lpfc_hba pointer.
3053 * @val: link speed value.
3056 * If val is in a valid range [0,1], then set the adapter's initial
3057 * cfg_aer_support field. It will be up to the driver's probe_one
3058 * routine to determine whether the device's AER support can be set
3062 * If the value is not in range log a kernel error message, and
3063 * choose the default value of setting AER support and return.
3066 * zero if val saved.
3067 * -EINVAL val out of range
3070 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3072 if (val == 0 || val == 1) {
3073 phba->cfg_aer_support = val;
3076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3077 "2712 lpfc_aer_support attribute value %d out "
3078 "of range, allowed values are 0|1, setting it "
3079 "to default value of 1\n", val);
3080 /* By default, try to enable AER on a device */
3081 phba->cfg_aer_support = 1;
3085 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3086 lpfc_aer_support_show, lpfc_aer_support_store);
3089 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3090 * @dev: class device that is converted into a Scsi_host.
3091 * @attr: device attribute, not used.
3092 * @buf: containing the string "selective".
3093 * @count: unused variable.
3096 * If the @buf contains 1 and the device currently has the AER support
3097 * enabled, then invokes the kernel AER helper routine
3098 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3099 * error status register.
3104 * -EINVAL if the buf does not contain the 1 or the device is not currently
3105 * enabled with the AER support.
3108 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3109 const char *buf, size_t count)
3111 struct Scsi_Host *shost = class_to_shost(dev);
3112 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3113 struct lpfc_hba *phba = vport->phba;
3116 if (!isdigit(buf[0]))
3118 if (sscanf(buf, "%i", &val) != 1)
3123 if (phba->hba_flag & HBA_AER_ENABLED)
3124 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3132 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3133 lpfc_aer_cleanup_state);
3136 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3137 # Value range is [2,3]. Default value is 3.
3139 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3140 "Select Fibre Channel class of service for FCP sequences");
3143 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3144 # is [0,1]. Default value is 0.
3146 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3147 "Use ADISC on rediscovery to authenticate FCP devices");
3150 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3151 # depth. Default value is 0. When the value of this parameter is zero the
3152 # SCSI command completion time is not used for controlling I/O queue depth. When
3153 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3154 # to limit the I/O completion time to the parameter value.
3155 # The value is set in milliseconds.
3157 static int lpfc_max_scsicmpl_time;
3158 module_param(lpfc_max_scsicmpl_time, int, 0);
3159 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3160 "Use command completion time to control queue depth");
3161 lpfc_vport_param_show(max_scsicmpl_time);
3162 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3164 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3166 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3167 struct lpfc_nodelist *ndlp, *next_ndlp;
3169 if (val == vport->cfg_max_scsicmpl_time)
3171 if ((val < 0) || (val > 60000))
3173 vport->cfg_max_scsicmpl_time = val;
3175 spin_lock_irq(shost->host_lock);
3176 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3177 if (!NLP_CHK_NODE_ACT(ndlp))
3179 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3181 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3183 spin_unlock_irq(shost->host_lock);
3186 lpfc_vport_param_store(max_scsicmpl_time);
3187 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3188 lpfc_max_scsicmpl_time_show,
3189 lpfc_max_scsicmpl_time_store);
3192 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3193 # range is [0,1]. Default value is 0.
3195 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3198 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3199 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3200 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3201 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3202 # cr_delay is set to 0.
3204 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3205 "interrupt response is generated");
3207 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3208 "interrupt response is generated");
3211 # lpfc_multi_ring_support: Determines how many rings to spread available
3212 # cmd/rsp IOCB entries across.
3213 # Value range is [1,2]. Default value is 1.
3215 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3216 "SLI rings to spread IOCB entries across");
3219 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3220 # identifies what rctl value to configure the additional ring for.
3221 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3223 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3224 255, "Identifies RCTL for additional ring configuration");
3227 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3228 # identifies what type value to configure the additional ring for.
3229 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3231 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3232 255, "Identifies TYPE for additional ring configuration");
3235 # lpfc_fdmi_on: controls FDMI support.
3236 # 0 = no FDMI support
3237 # 1 = support FDMI without attribute of hostname
3238 # 2 = support FDMI with attribute of hostname
3239 # Value range [0,2]. Default value is 0.
3241 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3244 # Specifies the maximum number of ELS cmds we can have outstanding (for
3245 # discovery). Value range is [1,64]. Default value = 32.
3247 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3248 "during discovery");
3251 # lpfc_max_luns: maximum allowed LUN.
3252 # Value range is [0,65535]. Default value is 255.
3253 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3255 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3258 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3259 # Value range is [1,255], default value is 10.
3261 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3262 "Milliseconds driver will wait between polling FCP ring");
3265 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3266 # support this feature
3269 # 2 = MSI-X enabled (default)
3270 # Value range is [0,2]. Default value is 2.
3272 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3273 "MSI-X (2), if possible");
3276 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3278 # Value range is [636,651042]. Default value is 10000.
3280 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3281 "Set the maximum number of fast-path FCP interrupts per second");
3284 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3286 # Value range is [1,31]. Default value is 4.
3288 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3289 "Set the number of fast-path FCP work queues, if possible");
3292 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3294 # Value range is [1,7]. Default value is 1.
3296 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3297 "Set the number of fast-path FCP event queues, if possible");
3300 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3301 # 0 = HBA resets disabled
3302 # 1 = HBA resets enabled (default)
3303 # Value range is [0,1]. Default value is 1.
3305 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3308 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3309 # 0 = HBA Heartbeat disabled
3310 # 1 = HBA Heartbeat enabled (default)
3311 # Value range is [0,1]. Default value is 1.
3313 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3316 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3317 # 0 = BlockGuard disabled (default)
3318 # 1 = BlockGuard enabled
3319 # Value range is [0,1]. Default value is 0.
3321 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3325 # - Bit mask of host protection capabilities used to register with the
3327 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3328 # - Allows you to ultimately specify which profiles to use
3329 # - Default will result in registering capabilities for all profiles.
3332 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
3334 module_param(lpfc_prot_mask, uint, 0);
3335 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3338 # lpfc_prot_guard: i
3339 # - Bit mask of protection guard types to register with the SCSI mid-layer
3340 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3341 # - Allows you to ultimately specify which profiles to use
3342 # - Default will result in registering capabilities for all guard types
3345 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3346 module_param(lpfc_prot_guard, byte, 0);
3347 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3351 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3352 * This value can be set to values between 64 and 256. The default value is
3353 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3354 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3356 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3357 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3359 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3360 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3361 "Max Protection Scatter Gather Segment Count");
3363 struct device_attribute *lpfc_hba_attrs[] = {
3365 &dev_attr_bg_guard_err,
3366 &dev_attr_bg_apptag_err,
3367 &dev_attr_bg_reftag_err,
3369 &dev_attr_serialnum,
3370 &dev_attr_modeldesc,
3371 &dev_attr_modelname,
3372 &dev_attr_programtype,
3376 &dev_attr_option_rom_version,
3377 &dev_attr_link_state,
3378 &dev_attr_num_discovered_ports,
3379 &dev_attr_menlo_mgmt_mode,
3380 &dev_attr_lpfc_drvr_version,
3381 &dev_attr_lpfc_enable_fip,
3382 &dev_attr_lpfc_temp_sensor,
3383 &dev_attr_lpfc_log_verbose,
3384 &dev_attr_lpfc_lun_queue_depth,
3385 &dev_attr_lpfc_tgt_queue_depth,
3386 &dev_attr_lpfc_hba_queue_depth,
3387 &dev_attr_lpfc_peer_port_login,
3388 &dev_attr_lpfc_nodev_tmo,
3389 &dev_attr_lpfc_devloss_tmo,
3390 &dev_attr_lpfc_fcp_class,
3391 &dev_attr_lpfc_use_adisc,
3392 &dev_attr_lpfc_ack0,
3393 &dev_attr_lpfc_topology,
3394 &dev_attr_lpfc_scan_down,
3395 &dev_attr_lpfc_link_speed,
3396 &dev_attr_lpfc_cr_delay,
3397 &dev_attr_lpfc_cr_count,
3398 &dev_attr_lpfc_multi_ring_support,
3399 &dev_attr_lpfc_multi_ring_rctl,
3400 &dev_attr_lpfc_multi_ring_type,
3401 &dev_attr_lpfc_fdmi_on,
3402 &dev_attr_lpfc_max_luns,
3403 &dev_attr_lpfc_enable_npiv,
3404 &dev_attr_lpfc_enable_rrq,
3405 &dev_attr_nport_evt_cnt,
3406 &dev_attr_board_mode,
3413 &dev_attr_npiv_info,
3414 &dev_attr_issue_reset,
3415 &dev_attr_lpfc_poll,
3416 &dev_attr_lpfc_poll_tmo,
3417 &dev_attr_lpfc_use_msi,
3418 &dev_attr_lpfc_fcp_imax,
3419 &dev_attr_lpfc_fcp_wq_count,
3420 &dev_attr_lpfc_fcp_eq_count,
3421 &dev_attr_lpfc_enable_bg,
3422 &dev_attr_lpfc_soft_wwnn,
3423 &dev_attr_lpfc_soft_wwpn,
3424 &dev_attr_lpfc_soft_wwn_enable,
3425 &dev_attr_lpfc_enable_hba_reset,
3426 &dev_attr_lpfc_enable_hba_heartbeat,
3427 &dev_attr_lpfc_sg_seg_cnt,
3428 &dev_attr_lpfc_max_scsicmpl_time,
3429 &dev_attr_lpfc_stat_data_ctrl,
3430 &dev_attr_lpfc_prot_sg_seg_cnt,
3431 &dev_attr_lpfc_aer_support,
3432 &dev_attr_lpfc_aer_state_cleanup,
3433 &dev_attr_lpfc_suppress_link_up,
3434 &dev_attr_lpfc_iocb_cnt,
3437 &dev_attr_txcmplq_hw,
3438 &dev_attr_lpfc_fips_level,
3439 &dev_attr_lpfc_fips_rev,
3443 struct device_attribute *lpfc_vport_attrs[] = {
3445 &dev_attr_link_state,
3446 &dev_attr_num_discovered_ports,
3447 &dev_attr_lpfc_drvr_version,
3448 &dev_attr_lpfc_log_verbose,
3449 &dev_attr_lpfc_lun_queue_depth,
3450 &dev_attr_lpfc_tgt_queue_depth,
3451 &dev_attr_lpfc_nodev_tmo,
3452 &dev_attr_lpfc_devloss_tmo,
3453 &dev_attr_lpfc_hba_queue_depth,
3454 &dev_attr_lpfc_peer_port_login,
3455 &dev_attr_lpfc_restrict_login,
3456 &dev_attr_lpfc_fcp_class,
3457 &dev_attr_lpfc_use_adisc,
3458 &dev_attr_lpfc_fdmi_on,
3459 &dev_attr_lpfc_max_luns,
3460 &dev_attr_nport_evt_cnt,
3461 &dev_attr_npiv_info,
3462 &dev_attr_lpfc_enable_da_id,
3463 &dev_attr_lpfc_max_scsicmpl_time,
3464 &dev_attr_lpfc_stat_data_ctrl,
3465 &dev_attr_lpfc_static_vport,
3466 &dev_attr_lpfc_fips_level,
3467 &dev_attr_lpfc_fips_rev,
3472 * sysfs_ctlreg_write - Write method for writing to ctlreg
3473 * @filp: open sysfs file
3474 * @kobj: kernel kobject that contains the kernel class device.
3475 * @bin_attr: kernel attributes passed to us.
3476 * @buf: contains the data to be written to the adapter IOREG space.
3477 * @off: offset into buffer to beginning of data.
3478 * @count: bytes to transfer.
3481 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3482 * Uses the adapter io control registers to send buf contents to the adapter.
3485 * -ERANGE off and count combo out of range
3486 * -EINVAL off, count or buff address invalid
3487 * -EPERM adapter is offline
3488 * value of count, buf contents written
3491 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3492 struct bin_attribute *bin_attr,
3493 char *buf, loff_t off, size_t count)
3496 struct device *dev = container_of(kobj, struct device, kobj);
3497 struct Scsi_Host *shost = class_to_shost(dev);
3498 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3499 struct lpfc_hba *phba = vport->phba;
3501 if (phba->sli_rev >= LPFC_SLI_REV4)
3504 if ((off + count) > FF_REG_AREA_SIZE)
3507 if (count == 0) return 0;
3509 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3512 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3516 spin_lock_irq(&phba->hbalock);
3517 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3518 writel(*((uint32_t *)(buf + buf_off)),
3519 phba->ctrl_regs_memmap_p + off + buf_off);
3521 spin_unlock_irq(&phba->hbalock);
3527 * sysfs_ctlreg_read - Read method for reading from ctlreg
3528 * @filp: open sysfs file
3529 * @kobj: kernel kobject that contains the kernel class device.
3530 * @bin_attr: kernel attributes passed to us.
3531 * @buf: if successful contains the data from the adapter IOREG space.
3532 * @off: offset into buffer to beginning of data.
3533 * @count: bytes to transfer.
3536 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3537 * Uses the adapter io control registers to read data into buf.
3540 * -ERANGE off and count combo out of range
3541 * -EINVAL off, count or buff address invalid
3542 * value of count, buf contents read
3545 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3546 struct bin_attribute *bin_attr,
3547 char *buf, loff_t off, size_t count)
3551 struct device *dev = container_of(kobj, struct device, kobj);
3552 struct Scsi_Host *shost = class_to_shost(dev);
3553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3554 struct lpfc_hba *phba = vport->phba;
3556 if (phba->sli_rev >= LPFC_SLI_REV4)
3559 if (off > FF_REG_AREA_SIZE)
3562 if ((off + count) > FF_REG_AREA_SIZE)
3563 count = FF_REG_AREA_SIZE - off;
3565 if (count == 0) return 0;
3567 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3570 spin_lock_irq(&phba->hbalock);
3572 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3573 tmp_ptr = (uint32_t *)(buf + buf_off);
3574 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3577 spin_unlock_irq(&phba->hbalock);
3582 static struct bin_attribute sysfs_ctlreg_attr = {
3585 .mode = S_IRUSR | S_IWUSR,
3588 .read = sysfs_ctlreg_read,
3589 .write = sysfs_ctlreg_write,
3593 * sysfs_mbox_idle - frees the sysfs mailbox
3594 * @phba: lpfc_hba pointer
3597 sysfs_mbox_idle(struct lpfc_hba *phba)
3599 phba->sysfs_mbox.state = SMBOX_IDLE;
3600 phba->sysfs_mbox.offset = 0;
3602 if (phba->sysfs_mbox.mbox) {
3603 mempool_free(phba->sysfs_mbox.mbox,
3604 phba->mbox_mem_pool);
3605 phba->sysfs_mbox.mbox = NULL;
3610 * sysfs_mbox_write - Write method for writing information via mbox
3611 * @filp: open sysfs file
3612 * @kobj: kernel kobject that contains the kernel class device.
3613 * @bin_attr: kernel attributes passed to us.
3614 * @buf: contains the data to be written to sysfs mbox.
3615 * @off: offset into buffer to beginning of data.
3616 * @count: bytes to transfer.
3619 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3620 * Uses the sysfs mbox to send buf contents to the adapter.
3623 * -ERANGE off and count combo out of range
3624 * -EINVAL off, count or buff address invalid
3625 * zero if count is zero
3626 * -EPERM adapter is offline
3627 * -ENOMEM failed to allocate memory for the mail box
3628 * -EAGAIN offset, state or mbox is NULL
3629 * count number of bytes transferred
3632 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3633 struct bin_attribute *bin_attr,
3634 char *buf, loff_t off, size_t count)
3636 struct device *dev = container_of(kobj, struct device, kobj);
3637 struct Scsi_Host *shost = class_to_shost(dev);
3638 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3639 struct lpfc_hba *phba = vport->phba;
3640 struct lpfcMboxq *mbox = NULL;
3642 if ((count + off) > MAILBOX_CMD_SIZE)
3645 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3652 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3655 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3658 spin_lock_irq(&phba->hbalock);
3661 if (phba->sysfs_mbox.mbox)
3662 mempool_free(mbox, phba->mbox_mem_pool);
3664 phba->sysfs_mbox.mbox = mbox;
3665 phba->sysfs_mbox.state = SMBOX_WRITING;
3667 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3668 phba->sysfs_mbox.offset != off ||
3669 phba->sysfs_mbox.mbox == NULL) {
3670 sysfs_mbox_idle(phba);
3671 spin_unlock_irq(&phba->hbalock);
3676 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3679 phba->sysfs_mbox.offset = off + count;
3681 spin_unlock_irq(&phba->hbalock);
3687 * sysfs_mbox_read - Read method for reading information via mbox
3688 * @filp: open sysfs file
3689 * @kobj: kernel kobject that contains the kernel class device.
3690 * @bin_attr: kernel attributes passed to us.
3691 * @buf: contains the data to be read from sysfs mbox.
3692 * @off: offset into buffer to beginning of data.
3693 * @count: bytes to transfer.
3696 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3697 * Uses the sysfs mbox to receive data from to the adapter.
3700 * -ERANGE off greater than mailbox command size
3701 * -EINVAL off, count or buff address invalid
3702 * zero if off and count are zero
3703 * -EACCES adapter over temp
3704 * -EPERM garbage can value to catch a multitude of errors
3705 * -EAGAIN management IO not permitted, state or off error
3706 * -ETIME mailbox timeout
3707 * -ENODEV mailbox error
3708 * count number of bytes transferred
3711 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3712 struct bin_attribute *bin_attr,
3713 char *buf, loff_t off, size_t count)
3715 struct device *dev = container_of(kobj, struct device, kobj);
3716 struct Scsi_Host *shost = class_to_shost(dev);
3717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3718 struct lpfc_hba *phba = vport->phba;
3722 if (off > MAILBOX_CMD_SIZE)
3725 if ((count + off) > MAILBOX_CMD_SIZE)
3726 count = MAILBOX_CMD_SIZE - off;
3728 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3731 if (off && count == 0)
3734 spin_lock_irq(&phba->hbalock);
3736 if (phba->over_temp_state == HBA_OVER_TEMP) {
3737 sysfs_mbox_idle(phba);
3738 spin_unlock_irq(&phba->hbalock);
3743 phba->sysfs_mbox.state == SMBOX_WRITING &&
3744 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3745 pmb = &phba->sysfs_mbox.mbox->u.mb;
3746 switch (pmb->mbxCommand) {
3750 case MBX_CONFIG_LINK:
3751 case MBX_CONFIG_RING:
3752 case MBX_RESET_RING:
3753 case MBX_UNREG_LOGIN:
3755 case MBX_DUMP_CONTEXT:
3760 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3761 printk(KERN_WARNING "mbox_read:Command 0x%x "
3762 "is illegal in on-line state\n",
3764 sysfs_mbox_idle(phba);
3765 spin_unlock_irq(&phba->hbalock);
3769 case MBX_WRITE_VPARMS:
3772 case MBX_READ_CONFIG:
3773 case MBX_READ_RCONFIG:
3774 case MBX_READ_STATUS:
3777 case MBX_READ_LNK_STAT:
3778 case MBX_DUMP_MEMORY:
3780 case MBX_UPDATE_CFG:
3781 case MBX_KILL_BOARD:
3783 case MBX_LOAD_EXP_ROM:
3785 case MBX_DEL_LD_ENTRY:
3786 case MBX_SET_VARIABLE:
3788 case MBX_PORT_CAPABILITIES:
3789 case MBX_PORT_IOV_CONTROL:
3791 case MBX_SECURITY_MGMT:
3793 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3794 printk(KERN_WARNING "mbox_read:Command 0x%x "
3795 "is not permitted\n", pmb->mbxCommand);
3796 sysfs_mbox_idle(phba);
3797 spin_unlock_irq(&phba->hbalock);
3801 case MBX_READ_SPARM64:
3802 case MBX_READ_TOPOLOGY:
3804 case MBX_REG_LOGIN64:
3805 case MBX_CONFIG_PORT:
3806 case MBX_RUN_BIU_DIAG:
3807 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3809 sysfs_mbox_idle(phba);
3810 spin_unlock_irq(&phba->hbalock);
3813 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3815 sysfs_mbox_idle(phba);
3816 spin_unlock_irq(&phba->hbalock);
3820 /* If HBA encountered an error attention, allow only DUMP
3821 * or RESTART mailbox commands until the HBA is restarted.
3823 if (phba->pport->stopped &&
3824 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3825 pmb->mbxCommand != MBX_RESTART &&
3826 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3827 pmb->mbxCommand != MBX_WRITE_WWN)
3828 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3829 "1259 mbox: Issued mailbox cmd "
3830 "0x%x while in stopped state.\n",
3833 phba->sysfs_mbox.mbox->vport = vport;
3835 /* Don't allow mailbox commands to be sent when blocked
3836 * or when in the middle of discovery
3838 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3839 sysfs_mbox_idle(phba);
3840 spin_unlock_irq(&phba->hbalock);
3844 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3845 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3847 spin_unlock_irq(&phba->hbalock);
3848 rc = lpfc_sli_issue_mbox (phba,
3849 phba->sysfs_mbox.mbox,
3851 spin_lock_irq(&phba->hbalock);
3854 spin_unlock_irq(&phba->hbalock);
3855 rc = lpfc_sli_issue_mbox_wait (phba,
3856 phba->sysfs_mbox.mbox,
3857 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3858 spin_lock_irq(&phba->hbalock);
3861 if (rc != MBX_SUCCESS) {
3862 if (rc == MBX_TIMEOUT) {
3863 phba->sysfs_mbox.mbox = NULL;
3865 sysfs_mbox_idle(phba);
3866 spin_unlock_irq(&phba->hbalock);
3867 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3869 phba->sysfs_mbox.state = SMBOX_READING;
3871 else if (phba->sysfs_mbox.offset != off ||
3872 phba->sysfs_mbox.state != SMBOX_READING) {
3873 printk(KERN_WARNING "mbox_read: Bad State\n");
3874 sysfs_mbox_idle(phba);
3875 spin_unlock_irq(&phba->hbalock);
3879 memcpy(buf, (uint8_t *) &pmb + off, count);
3881 phba->sysfs_mbox.offset = off + count;
3883 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3884 sysfs_mbox_idle(phba);
3886 spin_unlock_irq(&phba->hbalock);
3891 static struct bin_attribute sysfs_mbox_attr = {
3894 .mode = S_IRUSR | S_IWUSR,
3896 .size = MAILBOX_CMD_SIZE,
3897 .read = sysfs_mbox_read,
3898 .write = sysfs_mbox_write,
3902 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3903 * @vport: address of lpfc vport structure.
3907 * error return code from sysfs_create_bin_file()
3910 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3912 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3915 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3916 &sysfs_drvr_stat_data_attr);
3918 /* Virtual ports do not need ctrl_reg and mbox */
3919 if (error || vport->port_type == LPFC_NPIV_PORT)
3922 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3923 &sysfs_ctlreg_attr);
3925 goto out_remove_stat_attr;
3927 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3930 goto out_remove_ctlreg_attr;
3933 out_remove_ctlreg_attr:
3934 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3935 out_remove_stat_attr:
3936 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3937 &sysfs_drvr_stat_data_attr);
3943 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
3944 * @vport: address of lpfc vport structure.
3947 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
3949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3950 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3951 &sysfs_drvr_stat_data_attr);
3952 /* Virtual ports do not need ctrl_reg and mbox */
3953 if (vport->port_type == LPFC_NPIV_PORT)
3955 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3956 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3961 * Dynamic FC Host Attributes Support
3965 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
3966 * @shost: kernel scsi host pointer.
3969 lpfc_get_host_port_id(struct Scsi_Host *shost)
3971 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3973 /* note: fc_myDID already in cpu endianness */
3974 fc_host_port_id(shost) = vport->fc_myDID;
3978 * lpfc_get_host_port_type - Set the value of the scsi host port type
3979 * @shost: kernel scsi host pointer.
3982 lpfc_get_host_port_type(struct Scsi_Host *shost)
3984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3985 struct lpfc_hba *phba = vport->phba;
3987 spin_lock_irq(shost->host_lock);
3989 if (vport->port_type == LPFC_NPIV_PORT) {
3990 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3991 } else if (lpfc_is_link_up(phba)) {
3992 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3993 if (vport->fc_flag & FC_PUBLIC_LOOP)
3994 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3996 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3998 if (vport->fc_flag & FC_FABRIC)
3999 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4001 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4004 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4006 spin_unlock_irq(shost->host_lock);
4010 * lpfc_get_host_port_state - Set the value of the scsi host port state
4011 * @shost: kernel scsi host pointer.
4014 lpfc_get_host_port_state(struct Scsi_Host *shost)
4016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4017 struct lpfc_hba *phba = vport->phba;
4019 spin_lock_irq(shost->host_lock);
4021 if (vport->fc_flag & FC_OFFLINE_MODE)
4022 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4024 switch (phba->link_state) {
4025 case LPFC_LINK_UNKNOWN:
4026 case LPFC_LINK_DOWN:
4027 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4031 case LPFC_HBA_READY:
4032 /* Links up, beyond this port_type reports state */
4033 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4035 case LPFC_HBA_ERROR:
4036 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4039 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4044 spin_unlock_irq(shost->host_lock);
4048 * lpfc_get_host_speed - Set the value of the scsi host speed
4049 * @shost: kernel scsi host pointer.
4052 lpfc_get_host_speed(struct Scsi_Host *shost)
4054 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4055 struct lpfc_hba *phba = vport->phba;
4057 spin_lock_irq(shost->host_lock);
4059 if (lpfc_is_link_up(phba)) {
4060 switch(phba->fc_linkspeed) {
4061 case LPFC_LINK_SPEED_1GHZ:
4062 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4064 case LPFC_LINK_SPEED_2GHZ:
4065 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4067 case LPFC_LINK_SPEED_4GHZ:
4068 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4070 case LPFC_LINK_SPEED_8GHZ:
4071 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4073 case LPFC_LINK_SPEED_10GHZ:
4074 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4076 case LPFC_LINK_SPEED_16GHZ:
4077 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4080 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4084 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4086 spin_unlock_irq(shost->host_lock);
4090 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4091 * @shost: kernel scsi host pointer.
4094 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4097 struct lpfc_hba *phba = vport->phba;
4100 spin_lock_irq(shost->host_lock);
4102 if ((vport->fc_flag & FC_FABRIC) ||
4103 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4104 (vport->fc_flag & FC_PUBLIC_LOOP)))
4105 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4107 /* fabric is local port if there is no F/FL_Port */
4110 spin_unlock_irq(shost->host_lock);
4112 fc_host_fabric_name(shost) = node_name;
4116 * lpfc_get_stats - Return statistical information about the adapter
4117 * @shost: kernel scsi host pointer.
4120 * NULL on error for link down, no mbox pool, sli2 active,
4121 * management not allowed, memory allocation error, or mbox error.
4125 * address of the adapter host statistics
4127 static struct fc_host_statistics *
4128 lpfc_get_stats(struct Scsi_Host *shost)
4130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4131 struct lpfc_hba *phba = vport->phba;
4132 struct lpfc_sli *psli = &phba->sli;
4133 struct fc_host_statistics *hs = &phba->link_stats;
4134 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4135 LPFC_MBOXQ_t *pmboxq;
4137 unsigned long seconds;
4141 * prevent udev from issuing mailbox commands until the port is
4144 if (phba->link_state < LPFC_LINK_DOWN ||
4145 !phba->mbox_mem_pool ||
4146 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4149 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4152 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4155 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4157 pmb = &pmboxq->u.mb;
4158 pmb->mbxCommand = MBX_READ_STATUS;
4159 pmb->mbxOwner = OWN_HOST;
4160 pmboxq->context1 = NULL;
4161 pmboxq->vport = vport;
4163 if (vport->fc_flag & FC_OFFLINE_MODE)
4164 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4166 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4168 if (rc != MBX_SUCCESS) {
4169 if (rc != MBX_TIMEOUT)
4170 mempool_free(pmboxq, phba->mbox_mem_pool);
4174 memset(hs, 0, sizeof (struct fc_host_statistics));
4176 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4177 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4178 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4179 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4181 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4182 pmb->mbxCommand = MBX_READ_LNK_STAT;
4183 pmb->mbxOwner = OWN_HOST;
4184 pmboxq->context1 = NULL;
4185 pmboxq->vport = vport;
4187 if (vport->fc_flag & FC_OFFLINE_MODE)
4188 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4190 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4192 if (rc != MBX_SUCCESS) {
4193 if (rc != MBX_TIMEOUT)
4194 mempool_free(pmboxq, phba->mbox_mem_pool);
4198 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4199 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4200 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4201 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4202 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4203 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4204 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4206 hs->link_failure_count -= lso->link_failure_count;
4207 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4208 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4209 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4210 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4211 hs->invalid_crc_count -= lso->invalid_crc_count;
4212 hs->error_frames -= lso->error_frames;
4214 if (phba->hba_flag & HBA_FCOE_MODE) {
4216 hs->nos_count = (phba->link_events >> 1);
4217 hs->nos_count -= lso->link_events;
4218 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4219 hs->lip_count = (phba->fc_eventTag >> 1);
4220 hs->lip_count -= lso->link_events;
4224 hs->nos_count = (phba->fc_eventTag >> 1);
4225 hs->nos_count -= lso->link_events;
4228 hs->dumped_frames = -1;
4230 seconds = get_seconds();
4231 if (seconds < psli->stats_start)
4232 hs->seconds_since_last_reset = seconds +
4233 ((unsigned long)-1 - psli->stats_start);
4235 hs->seconds_since_last_reset = seconds - psli->stats_start;
4237 mempool_free(pmboxq, phba->mbox_mem_pool);
4243 * lpfc_reset_stats - Copy the adapter link stats information
4244 * @shost: kernel scsi host pointer.
4247 lpfc_reset_stats(struct Scsi_Host *shost)
4249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4250 struct lpfc_hba *phba = vport->phba;
4251 struct lpfc_sli *psli = &phba->sli;
4252 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4253 LPFC_MBOXQ_t *pmboxq;
4257 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4260 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4263 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4265 pmb = &pmboxq->u.mb;
4266 pmb->mbxCommand = MBX_READ_STATUS;
4267 pmb->mbxOwner = OWN_HOST;
4268 pmb->un.varWords[0] = 0x1; /* reset request */
4269 pmboxq->context1 = NULL;
4270 pmboxq->vport = vport;
4272 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4273 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4274 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4276 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4278 if (rc != MBX_SUCCESS) {
4279 if (rc != MBX_TIMEOUT)
4280 mempool_free(pmboxq, phba->mbox_mem_pool);
4284 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4285 pmb->mbxCommand = MBX_READ_LNK_STAT;
4286 pmb->mbxOwner = OWN_HOST;
4287 pmboxq->context1 = NULL;
4288 pmboxq->vport = vport;
4290 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4291 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4292 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4294 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4296 if (rc != MBX_SUCCESS) {
4297 if (rc != MBX_TIMEOUT)
4298 mempool_free( pmboxq, phba->mbox_mem_pool);
4302 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4303 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4304 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4305 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4306 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4307 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4308 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4309 if (phba->hba_flag & HBA_FCOE_MODE)
4310 lso->link_events = (phba->link_events >> 1);
4312 lso->link_events = (phba->fc_eventTag >> 1);
4314 psli->stats_start = get_seconds();
4316 mempool_free(pmboxq, phba->mbox_mem_pool);
4322 * The LPFC driver treats linkdown handling as target loss events so there
4323 * are no sysfs handlers for link_down_tmo.
4327 * lpfc_get_node_by_target - Return the nodelist for a target
4328 * @starget: kernel scsi target pointer.
4331 * address of the node list if found
4332 * NULL target not found
4334 static struct lpfc_nodelist *
4335 lpfc_get_node_by_target(struct scsi_target *starget)
4337 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4339 struct lpfc_nodelist *ndlp;
4341 spin_lock_irq(shost->host_lock);
4342 /* Search for this, mapped, target ID */
4343 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4344 if (NLP_CHK_NODE_ACT(ndlp) &&
4345 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4346 starget->id == ndlp->nlp_sid) {
4347 spin_unlock_irq(shost->host_lock);
4351 spin_unlock_irq(shost->host_lock);
4356 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4357 * @starget: kernel scsi target pointer.
4360 lpfc_get_starget_port_id(struct scsi_target *starget)
4362 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4364 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4368 * lpfc_get_starget_node_name - Set the target node name
4369 * @starget: kernel scsi target pointer.
4371 * Description: Set the target node name to the ndlp node name wwn or zero.
4374 lpfc_get_starget_node_name(struct scsi_target *starget)
4376 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4378 fc_starget_node_name(starget) =
4379 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4383 * lpfc_get_starget_port_name - Set the target port name
4384 * @starget: kernel scsi target pointer.
4386 * Description: set the target port name to the ndlp port name wwn or zero.
4389 lpfc_get_starget_port_name(struct scsi_target *starget)
4391 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4393 fc_starget_port_name(starget) =
4394 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4398 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4399 * @rport: fc rport address.
4400 * @timeout: new value for dev loss tmo.
4403 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4404 * dev_loss_tmo to one.
4407 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4410 rport->dev_loss_tmo = timeout;
4412 rport->dev_loss_tmo = 1;
4416 * lpfc_rport_show_function - Return rport target information
4419 * Macro that uses field to generate a function with the name lpfc_show_rport_
4421 * lpfc_show_rport_##field: returns the bytes formatted in buf
4422 * @cdev: class converted to an fc_rport.
4423 * @buf: on return contains the target_field or zero.
4425 * Returns: size of formatted string.
4427 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4429 lpfc_show_rport_##field (struct device *dev, \
4430 struct device_attribute *attr, \
4433 struct fc_rport *rport = transport_class_to_rport(dev); \
4434 struct lpfc_rport_data *rdata = rport->hostdata; \
4435 return snprintf(buf, sz, format_string, \
4436 (rdata->target) ? cast rdata->target->field : 0); \
4439 #define lpfc_rport_rd_attr(field, format_string, sz) \
4440 lpfc_rport_show_function(field, format_string, sz, ) \
4441 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4444 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4445 * @fc_vport: The fc_vport who's symbolic name has been changed.
4448 * This function is called by the transport after the @fc_vport's symbolic name
4449 * has been changed. This function re-registers the symbolic name with the
4450 * switch to propogate the change into the fabric if the vport is active.
4453 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4455 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4457 if (vport->port_state == LPFC_VPORT_READY)
4458 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4462 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4463 * @phba: Pointer to lpfc_hba struct.
4465 * This function is called by the lpfc_get_cfgparam() routine to set the
4466 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4467 * log messsage according to the module's lpfc_log_verbose parameter setting
4468 * before hba port or vport created.
4471 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4473 phba->cfg_log_verbose = verbose;
4476 struct fc_function_template lpfc_transport_functions = {
4477 /* fixed attributes the driver supports */
4478 .show_host_node_name = 1,
4479 .show_host_port_name = 1,
4480 .show_host_supported_classes = 1,
4481 .show_host_supported_fc4s = 1,
4482 .show_host_supported_speeds = 1,
4483 .show_host_maxframe_size = 1,
4484 .show_host_symbolic_name = 1,
4486 /* dynamic attributes the driver supports */
4487 .get_host_port_id = lpfc_get_host_port_id,
4488 .show_host_port_id = 1,
4490 .get_host_port_type = lpfc_get_host_port_type,
4491 .show_host_port_type = 1,
4493 .get_host_port_state = lpfc_get_host_port_state,
4494 .show_host_port_state = 1,
4496 /* active_fc4s is shown but doesn't change (thus no get function) */
4497 .show_host_active_fc4s = 1,
4499 .get_host_speed = lpfc_get_host_speed,
4500 .show_host_speed = 1,
4502 .get_host_fabric_name = lpfc_get_host_fabric_name,
4503 .show_host_fabric_name = 1,
4506 * The LPFC driver treats linkdown handling as target loss events
4507 * so there are no sysfs handlers for link_down_tmo.
4510 .get_fc_host_stats = lpfc_get_stats,
4511 .reset_fc_host_stats = lpfc_reset_stats,
4513 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4514 .show_rport_maxframe_size = 1,
4515 .show_rport_supported_classes = 1,
4517 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4518 .show_rport_dev_loss_tmo = 1,
4520 .get_starget_port_id = lpfc_get_starget_port_id,
4521 .show_starget_port_id = 1,
4523 .get_starget_node_name = lpfc_get_starget_node_name,
4524 .show_starget_node_name = 1,
4526 .get_starget_port_name = lpfc_get_starget_port_name,
4527 .show_starget_port_name = 1,
4529 .issue_fc_host_lip = lpfc_issue_lip,
4530 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4531 .terminate_rport_io = lpfc_terminate_rport_io,
4533 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4535 .vport_disable = lpfc_vport_disable,
4537 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4539 .bsg_request = lpfc_bsg_request,
4540 .bsg_timeout = lpfc_bsg_timeout,
4543 struct fc_function_template lpfc_vport_transport_functions = {
4544 /* fixed attributes the driver supports */
4545 .show_host_node_name = 1,
4546 .show_host_port_name = 1,
4547 .show_host_supported_classes = 1,
4548 .show_host_supported_fc4s = 1,
4549 .show_host_supported_speeds = 1,
4550 .show_host_maxframe_size = 1,
4551 .show_host_symbolic_name = 1,
4553 /* dynamic attributes the driver supports */
4554 .get_host_port_id = lpfc_get_host_port_id,
4555 .show_host_port_id = 1,
4557 .get_host_port_type = lpfc_get_host_port_type,
4558 .show_host_port_type = 1,
4560 .get_host_port_state = lpfc_get_host_port_state,
4561 .show_host_port_state = 1,
4563 /* active_fc4s is shown but doesn't change (thus no get function) */
4564 .show_host_active_fc4s = 1,
4566 .get_host_speed = lpfc_get_host_speed,
4567 .show_host_speed = 1,
4569 .get_host_fabric_name = lpfc_get_host_fabric_name,
4570 .show_host_fabric_name = 1,
4573 * The LPFC driver treats linkdown handling as target loss events
4574 * so there are no sysfs handlers for link_down_tmo.
4577 .get_fc_host_stats = lpfc_get_stats,
4578 .reset_fc_host_stats = lpfc_reset_stats,
4580 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4581 .show_rport_maxframe_size = 1,
4582 .show_rport_supported_classes = 1,
4584 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4585 .show_rport_dev_loss_tmo = 1,
4587 .get_starget_port_id = lpfc_get_starget_port_id,
4588 .show_starget_port_id = 1,
4590 .get_starget_node_name = lpfc_get_starget_node_name,
4591 .show_starget_node_name = 1,
4593 .get_starget_port_name = lpfc_get_starget_port_name,
4594 .show_starget_port_name = 1,
4596 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4597 .terminate_rport_io = lpfc_terminate_rport_io,
4599 .vport_disable = lpfc_vport_disable,
4601 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4605 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4606 * @phba: lpfc_hba pointer.
4609 lpfc_get_cfgparam(struct lpfc_hba *phba)
4611 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4612 lpfc_cr_count_init(phba, lpfc_cr_count);
4613 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4614 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4615 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4616 lpfc_ack0_init(phba, lpfc_ack0);
4617 lpfc_topology_init(phba, lpfc_topology);
4618 lpfc_link_speed_init(phba, lpfc_link_speed);
4619 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4620 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4621 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4622 lpfc_use_msi_init(phba, lpfc_use_msi);
4623 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4624 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4625 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4626 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4627 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4628 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4629 if (phba->sli_rev == LPFC_SLI_REV4)
4632 phba->cfg_poll = lpfc_poll;
4633 phba->cfg_soft_wwnn = 0L;
4634 phba->cfg_soft_wwpn = 0L;
4635 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4636 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4637 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4638 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4639 lpfc_aer_support_init(phba, lpfc_aer_support);
4640 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4641 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
4646 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4647 * @vport: lpfc_vport pointer.
4650 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4652 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4653 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4654 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
4655 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4656 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4657 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4658 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4659 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4660 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4661 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4662 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4663 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4664 lpfc_max_luns_init(vport, lpfc_max_luns);
4665 lpfc_scan_down_init(vport, lpfc_scan_down);
4666 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);