1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/aer.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_tcq.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_version.h"
45 #include "lpfc_compat.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
49 #define LPFC_DEF_DEVLOSS_TMO 30
50 #define LPFC_MIN_DEVLOSS_TMO 1
51 #define LPFC_MAX_DEVLOSS_TMO 255
53 #define LPFC_MAX_LINK_SPEED 8
54 #define LPFC_LINK_SPEED_BITMAP 0x00000117
55 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
58 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
59 * @incr: integer to convert.
60 * @hdw: ascii string holding converted integer plus a string terminator.
63 * JEDEC Joint Electron Device Engineering Council.
64 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
65 * character string. The string is then terminated with a NULL in byte 9.
66 * Hex 0-9 becomes ascii '0' to '9'.
67 * Hex a-f becomes ascii '=' to 'B' capital B.
70 * Coded for 32 bit integers only.
73 lpfc_jedec_to_ascii(int incr, char hdw[])
76 for (i = 0; i < 8; i++) {
79 hdw[7 - i] = 0x30 + j;
81 hdw[7 - i] = 0x61 + j - 10;
89 * lpfc_drvr_version_show - Return the Emulex driver string with version number
90 * @dev: class unused variable.
91 * @attr: device attribute, not used.
92 * @buf: on return contains the module description text.
94 * Returns: size of formatted string.
97 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
100 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
104 * lpfc_enable_fip_show - Return the fip mode of the HBA
105 * @dev: class unused variable.
106 * @attr: device attribute, not used.
107 * @buf: on return contains the module description text.
109 * Returns: size of formatted string.
112 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
115 struct Scsi_Host *shost = class_to_shost(dev);
116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
117 struct lpfc_hba *phba = vport->phba;
119 if (phba->hba_flag & HBA_FIP_SUPPORT)
120 return snprintf(buf, PAGE_SIZE, "1\n");
122 return snprintf(buf, PAGE_SIZE, "0\n");
126 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
129 struct Scsi_Host *shost = class_to_shost(dev);
130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
131 struct lpfc_hba *phba = vport->phba;
133 if (phba->cfg_enable_bg)
134 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
135 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
137 return snprintf(buf, PAGE_SIZE,
138 "BlockGuard Not Supported\n");
140 return snprintf(buf, PAGE_SIZE,
141 "BlockGuard Disabled\n");
145 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
148 struct Scsi_Host *shost = class_to_shost(dev);
149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
150 struct lpfc_hba *phba = vport->phba;
152 return snprintf(buf, PAGE_SIZE, "%llu\n",
153 (unsigned long long)phba->bg_guard_err_cnt);
157 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
160 struct Scsi_Host *shost = class_to_shost(dev);
161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
162 struct lpfc_hba *phba = vport->phba;
164 return snprintf(buf, PAGE_SIZE, "%llu\n",
165 (unsigned long long)phba->bg_apptag_err_cnt);
169 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
172 struct Scsi_Host *shost = class_to_shost(dev);
173 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
174 struct lpfc_hba *phba = vport->phba;
176 return snprintf(buf, PAGE_SIZE, "%llu\n",
177 (unsigned long long)phba->bg_reftag_err_cnt);
181 * lpfc_info_show - Return some pci info about the host in ascii
182 * @dev: class converted to a Scsi_host structure.
183 * @attr: device attribute, not used.
184 * @buf: on return contains the formatted text from lpfc_info().
186 * Returns: size of formatted string.
189 lpfc_info_show(struct device *dev, struct device_attribute *attr,
192 struct Scsi_Host *host = class_to_shost(dev);
194 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
198 * lpfc_serialnum_show - Return the hba serial number in ascii
199 * @dev: class converted to a Scsi_host structure.
200 * @attr: device attribute, not used.
201 * @buf: on return contains the formatted text serial number.
203 * Returns: size of formatted string.
206 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
209 struct Scsi_Host *shost = class_to_shost(dev);
210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
211 struct lpfc_hba *phba = vport->phba;
213 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
217 * lpfc_temp_sensor_show - Return the temperature sensor level
218 * @dev: class converted to a Scsi_host structure.
219 * @attr: device attribute, not used.
220 * @buf: on return contains the formatted support level.
223 * Returns a number indicating the temperature sensor level currently
224 * supported, zero or one in ascii.
226 * Returns: size of formatted string.
229 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
232 struct Scsi_Host *shost = class_to_shost(dev);
233 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
234 struct lpfc_hba *phba = vport->phba;
235 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
239 * lpfc_modeldesc_show - Return the model description of the hba
240 * @dev: class converted to a Scsi_host structure.
241 * @attr: device attribute, not used.
242 * @buf: on return contains the scsi vpd model description.
244 * Returns: size of formatted string.
247 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
250 struct Scsi_Host *shost = class_to_shost(dev);
251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
252 struct lpfc_hba *phba = vport->phba;
254 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
258 * lpfc_modelname_show - Return the model name of the hba
259 * @dev: class converted to a Scsi_host structure.
260 * @attr: device attribute, not used.
261 * @buf: on return contains the scsi vpd model name.
263 * Returns: size of formatted string.
266 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
269 struct Scsi_Host *shost = class_to_shost(dev);
270 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
271 struct lpfc_hba *phba = vport->phba;
273 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
277 * lpfc_programtype_show - Return the program type of the hba
278 * @dev: class converted to a Scsi_host structure.
279 * @attr: device attribute, not used.
280 * @buf: on return contains the scsi vpd program type.
282 * Returns: size of formatted string.
285 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
288 struct Scsi_Host *shost = class_to_shost(dev);
289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
290 struct lpfc_hba *phba = vport->phba;
292 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
296 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
297 * @dev: class converted to a Scsi_host structure.
298 * @attr: device attribute, not used.
299 * @buf: on return contains the Menlo Maintenance sli flag.
301 * Returns: size of formatted string.
304 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
306 struct Scsi_Host *shost = class_to_shost(dev);
307 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
308 struct lpfc_hba *phba = vport->phba;
310 return snprintf(buf, PAGE_SIZE, "%d\n",
311 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
315 * lpfc_vportnum_show - Return the port number in ascii of the hba
316 * @dev: class converted to a Scsi_host structure.
317 * @attr: device attribute, not used.
318 * @buf: on return contains scsi vpd program type.
320 * Returns: size of formatted string.
323 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
326 struct Scsi_Host *shost = class_to_shost(dev);
327 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
328 struct lpfc_hba *phba = vport->phba;
330 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
334 * lpfc_fwrev_show - Return the firmware rev running in the hba
335 * @dev: class converted to a Scsi_host structure.
336 * @attr: device attribute, not used.
337 * @buf: on return contains the scsi vpd program type.
339 * Returns: size of formatted string.
342 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
345 struct Scsi_Host *shost = class_to_shost(dev);
346 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
347 struct lpfc_hba *phba = vport->phba;
350 lpfc_decode_firmware_rev(phba, fwrev, 1);
351 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
355 * lpfc_hdw_show - Return the jedec information about the hba
356 * @dev: class converted to a Scsi_host structure.
357 * @attr: device attribute, not used.
358 * @buf: on return contains the scsi vpd program type.
360 * Returns: size of formatted string.
363 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
366 struct Scsi_Host *shost = class_to_shost(dev);
367 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
368 struct lpfc_hba *phba = vport->phba;
369 lpfc_vpd_t *vp = &phba->vpd;
371 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
372 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
376 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
377 * @dev: class converted to a Scsi_host structure.
378 * @attr: device attribute, not used.
379 * @buf: on return contains the ROM and FCode ascii strings.
381 * Returns: size of formatted string.
384 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
387 struct Scsi_Host *shost = class_to_shost(dev);
388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
389 struct lpfc_hba *phba = vport->phba;
391 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
395 * lpfc_state_show - Return the link state of the port
396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains text describing the state of the link.
401 * The switch statement has no default so zero will be returned.
403 * Returns: size of formatted string.
406 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
409 struct Scsi_Host *shost = class_to_shost(dev);
410 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
411 struct lpfc_hba *phba = vport->phba;
414 switch (phba->link_state) {
415 case LPFC_LINK_UNKNOWN:
416 case LPFC_WARM_START:
417 case LPFC_INIT_START:
418 case LPFC_INIT_MBX_CMDS:
421 if (phba->hba_flag & LINK_DISABLED)
422 len += snprintf(buf + len, PAGE_SIZE-len,
423 "Link Down - User disabled\n");
425 len += snprintf(buf + len, PAGE_SIZE-len,
431 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
433 switch (vport->port_state) {
434 case LPFC_LOCAL_CFG_LINK:
435 len += snprintf(buf + len, PAGE_SIZE-len,
436 "Configuring Link\n");
440 case LPFC_FABRIC_CFG_LINK:
443 case LPFC_BUILD_DISC_LIST:
445 len += snprintf(buf + len, PAGE_SIZE - len,
448 case LPFC_VPORT_READY:
449 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
452 case LPFC_VPORT_FAILED:
453 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
456 case LPFC_VPORT_UNKNOWN:
457 len += snprintf(buf + len, PAGE_SIZE - len,
461 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
462 len += snprintf(buf + len, PAGE_SIZE-len,
463 " Menlo Maint Mode\n");
464 else if (phba->fc_topology == TOPOLOGY_LOOP) {
465 if (vport->fc_flag & FC_PUBLIC_LOOP)
466 len += snprintf(buf + len, PAGE_SIZE-len,
469 len += snprintf(buf + len, PAGE_SIZE-len,
472 if (vport->fc_flag & FC_FABRIC)
473 len += snprintf(buf + len, PAGE_SIZE-len,
476 len += snprintf(buf + len, PAGE_SIZE-len,
485 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
486 * @dev: class device that is converted into a Scsi_host.
487 * @attr: device attribute, not used.
488 * @buf: on return contains the sum of fc mapped and unmapped.
491 * Returns the ascii text number of the sum of the fc mapped and unmapped
494 * Returns: size of formatted string.
497 lpfc_num_discovered_ports_show(struct device *dev,
498 struct device_attribute *attr, char *buf)
500 struct Scsi_Host *shost = class_to_shost(dev);
501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 return snprintf(buf, PAGE_SIZE, "%d\n",
504 vport->fc_map_cnt + vport->fc_unmap_cnt);
508 * lpfc_issue_lip - Misnomer, name carried over from long ago
509 * @shost: Scsi_Host pointer.
512 * Bring the link down gracefully then re-init the link. The firmware will
513 * re-init the fiber channel interface as required. Does not issue a LIP.
516 * -EPERM port offline or management commands are being blocked
517 * -ENOMEM cannot allocate memory for the mailbox command
518 * -EIO error sending the mailbox command
522 lpfc_issue_lip(struct Scsi_Host *shost)
524 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
525 struct lpfc_hba *phba = vport->phba;
526 LPFC_MBOXQ_t *pmboxq;
527 int mbxstatus = MBXERR_ERROR;
529 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
530 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
533 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
538 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
539 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
540 pmboxq->u.mb.mbxOwner = OWN_HOST;
542 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
544 if ((mbxstatus == MBX_SUCCESS) &&
545 (pmboxq->u.mb.mbxStatus == 0 ||
546 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
547 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
548 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
549 phba->cfg_link_speed);
550 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
554 lpfc_set_loopback_flag(phba);
555 if (mbxstatus != MBX_TIMEOUT)
556 mempool_free(pmboxq, phba->mbox_mem_pool);
558 if (mbxstatus == MBXERR_ERROR)
565 * lpfc_do_offline - Issues a mailbox command to bring the link down
566 * @phba: lpfc_hba pointer.
567 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
570 * Assumes any error from lpfc_do_offline() will be negative.
571 * Can wait up to 5 seconds for the port ring buffers count
572 * to reach zero, prints a warning if it is not zero and continues.
573 * lpfc_workq_post_event() returns a non-zero return code if call fails.
576 * -EIO error posting the event
580 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
582 struct completion online_compl;
583 struct lpfc_sli_ring *pring;
584 struct lpfc_sli *psli;
589 init_completion(&online_compl);
590 lpfc_workq_post_event(phba, &status, &online_compl,
591 LPFC_EVT_OFFLINE_PREP);
592 wait_for_completion(&online_compl);
599 /* Wait a little for things to settle down, but not
600 * long enough for dev loss timeout to expire.
602 for (i = 0; i < psli->num_rings; i++) {
603 pring = &psli->ring[i];
604 while (pring->txcmplq_cnt) {
606 if (cnt++ > 500) { /* 5 secs */
607 lpfc_printf_log(phba,
608 KERN_WARNING, LOG_INIT,
609 "0466 Outstanding IO when "
610 "bringing Adapter offline\n");
616 init_completion(&online_compl);
617 lpfc_workq_post_event(phba, &status, &online_compl, type);
618 wait_for_completion(&online_compl);
627 * lpfc_selective_reset - Offline then onlines the port
628 * @phba: lpfc_hba pointer.
631 * If the port is configured to allow a reset then the hba is brought
632 * offline then online.
635 * Assumes any error from lpfc_do_offline() will be negative.
638 * lpfc_do_offline() return code if not zero
639 * -EIO reset not configured or error posting the event
643 lpfc_selective_reset(struct lpfc_hba *phba)
645 struct completion online_compl;
648 if (!phba->cfg_enable_hba_reset)
651 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
656 init_completion(&online_compl);
657 lpfc_workq_post_event(phba, &status, &online_compl,
659 wait_for_completion(&online_compl);
668 * lpfc_issue_reset - Selectively resets an adapter
669 * @dev: class device that is converted into a Scsi_host.
670 * @attr: device attribute, not used.
671 * @buf: containing the string "selective".
672 * @count: unused variable.
675 * If the buf contains the string "selective" then lpfc_selective_reset()
676 * is called to perform the reset.
679 * Assumes any error from lpfc_selective_reset() will be negative.
680 * If lpfc_selective_reset() returns zero then the length of the buffer
681 * is returned which indicates success
684 * -EINVAL if the buffer does not contain the string "selective"
685 * length of buf if lpfc-selective_reset() if the call succeeds
686 * return value of lpfc_selective_reset() if the call fails
689 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
690 const char *buf, size_t count)
692 struct Scsi_Host *shost = class_to_shost(dev);
693 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
694 struct lpfc_hba *phba = vport->phba;
696 int status = -EINVAL;
698 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
699 status = lpfc_selective_reset(phba);
708 * lpfc_nport_evt_cnt_show - Return the number of nport events
709 * @dev: class device that is converted into a Scsi_host.
710 * @attr: device attribute, not used.
711 * @buf: on return contains the ascii number of nport events.
713 * Returns: size of formatted string.
716 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
719 struct Scsi_Host *shost = class_to_shost(dev);
720 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
721 struct lpfc_hba *phba = vport->phba;
723 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
727 * lpfc_board_mode_show - Return the state of the board
728 * @dev: class device that is converted into a Scsi_host.
729 * @attr: device attribute, not used.
730 * @buf: on return contains the state of the adapter.
732 * Returns: size of formatted string.
735 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
738 struct Scsi_Host *shost = class_to_shost(dev);
739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
740 struct lpfc_hba *phba = vport->phba;
743 if (phba->link_state == LPFC_HBA_ERROR)
745 else if (phba->link_state == LPFC_WARM_START)
746 state = "warm start";
747 else if (phba->link_state == LPFC_INIT_START)
752 return snprintf(buf, PAGE_SIZE, "%s\n", state);
756 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
757 * @dev: class device that is converted into a Scsi_host.
758 * @attr: device attribute, not used.
759 * @buf: containing one of the strings "online", "offline", "warm" or "error".
760 * @count: unused variable.
763 * -EACCES if enable hba reset not enabled
764 * -EINVAL if the buffer does not contain a valid string (see above)
765 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
766 * buf length greater than zero indicates success
769 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
770 const char *buf, size_t count)
772 struct Scsi_Host *shost = class_to_shost(dev);
773 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
774 struct lpfc_hba *phba = vport->phba;
775 struct completion online_compl;
778 if (!phba->cfg_enable_hba_reset)
780 init_completion(&online_compl);
782 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
783 lpfc_workq_post_event(phba, &status, &online_compl,
785 wait_for_completion(&online_compl);
786 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
787 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
788 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
789 if (phba->sli_rev == LPFC_SLI_REV4)
792 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
793 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
794 if (phba->sli_rev == LPFC_SLI_REV4)
797 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
808 * lpfc_get_hba_info - Return various bits of informaton about the adapter
809 * @phba: pointer to the adapter structure.
810 * @mxri: max xri count.
811 * @axri: available xri count.
812 * @mrpi: max rpi count.
813 * @arpi: available rpi count.
814 * @mvpi: max vpi count.
815 * @avpi: available vpi count.
818 * If an integer pointer for an count is not null then the value for the
826 lpfc_get_hba_info(struct lpfc_hba *phba,
827 uint32_t *mxri, uint32_t *axri,
828 uint32_t *mrpi, uint32_t *arpi,
829 uint32_t *mvpi, uint32_t *avpi)
831 struct lpfc_sli *psli = &phba->sli;
832 struct lpfc_mbx_read_config *rd_config;
833 LPFC_MBOXQ_t *pmboxq;
838 * prevent udev from issuing mailbox commands until the port is
841 if (phba->link_state < LPFC_LINK_DOWN ||
842 !phba->mbox_mem_pool ||
843 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
846 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
849 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
852 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
855 pmb->mbxCommand = MBX_READ_CONFIG;
856 pmb->mbxOwner = OWN_HOST;
857 pmboxq->context1 = NULL;
859 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
860 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
861 rc = MBX_NOT_FINISHED;
863 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
865 if (rc != MBX_SUCCESS) {
866 if (rc != MBX_TIMEOUT)
867 mempool_free(pmboxq, phba->mbox_mem_pool);
871 if (phba->sli_rev == LPFC_SLI_REV4) {
872 rd_config = &pmboxq->u.mqe.un.rd_config;
874 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
876 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
877 phba->sli4_hba.max_cfg_param.rpi_used;
879 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
881 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
882 phba->sli4_hba.max_cfg_param.xri_used;
884 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
886 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
887 phba->sli4_hba.max_cfg_param.vpi_used;
890 *mrpi = pmb->un.varRdConfig.max_rpi;
892 *arpi = pmb->un.varRdConfig.avail_rpi;
894 *mxri = pmb->un.varRdConfig.max_xri;
896 *axri = pmb->un.varRdConfig.avail_xri;
898 *mvpi = pmb->un.varRdConfig.max_vpi;
900 *avpi = pmb->un.varRdConfig.avail_vpi;
903 mempool_free(pmboxq, phba->mbox_mem_pool);
908 * lpfc_max_rpi_show - Return maximum rpi
909 * @dev: class device that is converted into a Scsi_host.
910 * @attr: device attribute, not used.
911 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
914 * Calls lpfc_get_hba_info() asking for just the mrpi count.
915 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
916 * to "Unknown" and the buffer length is returned, therefore the caller
917 * must check for "Unknown" in the buffer to detect a failure.
919 * Returns: size of formatted string.
922 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
925 struct Scsi_Host *shost = class_to_shost(dev);
926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
927 struct lpfc_hba *phba = vport->phba;
930 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
931 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
932 return snprintf(buf, PAGE_SIZE, "Unknown\n");
936 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
937 * @dev: class device that is converted into a Scsi_host.
938 * @attr: device attribute, not used.
939 * @buf: containing the used rpi count in decimal or "Unknown".
942 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
943 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
944 * to "Unknown" and the buffer length is returned, therefore the caller
945 * must check for "Unknown" in the buffer to detect a failure.
947 * Returns: size of formatted string.
950 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
953 struct Scsi_Host *shost = class_to_shost(dev);
954 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
955 struct lpfc_hba *phba = vport->phba;
958 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
959 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
960 return snprintf(buf, PAGE_SIZE, "Unknown\n");
964 * lpfc_max_xri_show - Return maximum xri
965 * @dev: class device that is converted into a Scsi_host.
966 * @attr: device attribute, not used.
967 * @buf: on return contains the maximum xri count in decimal or "Unknown".
970 * Calls lpfc_get_hba_info() asking for just the mrpi count.
971 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
972 * to "Unknown" and the buffer length is returned, therefore the caller
973 * must check for "Unknown" in the buffer to detect a failure.
975 * Returns: size of formatted string.
978 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
981 struct Scsi_Host *shost = class_to_shost(dev);
982 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
983 struct lpfc_hba *phba = vport->phba;
986 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
987 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
988 return snprintf(buf, PAGE_SIZE, "Unknown\n");
992 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
993 * @dev: class device that is converted into a Scsi_host.
994 * @attr: device attribute, not used.
995 * @buf: on return contains the used xri count in decimal or "Unknown".
998 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
999 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1000 * to "Unknown" and the buffer length is returned, therefore the caller
1001 * must check for "Unknown" in the buffer to detect a failure.
1003 * Returns: size of formatted string.
1006 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1009 struct Scsi_Host *shost = class_to_shost(dev);
1010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1011 struct lpfc_hba *phba = vport->phba;
1014 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1015 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1016 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1020 * lpfc_max_vpi_show - Return maximum vpi
1021 * @dev: class device that is converted into a Scsi_host.
1022 * @attr: device attribute, not used.
1023 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1026 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1027 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1028 * to "Unknown" and the buffer length is returned, therefore the caller
1029 * must check for "Unknown" in the buffer to detect a failure.
1031 * Returns: size of formatted string.
1034 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1037 struct Scsi_Host *shost = class_to_shost(dev);
1038 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1039 struct lpfc_hba *phba = vport->phba;
1042 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1043 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1044 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1048 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1049 * @dev: class device that is converted into a Scsi_host.
1050 * @attr: device attribute, not used.
1051 * @buf: on return contains the used vpi count in decimal or "Unknown".
1054 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1055 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1056 * to "Unknown" and the buffer length is returned, therefore the caller
1057 * must check for "Unknown" in the buffer to detect a failure.
1059 * Returns: size of formatted string.
1062 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1065 struct Scsi_Host *shost = class_to_shost(dev);
1066 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1067 struct lpfc_hba *phba = vport->phba;
1070 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1071 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1072 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1076 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1077 * @dev: class device that is converted into a Scsi_host.
1078 * @attr: device attribute, not used.
1079 * @buf: text that must be interpreted to determine if npiv is supported.
1082 * Buffer will contain text indicating npiv is not suppoerted on the port,
1083 * the port is an NPIV physical port, or it is an npiv virtual port with
1084 * the id of the vport.
1086 * Returns: size of formatted string.
1089 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1092 struct Scsi_Host *shost = class_to_shost(dev);
1093 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1094 struct lpfc_hba *phba = vport->phba;
1096 if (!(phba->max_vpi))
1097 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1098 if (vport->port_type == LPFC_PHYSICAL_PORT)
1099 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1100 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1104 * lpfc_poll_show - Return text about poll support for the adapter
1105 * @dev: class device that is converted into a Scsi_host.
1106 * @attr: device attribute, not used.
1107 * @buf: on return contains the cfg_poll in hex.
1110 * cfg_poll should be a lpfc_polling_flags type.
1112 * Returns: size of formatted string.
1115 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1118 struct Scsi_Host *shost = class_to_shost(dev);
1119 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1120 struct lpfc_hba *phba = vport->phba;
1122 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1126 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1127 * @dev: class device that is converted into a Scsi_host.
1128 * @attr: device attribute, not used.
1129 * @buf: one or more lpfc_polling_flags values.
1133 * buf contents converted to integer and checked for a valid value.
1136 * -EINVAL if the buffer connot be converted or is out of range
1137 * length of the buf on success
1140 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1141 const char *buf, size_t count)
1143 struct Scsi_Host *shost = class_to_shost(dev);
1144 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1145 struct lpfc_hba *phba = vport->phba;
1150 if (!isdigit(buf[0]))
1153 if (sscanf(buf, "%i", &val) != 1)
1156 if ((val & 0x3) != val)
1159 if (phba->sli_rev == LPFC_SLI_REV4)
1162 spin_lock_irq(&phba->hbalock);
1164 old_val = phba->cfg_poll;
1166 if (val & ENABLE_FCP_RING_POLLING) {
1167 if ((val & DISABLE_FCP_RING_INT) &&
1168 !(old_val & DISABLE_FCP_RING_INT)) {
1169 creg_val = readl(phba->HCregaddr);
1170 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1171 writel(creg_val, phba->HCregaddr);
1172 readl(phba->HCregaddr); /* flush */
1174 lpfc_poll_start_timer(phba);
1176 } else if (val != 0x0) {
1177 spin_unlock_irq(&phba->hbalock);
1181 if (!(val & DISABLE_FCP_RING_INT) &&
1182 (old_val & DISABLE_FCP_RING_INT))
1184 spin_unlock_irq(&phba->hbalock);
1185 del_timer(&phba->fcp_poll_timer);
1186 spin_lock_irq(&phba->hbalock);
1187 creg_val = readl(phba->HCregaddr);
1188 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1189 writel(creg_val, phba->HCregaddr);
1190 readl(phba->HCregaddr); /* flush */
1193 phba->cfg_poll = val;
1195 spin_unlock_irq(&phba->hbalock);
1201 * lpfc_param_show - Return a cfg attribute value in decimal
1204 * Macro that given an attr e.g. hba_queue_depth expands
1205 * into a function with the name lpfc_hba_queue_depth_show.
1207 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1208 * @dev: class device that is converted into a Scsi_host.
1209 * @attr: device attribute, not used.
1210 * @buf: on return contains the attribute value in decimal.
1212 * Returns: size of formatted string.
1214 #define lpfc_param_show(attr) \
1216 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1219 struct Scsi_Host *shost = class_to_shost(dev);\
1220 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1221 struct lpfc_hba *phba = vport->phba;\
1223 val = phba->cfg_##attr;\
1224 return snprintf(buf, PAGE_SIZE, "%d\n",\
1229 * lpfc_param_hex_show - Return a cfg attribute value in hex
1232 * Macro that given an attr e.g. hba_queue_depth expands
1233 * into a function with the name lpfc_hba_queue_depth_show
1235 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1236 * @dev: class device that is converted into a Scsi_host.
1237 * @attr: device attribute, not used.
1238 * @buf: on return contains the attribute value in hexadecimal.
1240 * Returns: size of formatted string.
1242 #define lpfc_param_hex_show(attr) \
1244 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1247 struct Scsi_Host *shost = class_to_shost(dev);\
1248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1249 struct lpfc_hba *phba = vport->phba;\
1251 val = phba->cfg_##attr;\
1252 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1257 * lpfc_param_init - Intializes a cfg attribute
1260 * Macro that given an attr e.g. hba_queue_depth expands
1261 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1262 * takes a default argument, a minimum and maximum argument.
1264 * lpfc_##attr##_init: Initializes an attribute.
1265 * @phba: pointer the the adapter structure.
1266 * @val: integer attribute value.
1268 * Validates the min and max values then sets the adapter config field
1269 * accordingly, or uses the default if out of range and prints an error message.
1273 * -EINVAL if default used
1275 #define lpfc_param_init(attr, default, minval, maxval) \
1277 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1279 if (val >= minval && val <= maxval) {\
1280 phba->cfg_##attr = val;\
1283 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1284 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1285 "allowed range is ["#minval", "#maxval"]\n", val); \
1286 phba->cfg_##attr = default;\
1291 * lpfc_param_set - Set a cfg attribute value
1294 * Macro that given an attr e.g. hba_queue_depth expands
1295 * into a function with the name lpfc_hba_queue_depth_set
1297 * lpfc_##attr##_set: Sets an attribute value.
1298 * @phba: pointer the the adapter structure.
1299 * @val: integer attribute value.
1302 * Validates the min and max values then sets the
1303 * adapter config field if in the valid range. prints error message
1304 * and does not set the parameter if invalid.
1308 * -EINVAL if val is invalid
1310 #define lpfc_param_set(attr, default, minval, maxval) \
1312 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1314 if (val >= minval && val <= maxval) {\
1315 phba->cfg_##attr = val;\
1318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1319 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1320 "allowed range is ["#minval", "#maxval"]\n", val); \
1325 * lpfc_param_store - Set a vport attribute value
1328 * Macro that given an attr e.g. hba_queue_depth expands
1329 * into a function with the name lpfc_hba_queue_depth_store.
1331 * lpfc_##attr##_store: Set an sttribute value.
1332 * @dev: class device that is converted into a Scsi_host.
1333 * @attr: device attribute, not used.
1334 * @buf: contains the attribute value in ascii.
1338 * Convert the ascii text number to an integer, then
1339 * use the lpfc_##attr##_set function to set the value.
1342 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1343 * length of buffer upon success.
1345 #define lpfc_param_store(attr) \
1347 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1348 const char *buf, size_t count) \
1350 struct Scsi_Host *shost = class_to_shost(dev);\
1351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1352 struct lpfc_hba *phba = vport->phba;\
1354 if (!isdigit(buf[0]))\
1356 if (sscanf(buf, "%i", &val) != 1)\
1358 if (lpfc_##attr##_set(phba, val) == 0) \
1359 return strlen(buf);\
1365 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1368 * Macro that given an attr e.g. hba_queue_depth expands
1369 * into a function with the name lpfc_hba_queue_depth_show
1371 * lpfc_##attr##_show: prints the attribute value in decimal.
1372 * @dev: class device that is converted into a Scsi_host.
1373 * @attr: device attribute, not used.
1374 * @buf: on return contains the attribute value in decimal.
1376 * Returns: length of formatted string.
1378 #define lpfc_vport_param_show(attr) \
1380 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1383 struct Scsi_Host *shost = class_to_shost(dev);\
1384 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1386 val = vport->cfg_##attr;\
1387 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1391 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1394 * Macro that given an attr e.g.
1395 * hba_queue_depth expands into a function with the name
1396 * lpfc_hba_queue_depth_show
1398 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1399 * @dev: class device that is converted into a Scsi_host.
1400 * @attr: device attribute, not used.
1401 * @buf: on return contains the attribute value in hexadecimal.
1403 * Returns: length of formatted string.
1405 #define lpfc_vport_param_hex_show(attr) \
1407 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1410 struct Scsi_Host *shost = class_to_shost(dev);\
1411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1413 val = vport->cfg_##attr;\
1414 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1418 * lpfc_vport_param_init - Initialize a vport cfg attribute
1421 * Macro that given an attr e.g. hba_queue_depth expands
1422 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1423 * takes a default argument, a minimum and maximum argument.
1425 * lpfc_##attr##_init: validates the min and max values then sets the
1426 * adapter config field accordingly, or uses the default if out of range
1427 * and prints an error message.
1428 * @phba: pointer the the adapter structure.
1429 * @val: integer attribute value.
1433 * -EINVAL if default used
1435 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1437 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1439 if (val >= minval && val <= maxval) {\
1440 vport->cfg_##attr = val;\
1443 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1444 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1445 "allowed range is ["#minval", "#maxval"]\n", val); \
1446 vport->cfg_##attr = default;\
1451 * lpfc_vport_param_set - Set a vport cfg attribute
1454 * Macro that given an attr e.g. hba_queue_depth expands
1455 * into a function with the name lpfc_hba_queue_depth_set
1457 * lpfc_##attr##_set: validates the min and max values then sets the
1458 * adapter config field if in the valid range. prints error message
1459 * and does not set the parameter if invalid.
1460 * @phba: pointer the the adapter structure.
1461 * @val: integer attribute value.
1465 * -EINVAL if val is invalid
1467 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1469 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1471 if (val >= minval && val <= maxval) {\
1472 vport->cfg_##attr = val;\
1475 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1476 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1477 "allowed range is ["#minval", "#maxval"]\n", val); \
1482 * lpfc_vport_param_store - Set a vport attribute
1485 * Macro that given an attr e.g. hba_queue_depth
1486 * expands into a function with the name lpfc_hba_queue_depth_store
1488 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1489 * use the lpfc_##attr##_set function to set the value.
1490 * @cdev: class device that is converted into a Scsi_host.
1491 * @buf: contains the attribute value in decimal.
1495 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1496 * length of buffer upon success.
1498 #define lpfc_vport_param_store(attr) \
1500 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1501 const char *buf, size_t count) \
1503 struct Scsi_Host *shost = class_to_shost(dev);\
1504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1506 if (!isdigit(buf[0]))\
1508 if (sscanf(buf, "%i", &val) != 1)\
1510 if (lpfc_##attr##_set(vport, val) == 0) \
1511 return strlen(buf);\
1517 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1518 static int lpfc_##name = defval;\
1519 module_param(lpfc_##name, int, 0);\
1520 MODULE_PARM_DESC(lpfc_##name, desc);\
1521 lpfc_param_init(name, defval, minval, maxval)
1523 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1524 static int lpfc_##name = defval;\
1525 module_param(lpfc_##name, int, 0);\
1526 MODULE_PARM_DESC(lpfc_##name, desc);\
1527 lpfc_param_show(name)\
1528 lpfc_param_init(name, defval, minval, maxval)\
1529 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1531 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1532 static int lpfc_##name = defval;\
1533 module_param(lpfc_##name, int, 0);\
1534 MODULE_PARM_DESC(lpfc_##name, desc);\
1535 lpfc_param_show(name)\
1536 lpfc_param_init(name, defval, minval, maxval)\
1537 lpfc_param_set(name, defval, minval, maxval)\
1538 lpfc_param_store(name)\
1539 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1540 lpfc_##name##_show, lpfc_##name##_store)
1542 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1543 static int lpfc_##name = defval;\
1544 module_param(lpfc_##name, int, 0);\
1545 MODULE_PARM_DESC(lpfc_##name, desc);\
1546 lpfc_param_hex_show(name)\
1547 lpfc_param_init(name, defval, minval, maxval)\
1548 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1550 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1551 static int lpfc_##name = defval;\
1552 module_param(lpfc_##name, int, 0);\
1553 MODULE_PARM_DESC(lpfc_##name, desc);\
1554 lpfc_param_hex_show(name)\
1555 lpfc_param_init(name, defval, minval, maxval)\
1556 lpfc_param_set(name, defval, minval, maxval)\
1557 lpfc_param_store(name)\
1558 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1559 lpfc_##name##_show, lpfc_##name##_store)
1561 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1562 static int lpfc_##name = defval;\
1563 module_param(lpfc_##name, int, 0);\
1564 MODULE_PARM_DESC(lpfc_##name, desc);\
1565 lpfc_vport_param_init(name, defval, minval, maxval)
1567 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1568 static int lpfc_##name = defval;\
1569 module_param(lpfc_##name, int, 0);\
1570 MODULE_PARM_DESC(lpfc_##name, desc);\
1571 lpfc_vport_param_show(name)\
1572 lpfc_vport_param_init(name, defval, minval, maxval)\
1573 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1575 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1576 static int lpfc_##name = defval;\
1577 module_param(lpfc_##name, int, 0);\
1578 MODULE_PARM_DESC(lpfc_##name, desc);\
1579 lpfc_vport_param_show(name)\
1580 lpfc_vport_param_init(name, defval, minval, maxval)\
1581 lpfc_vport_param_set(name, defval, minval, maxval)\
1582 lpfc_vport_param_store(name)\
1583 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1584 lpfc_##name##_show, lpfc_##name##_store)
1586 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1587 static int lpfc_##name = defval;\
1588 module_param(lpfc_##name, int, 0);\
1589 MODULE_PARM_DESC(lpfc_##name, desc);\
1590 lpfc_vport_param_hex_show(name)\
1591 lpfc_vport_param_init(name, defval, minval, maxval)\
1592 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1594 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1595 static int lpfc_##name = defval;\
1596 module_param(lpfc_##name, int, 0);\
1597 MODULE_PARM_DESC(lpfc_##name, desc);\
1598 lpfc_vport_param_hex_show(name)\
1599 lpfc_vport_param_init(name, defval, minval, maxval)\
1600 lpfc_vport_param_set(name, defval, minval, maxval)\
1601 lpfc_vport_param_store(name)\
1602 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1603 lpfc_##name##_show, lpfc_##name##_store)
1605 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1606 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1607 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1608 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1609 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1610 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1611 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1612 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1613 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1614 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1615 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1616 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1617 static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
1618 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1619 lpfc_option_rom_version_show, NULL);
1620 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1621 lpfc_num_discovered_ports_show, NULL);
1622 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1623 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1624 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1625 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1626 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1627 lpfc_board_mode_show, lpfc_board_mode_store);
1628 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1629 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1630 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1631 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1632 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1633 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1634 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1635 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1636 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1639 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1642 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1643 * @dev: class device that is converted into a Scsi_host.
1644 * @attr: device attribute, not used.
1645 * @buf: containing the string lpfc_soft_wwn_key.
1646 * @count: must be size of lpfc_soft_wwn_key.
1649 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1650 * length of buf indicates success
1653 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1654 const char *buf, size_t count)
1656 struct Scsi_Host *shost = class_to_shost(dev);
1657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1658 struct lpfc_hba *phba = vport->phba;
1659 unsigned int cnt = count;
1662 * We're doing a simple sanity check for soft_wwpn setting.
1663 * We require that the user write a specific key to enable
1664 * the soft_wwpn attribute to be settable. Once the attribute
1665 * is written, the enable key resets. If further updates are
1666 * desired, the key must be written again to re-enable the
1669 * The "key" is not secret - it is a hardcoded string shown
1670 * here. The intent is to protect against the random user or
1671 * application that is just writing attributes.
1674 /* count may include a LF at end of string */
1675 if (buf[cnt-1] == '\n')
1678 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1679 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1682 phba->soft_wwn_enable = 1;
1685 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1686 lpfc_soft_wwn_enable_store);
1689 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1690 * @dev: class device that is converted into a Scsi_host.
1691 * @attr: device attribute, not used.
1692 * @buf: on return contains the wwpn in hexadecimal.
1694 * Returns: size of formatted string.
1697 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1700 struct Scsi_Host *shost = class_to_shost(dev);
1701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1702 struct lpfc_hba *phba = vport->phba;
1704 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1705 (unsigned long long)phba->cfg_soft_wwpn);
1709 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1710 * @dev class device that is converted into a Scsi_host.
1711 * @attr: device attribute, not used.
1712 * @buf: contains the wwpn in hexadecimal.
1713 * @count: number of wwpn bytes in buf
1716 * -EACCES hba reset not enabled, adapter over temp
1717 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1718 * -EIO error taking adapter offline or online
1719 * value of count on success
1722 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1723 const char *buf, size_t count)
1725 struct Scsi_Host *shost = class_to_shost(dev);
1726 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1727 struct lpfc_hba *phba = vport->phba;
1728 struct completion online_compl;
1729 int stat1=0, stat2=0;
1730 unsigned int i, j, cnt=count;
1733 if (!phba->cfg_enable_hba_reset)
1735 spin_lock_irq(&phba->hbalock);
1736 if (phba->over_temp_state == HBA_OVER_TEMP) {
1737 spin_unlock_irq(&phba->hbalock);
1740 spin_unlock_irq(&phba->hbalock);
1741 /* count may include a LF at end of string */
1742 if (buf[cnt-1] == '\n')
1745 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1746 ((cnt == 17) && (*buf++ != 'x')) ||
1747 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1750 phba->soft_wwn_enable = 0;
1752 memset(wwpn, 0, sizeof(wwpn));
1754 /* Validate and store the new name */
1755 for (i=0, j=0; i < 16; i++) {
1756 if ((*buf >= 'a') && (*buf <= 'f'))
1757 j = ((j << 4) | ((*buf++ -'a') + 10));
1758 else if ((*buf >= 'A') && (*buf <= 'F'))
1759 j = ((j << 4) | ((*buf++ -'A') + 10));
1760 else if ((*buf >= '0') && (*buf <= '9'))
1761 j = ((j << 4) | (*buf++ -'0'));
1765 wwpn[i/2] = j & 0xff;
1769 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1770 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1771 if (phba->cfg_soft_wwnn)
1772 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1774 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1775 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1777 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1779 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1780 "0463 lpfc_soft_wwpn attribute set failed to "
1781 "reinit adapter - %d\n", stat1);
1782 init_completion(&online_compl);
1783 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1784 wait_for_completion(&online_compl);
1786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1787 "0464 lpfc_soft_wwpn attribute set failed to "
1788 "reinit adapter - %d\n", stat2);
1789 return (stat1 || stat2) ? -EIO : count;
1791 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1792 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1795 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1796 * @dev: class device that is converted into a Scsi_host.
1797 * @attr: device attribute, not used.
1798 * @buf: on return contains the wwnn in hexadecimal.
1800 * Returns: size of formatted string.
1803 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1806 struct Scsi_Host *shost = class_to_shost(dev);
1807 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1808 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1809 (unsigned long long)phba->cfg_soft_wwnn);
1813 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1814 * @cdev: class device that is converted into a Scsi_host.
1815 * @buf: contains the ww node name in hexadecimal.
1816 * @count: number of wwnn bytes in buf.
1819 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1820 * value of count on success
1823 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1824 const char *buf, size_t count)
1826 struct Scsi_Host *shost = class_to_shost(dev);
1827 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1828 unsigned int i, j, cnt=count;
1831 /* count may include a LF at end of string */
1832 if (buf[cnt-1] == '\n')
1835 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1836 ((cnt == 17) && (*buf++ != 'x')) ||
1837 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1841 * Allow wwnn to be set many times, as long as the enable is set.
1842 * However, once the wwpn is set, everything locks.
1845 memset(wwnn, 0, sizeof(wwnn));
1847 /* Validate and store the new name */
1848 for (i=0, j=0; i < 16; i++) {
1849 if ((*buf >= 'a') && (*buf <= 'f'))
1850 j = ((j << 4) | ((*buf++ -'a') + 10));
1851 else if ((*buf >= 'A') && (*buf <= 'F'))
1852 j = ((j << 4) | ((*buf++ -'A') + 10));
1853 else if ((*buf >= '0') && (*buf <= '9'))
1854 j = ((j << 4) | (*buf++ -'0'));
1858 wwnn[i/2] = j & 0xff;
1862 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1864 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1865 "lpfc%d: soft_wwnn set. Value will take effect upon "
1866 "setting of the soft_wwpn\n", phba->brd_no);
1870 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1871 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1874 static int lpfc_poll = 0;
1875 module_param(lpfc_poll, int, 0);
1876 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1878 " 1 - poll with interrupts enabled"
1879 " 3 - poll and disable FCP ring interrupts");
1881 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1882 lpfc_poll_show, lpfc_poll_store);
1884 int lpfc_sli_mode = 0;
1885 module_param(lpfc_sli_mode, int, 0);
1886 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1887 " 0 - auto (SLI-3 if supported),"
1888 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1889 " 3 - select SLI-3");
1891 int lpfc_enable_npiv = 0;
1892 module_param(lpfc_enable_npiv, int, 0);
1893 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1894 lpfc_param_show(enable_npiv);
1895 lpfc_param_init(enable_npiv, 0, 0, 1);
1896 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1897 lpfc_enable_npiv_show, NULL);
1900 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1901 # until the timer expires. Value range is [0,255]. Default value is 30.
1903 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1904 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1905 module_param(lpfc_nodev_tmo, int, 0);
1906 MODULE_PARM_DESC(lpfc_nodev_tmo,
1907 "Seconds driver will hold I/O waiting "
1908 "for a device to come back");
1911 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
1912 * @dev: class converted to a Scsi_host structure.
1913 * @attr: device attribute, not used.
1914 * @buf: on return contains the dev loss timeout in decimal.
1916 * Returns: size of formatted string.
1919 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1922 struct Scsi_Host *shost = class_to_shost(dev);
1923 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1925 val = vport->cfg_devloss_tmo;
1926 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1930 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
1931 * @vport: lpfc vport structure pointer.
1932 * @val: contains the nodev timeout value.
1935 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1936 * a kernel error message is printed and zero is returned.
1937 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1938 * Otherwise nodev tmo is set to the default value.
1941 * zero if already set or if val is in range
1942 * -EINVAL val out of range
1945 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1947 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1948 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1949 if (val != LPFC_DEF_DEVLOSS_TMO)
1950 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1951 "0407 Ignoring nodev_tmo module "
1952 "parameter because devloss_tmo is "
1957 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1958 vport->cfg_nodev_tmo = val;
1959 vport->cfg_devloss_tmo = val;
1962 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1963 "0400 lpfc_nodev_tmo attribute cannot be set to"
1964 " %d, allowed range is [%d, %d]\n",
1965 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1966 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1971 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
1972 * @vport: lpfc vport structure pointer.
1975 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1978 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1980 struct Scsi_Host *shost;
1981 struct lpfc_nodelist *ndlp;
1983 shost = lpfc_shost_from_vport(vport);
1984 spin_lock_irq(shost->host_lock);
1985 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1986 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
1987 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1988 spin_unlock_irq(shost->host_lock);
1992 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
1993 * @vport: lpfc vport structure pointer.
1994 * @val: contains the tmo value.
1997 * If the devloss tmo is already set or the vport dev loss tmo has changed
1998 * then a kernel error message is printed and zero is returned.
1999 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2000 * Otherwise nodev tmo is set to the default value.
2003 * zero if already set or if val is in range
2004 * -EINVAL val out of range
2007 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2009 if (vport->dev_loss_tmo_changed ||
2010 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2011 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2012 "0401 Ignoring change to nodev_tmo "
2013 "because devloss_tmo is set.\n");
2016 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2017 vport->cfg_nodev_tmo = val;
2018 vport->cfg_devloss_tmo = val;
2019 lpfc_update_rport_devloss_tmo(vport);
2022 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2023 "0403 lpfc_nodev_tmo attribute cannot be set to"
2024 "%d, allowed range is [%d, %d]\n",
2025 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2029 lpfc_vport_param_store(nodev_tmo)
2031 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2032 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2035 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2036 # disappear until the timer expires. Value range is [0,255]. Default
2039 module_param(lpfc_devloss_tmo, int, 0);
2040 MODULE_PARM_DESC(lpfc_devloss_tmo,
2041 "Seconds driver will hold I/O waiting "
2042 "for a device to come back");
2043 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2044 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2045 lpfc_vport_param_show(devloss_tmo)
2048 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2049 * @vport: lpfc vport structure pointer.
2050 * @val: contains the tmo value.
2053 * If val is in a valid range then set the vport nodev tmo,
2054 * devloss tmo, also set the vport dev loss tmo changed flag.
2055 * Else a kernel error message is printed.
2058 * zero if val is in range
2059 * -EINVAL val out of range
2062 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2064 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2065 vport->cfg_nodev_tmo = val;
2066 vport->cfg_devloss_tmo = val;
2067 vport->dev_loss_tmo_changed = 1;
2068 lpfc_update_rport_devloss_tmo(vport);
2072 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2073 "0404 lpfc_devloss_tmo attribute cannot be set to"
2074 " %d, allowed range is [%d, %d]\n",
2075 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2079 lpfc_vport_param_store(devloss_tmo)
2080 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2081 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2084 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2085 # deluged with LOTS of information.
2086 # You can set a bit mask to record specific types of verbose messages:
2087 # See lpfc_logmsh.h for definitions.
2089 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2090 "Verbose logging bit-mask");
2093 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2094 # objects that have been registered with the nameserver after login.
2096 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2097 "Deregister nameserver objects before LOGO");
2100 # lun_queue_depth: This parameter is used to limit the number of outstanding
2101 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2103 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2104 "Max number of FCP commands we can queue to a specific LUN");
2107 # hba_queue_depth: This parameter is used to limit the number of outstanding
2108 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2109 # value is greater than the maximum number of exchanges supported by the HBA,
2110 # then maximum number of exchanges supported by the HBA is used to determine
2111 # the hba_queue_depth.
2113 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2114 "Max number of FCP commands we can queue to a lpfc HBA");
2117 # peer_port_login: This parameter allows/prevents logins
2118 # between peer ports hosted on the same physical port.
2119 # When this parameter is set 0 peer ports of same physical port
2120 # are not allowed to login to each other.
2121 # When this parameter is set 1 peer ports of same physical port
2122 # are allowed to login to each other.
2123 # Default value of this parameter is 0.
2125 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2126 "Allow peer ports on the same physical port to login to each "
2130 # restrict_login: This parameter allows/prevents logins
2131 # between Virtual Ports and remote initiators.
2132 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2133 # other initiators and will attempt to PLOGI all remote ports.
2134 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2135 # remote ports and will not attempt to PLOGI to other initiators.
2136 # This parameter does not restrict to the physical port.
2137 # This parameter does not restrict logins to Fabric resident remote ports.
2138 # Default value of this parameter is 1.
2140 static int lpfc_restrict_login = 1;
2141 module_param(lpfc_restrict_login, int, 0);
2142 MODULE_PARM_DESC(lpfc_restrict_login,
2143 "Restrict virtual ports login to remote initiators.");
2144 lpfc_vport_param_show(restrict_login);
2147 * lpfc_restrict_login_init - Set the vport restrict login flag
2148 * @vport: lpfc vport structure pointer.
2149 * @val: contains the restrict login value.
2152 * If val is not in a valid range then log a kernel error message and set
2153 * the vport restrict login to one.
2154 * If the port type is physical clear the restrict login flag and return.
2155 * Else set the restrict login flag to val.
2158 * zero if val is in range
2159 * -EINVAL val out of range
2162 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2164 if (val < 0 || val > 1) {
2165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2166 "0422 lpfc_restrict_login attribute cannot "
2167 "be set to %d, allowed range is [0, 1]\n",
2169 vport->cfg_restrict_login = 1;
2172 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2173 vport->cfg_restrict_login = 0;
2176 vport->cfg_restrict_login = val;
2181 * lpfc_restrict_login_set - Set the vport restrict login flag
2182 * @vport: lpfc vport structure pointer.
2183 * @val: contains the restrict login value.
2186 * If val is not in a valid range then log a kernel error message and set
2187 * the vport restrict login to one.
2188 * If the port type is physical and the val is not zero log a kernel
2189 * error message, clear the restrict login flag and return zero.
2190 * Else set the restrict login flag to val.
2193 * zero if val is in range
2194 * -EINVAL val out of range
2197 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2199 if (val < 0 || val > 1) {
2200 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2201 "0425 lpfc_restrict_login attribute cannot "
2202 "be set to %d, allowed range is [0, 1]\n",
2204 vport->cfg_restrict_login = 1;
2207 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2208 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2209 "0468 lpfc_restrict_login must be 0 for "
2210 "Physical ports.\n");
2211 vport->cfg_restrict_login = 0;
2214 vport->cfg_restrict_login = val;
2217 lpfc_vport_param_store(restrict_login);
2218 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2219 lpfc_restrict_login_show, lpfc_restrict_login_store);
2222 # Some disk devices have a "select ID" or "select Target" capability.
2223 # From a protocol standpoint "select ID" usually means select the
2224 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2225 # annex" which contains a table that maps a "select ID" (a number
2226 # between 0 and 7F) to an ALPA. By default, for compatibility with
2227 # older drivers, the lpfc driver scans this table from low ALPA to high
2230 # Turning on the scan-down variable (on = 1, off = 0) will
2231 # cause the lpfc driver to use an inverted table, effectively
2232 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2234 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2235 # and will not work across a fabric. Also this parameter will take
2236 # effect only in the case when ALPA map is not available.)
2238 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2239 "Start scanning for devices from highest ALPA to lowest");
2242 # lpfc_topology: link topology for init link
2243 # 0x0 = attempt loop mode then point-to-point
2244 # 0x01 = internal loopback mode
2245 # 0x02 = attempt point-to-point mode only
2246 # 0x04 = attempt loop mode only
2247 # 0x06 = attempt point-to-point mode then loop
2248 # Set point-to-point mode if you want to run as an N_Port.
2249 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2250 # Default value is 0.
2254 * lpfc_topology_set - Set the adapters topology field
2255 * @phba: lpfc_hba pointer.
2256 * @val: topology value.
2259 * If val is in a valid range then set the adapter's topology field and
2260 * issue a lip; if the lip fails reset the topology to the old value.
2262 * If the value is not in range log a kernel error message and return an error.
2265 * zero if val is in range and lip okay
2266 * non-zero return value from lpfc_issue_lip()
2267 * -EINVAL val out of range
2270 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2271 const char *buf, size_t count)
2273 struct Scsi_Host *shost = class_to_shost(dev);
2274 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2275 struct lpfc_hba *phba = vport->phba;
2278 const char *val_buf = buf;
2282 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2284 val_buf = &buf[strlen("nolip ")];
2287 if (!isdigit(val_buf[0]))
2289 if (sscanf(val_buf, "%i", &val) != 1)
2292 if (val >= 0 && val <= 6) {
2293 prev_val = phba->cfg_topology;
2294 phba->cfg_topology = val;
2298 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2300 phba->cfg_topology = prev_val;
2305 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2306 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2307 "allowed range is [0, 6]\n",
2311 static int lpfc_topology = 0;
2312 module_param(lpfc_topology, int, 0);
2313 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2314 lpfc_param_show(topology)
2315 lpfc_param_init(topology, 0, 0, 6)
2316 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2317 lpfc_topology_show, lpfc_topology_store);
2320 * lpfc_static_vport_show: Read callback function for
2321 * lpfc_static_vport sysfs file.
2322 * @dev: Pointer to class device object.
2323 * @attr: device attribute structure.
2324 * @buf: Data buffer.
2326 * This function is the read call back function for
2327 * lpfc_static_vport sysfs file. The lpfc_static_vport
2328 * sysfs file report the mageability of the vport.
2331 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2334 struct Scsi_Host *shost = class_to_shost(dev);
2335 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2336 if (vport->vport_flag & STATIC_VPORT)
2337 sprintf(buf, "1\n");
2339 sprintf(buf, "0\n");
2345 * Sysfs attribute to control the statistical data collection.
2347 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2348 lpfc_static_vport_show, NULL);
2351 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2352 * @dev: Pointer to class device.
2353 * @buf: Data buffer.
2354 * @count: Size of the data buffer.
2356 * This function get called when an user write to the lpfc_stat_data_ctrl
2357 * sysfs file. This function parse the command written to the sysfs file
2358 * and take appropriate action. These commands are used for controlling
2359 * driver statistical data collection.
2360 * Following are the command this function handles.
2362 * setbucket <bucket_type> <base> <step>
2363 * = Set the latency buckets.
2364 * destroybucket = destroy all the buckets.
2365 * start = start data collection
2366 * stop = stop data collection
2367 * reset = reset the collected data
2370 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2371 const char *buf, size_t count)
2373 struct Scsi_Host *shost = class_to_shost(dev);
2374 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2375 struct lpfc_hba *phba = vport->phba;
2376 #define LPFC_MAX_DATA_CTRL_LEN 1024
2377 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2379 char *str_ptr, *token;
2380 struct lpfc_vport **vports;
2381 struct Scsi_Host *v_shost;
2382 char *bucket_type_str, *base_str, *step_str;
2383 unsigned long base, step, bucket_type;
2385 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2386 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2389 strcpy(bucket_data, buf);
2390 str_ptr = &bucket_data[0];
2391 /* Ignore this token - this is command token */
2392 token = strsep(&str_ptr, "\t ");
2396 bucket_type_str = strsep(&str_ptr, "\t ");
2397 if (!bucket_type_str)
2400 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2401 bucket_type = LPFC_LINEAR_BUCKET;
2402 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2403 bucket_type = LPFC_POWER2_BUCKET;
2407 base_str = strsep(&str_ptr, "\t ");
2410 base = simple_strtoul(base_str, NULL, 0);
2412 step_str = strsep(&str_ptr, "\t ");
2415 step = simple_strtoul(step_str, NULL, 0);
2419 /* Block the data collection for every vport */
2420 vports = lpfc_create_vport_work_array(phba);
2424 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2425 v_shost = lpfc_shost_from_vport(vports[i]);
2426 spin_lock_irq(v_shost->host_lock);
2427 /* Block and reset data collection */
2428 vports[i]->stat_data_blocked = 1;
2429 if (vports[i]->stat_data_enabled)
2430 lpfc_vport_reset_stat_data(vports[i]);
2431 spin_unlock_irq(v_shost->host_lock);
2434 /* Set the bucket attributes */
2435 phba->bucket_type = bucket_type;
2436 phba->bucket_base = base;
2437 phba->bucket_step = step;
2439 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2440 v_shost = lpfc_shost_from_vport(vports[i]);
2442 /* Unblock data collection */
2443 spin_lock_irq(v_shost->host_lock);
2444 vports[i]->stat_data_blocked = 0;
2445 spin_unlock_irq(v_shost->host_lock);
2447 lpfc_destroy_vport_work_array(phba, vports);
2451 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2452 vports = lpfc_create_vport_work_array(phba);
2456 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2457 v_shost = lpfc_shost_from_vport(vports[i]);
2458 spin_lock_irq(shost->host_lock);
2459 vports[i]->stat_data_blocked = 1;
2460 lpfc_free_bucket(vport);
2461 vport->stat_data_enabled = 0;
2462 vports[i]->stat_data_blocked = 0;
2463 spin_unlock_irq(shost->host_lock);
2465 lpfc_destroy_vport_work_array(phba, vports);
2466 phba->bucket_type = LPFC_NO_BUCKET;
2467 phba->bucket_base = 0;
2468 phba->bucket_step = 0;
2472 if (!strncmp(buf, "start", strlen("start"))) {
2473 /* If no buckets configured return error */
2474 if (phba->bucket_type == LPFC_NO_BUCKET)
2476 spin_lock_irq(shost->host_lock);
2477 if (vport->stat_data_enabled) {
2478 spin_unlock_irq(shost->host_lock);
2481 lpfc_alloc_bucket(vport);
2482 vport->stat_data_enabled = 1;
2483 spin_unlock_irq(shost->host_lock);
2487 if (!strncmp(buf, "stop", strlen("stop"))) {
2488 spin_lock_irq(shost->host_lock);
2489 if (vport->stat_data_enabled == 0) {
2490 spin_unlock_irq(shost->host_lock);
2493 lpfc_free_bucket(vport);
2494 vport->stat_data_enabled = 0;
2495 spin_unlock_irq(shost->host_lock);
2499 if (!strncmp(buf, "reset", strlen("reset"))) {
2500 if ((phba->bucket_type == LPFC_NO_BUCKET)
2501 || !vport->stat_data_enabled)
2503 spin_lock_irq(shost->host_lock);
2504 vport->stat_data_blocked = 1;
2505 lpfc_vport_reset_stat_data(vport);
2506 vport->stat_data_blocked = 0;
2507 spin_unlock_irq(shost->host_lock);
2515 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2516 * @dev: Pointer to class device object.
2517 * @buf: Data buffer.
2519 * This function is the read call back function for
2520 * lpfc_stat_data_ctrl sysfs file. This function report the
2521 * current statistical data collection state.
2524 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2527 struct Scsi_Host *shost = class_to_shost(dev);
2528 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2529 struct lpfc_hba *phba = vport->phba;
2533 unsigned long bucket_value;
2535 switch (phba->bucket_type) {
2536 case LPFC_LINEAR_BUCKET:
2537 bucket_type = "linear";
2539 case LPFC_POWER2_BUCKET:
2540 bucket_type = "power2";
2543 bucket_type = "No Bucket";
2547 sprintf(&buf[index], "Statistical Data enabled :%d, "
2548 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2549 " Bucket step :%d\nLatency Ranges :",
2550 vport->stat_data_enabled, vport->stat_data_blocked,
2551 bucket_type, phba->bucket_base, phba->bucket_step);
2552 index = strlen(buf);
2553 if (phba->bucket_type != LPFC_NO_BUCKET) {
2554 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2555 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2556 bucket_value = phba->bucket_base +
2557 phba->bucket_step * i;
2559 bucket_value = phba->bucket_base +
2560 (1 << i) * phba->bucket_step;
2562 if (index + 10 > PAGE_SIZE)
2564 sprintf(&buf[index], "%08ld ", bucket_value);
2565 index = strlen(buf);
2568 sprintf(&buf[index], "\n");
2573 * Sysfs attribute to control the statistical data collection.
2575 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2576 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2579 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2583 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2586 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2587 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2588 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2592 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2593 * @kobj: Pointer to the kernel object
2594 * @bin_attr: Attribute object
2595 * @buff: Buffer pointer
2597 * @count: Buffer size
2599 * This function is the read call back function for lpfc_drvr_stat_data
2600 * sysfs file. This function export the statistical data to user
2604 sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2605 char *buf, loff_t off, size_t count)
2607 struct device *dev = container_of(kobj, struct device,
2609 struct Scsi_Host *shost = class_to_shost(dev);
2610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2611 struct lpfc_hba *phba = vport->phba;
2612 int i = 0, index = 0;
2613 unsigned long nport_index;
2614 struct lpfc_nodelist *ndlp = NULL;
2615 nport_index = (unsigned long)off /
2616 MAX_STAT_DATA_SIZE_PER_TARGET;
2618 if (!vport->stat_data_enabled || vport->stat_data_blocked
2619 || (phba->bucket_type == LPFC_NO_BUCKET))
2622 spin_lock_irq(shost->host_lock);
2623 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2624 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2627 if (nport_index > 0) {
2632 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2636 if (!ndlp->lat_data)
2640 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2641 ndlp->nlp_portname.u.wwn[0],
2642 ndlp->nlp_portname.u.wwn[1],
2643 ndlp->nlp_portname.u.wwn[2],
2644 ndlp->nlp_portname.u.wwn[3],
2645 ndlp->nlp_portname.u.wwn[4],
2646 ndlp->nlp_portname.u.wwn[5],
2647 ndlp->nlp_portname.u.wwn[6],
2648 ndlp->nlp_portname.u.wwn[7]);
2650 index = strlen(buf);
2652 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2653 sprintf(&buf[index], "%010u,",
2654 ndlp->lat_data[i].cmd_count);
2655 index = strlen(buf);
2657 sprintf(&buf[index], "\n");
2658 index = strlen(buf);
2660 spin_unlock_irq(shost->host_lock);
2664 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2666 .name = "lpfc_drvr_stat_data",
2668 .owner = THIS_MODULE,
2670 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2671 .read = sysfs_drvr_stat_data_read,
2676 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2678 # 0 = auto select (default)
2683 # Value range is [0,8]. Default value is 0.
2687 * lpfc_link_speed_set - Set the adapters link speed
2688 * @phba: lpfc_hba pointer.
2689 * @val: link speed value.
2692 * If val is in a valid range then set the adapter's link speed field and
2693 * issue a lip; if the lip fails reset the link speed to the old value.
2696 * If the value is not in range log a kernel error message and return an error.
2699 * zero if val is in range and lip okay.
2700 * non-zero return value from lpfc_issue_lip()
2701 * -EINVAL val out of range
2704 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2705 const char *buf, size_t count)
2707 struct Scsi_Host *shost = class_to_shost(dev);
2708 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2709 struct lpfc_hba *phba = vport->phba;
2712 const char *val_buf = buf;
2716 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2718 val_buf = &buf[strlen("nolip ")];
2721 if (!isdigit(val_buf[0]))
2723 if (sscanf(val_buf, "%i", &val) != 1)
2726 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2727 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2728 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2729 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2730 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2733 if ((val >= 0 && val <= 8)
2734 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2735 prev_val = phba->cfg_link_speed;
2736 phba->cfg_link_speed = val;
2740 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2742 phba->cfg_link_speed = prev_val;
2748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2749 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2750 "allowed range is [0, 8]\n",
2755 static int lpfc_link_speed = 0;
2756 module_param(lpfc_link_speed, int, 0);
2757 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2758 lpfc_param_show(link_speed)
2761 * lpfc_link_speed_init - Set the adapters link speed
2762 * @phba: lpfc_hba pointer.
2763 * @val: link speed value.
2766 * If val is in a valid range then set the adapter's link speed field.
2769 * If the value is not in range log a kernel error message, clear the link
2770 * speed and return an error.
2773 * zero if val saved.
2774 * -EINVAL val out of range
2777 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2779 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2780 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2781 phba->cfg_link_speed = val;
2784 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2785 "0405 lpfc_link_speed attribute cannot "
2786 "be set to %d, allowed values are "
2787 "["LPFC_LINK_SPEED_STRING"]\n", val);
2788 phba->cfg_link_speed = 0;
2792 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2793 lpfc_link_speed_show, lpfc_link_speed_store);
2796 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2797 # 0 = aer disabled or not supported
2798 # 1 = aer supported and enabled (default)
2799 # Value range is [0,1]. Default value is 1.
2803 * lpfc_aer_support_store - Set the adapter for aer support
2805 * @dev: class device that is converted into a Scsi_host.
2806 * @attr: device attribute, not used.
2807 * @buf: containing the string "selective".
2808 * @count: unused variable.
2811 * If the val is 1 and currently the device's AER capability was not
2812 * enabled, invoke the kernel's enable AER helper routine, trying to
2813 * enable the device's AER capability. If the helper routine enabling
2814 * AER returns success, update the device's cfg_aer_support flag to
2815 * indicate AER is supported by the device; otherwise, if the device
2816 * AER capability is already enabled to support AER, then do nothing.
2818 * If the val is 0 and currently the device's AER support was enabled,
2819 * invoke the kernel's disable AER helper routine. After that, update
2820 * the device's cfg_aer_support flag to indicate AER is not supported
2821 * by the device; otherwise, if the device AER capability is already
2822 * disabled from supporting AER, then do nothing.
2825 * length of the buf on success if val is in range the intended mode
2827 * -EINVAL if val out of range or intended mode is not supported.
2830 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2831 const char *buf, size_t count)
2833 struct Scsi_Host *shost = class_to_shost(dev);
2834 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2835 struct lpfc_hba *phba = vport->phba;
2836 int val = 0, rc = -EINVAL;
2838 /* AER not supported on OC devices yet */
2839 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
2841 if (!isdigit(buf[0]))
2843 if (sscanf(buf, "%i", &val) != 1)
2848 if (phba->hba_flag & HBA_AER_ENABLED) {
2849 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2851 spin_lock_irq(&phba->hbalock);
2852 phba->hba_flag &= ~HBA_AER_ENABLED;
2853 spin_unlock_irq(&phba->hbalock);
2854 phba->cfg_aer_support = 0;
2859 phba->cfg_aer_support = 0;
2864 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2865 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2867 spin_lock_irq(&phba->hbalock);
2868 phba->hba_flag |= HBA_AER_ENABLED;
2869 spin_unlock_irq(&phba->hbalock);
2870 phba->cfg_aer_support = 1;
2875 phba->cfg_aer_support = 1;
2886 static int lpfc_aer_support = 1;
2887 module_param(lpfc_aer_support, int, 1);
2888 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2889 lpfc_param_show(aer_support)
2892 * lpfc_aer_support_init - Set the initial adapters aer support flag
2893 * @phba: lpfc_hba pointer.
2894 * @val: link speed value.
2897 * If val is in a valid range [0,1], then set the adapter's initial
2898 * cfg_aer_support field. It will be up to the driver's probe_one
2899 * routine to determine whether the device's AER support can be set
2903 * If the value is not in range log a kernel error message, and
2904 * choose the default value of setting AER support and return.
2907 * zero if val saved.
2908 * -EINVAL val out of range
2911 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
2913 /* AER not supported on OC devices yet */
2914 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
2915 phba->cfg_aer_support = 0;
2919 if (val == 0 || val == 1) {
2920 phba->cfg_aer_support = val;
2923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2924 "2712 lpfc_aer_support attribute value %d out "
2925 "of range, allowed values are 0|1, setting it "
2926 "to default value of 1\n", val);
2927 /* By default, try to enable AER on a device */
2928 phba->cfg_aer_support = 1;
2932 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
2933 lpfc_aer_support_show, lpfc_aer_support_store);
2936 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
2937 * @dev: class device that is converted into a Scsi_host.
2938 * @attr: device attribute, not used.
2939 * @buf: containing the string "selective".
2940 * @count: unused variable.
2943 * If the @buf contains 1 and the device currently has the AER support
2944 * enabled, then invokes the kernel AER helper routine
2945 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
2946 * error status register.
2951 * -EINVAL if the buf does not contain the 1 or the device is not currently
2952 * enabled with the AER support.
2955 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
2956 const char *buf, size_t count)
2958 struct Scsi_Host *shost = class_to_shost(dev);
2959 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2960 struct lpfc_hba *phba = vport->phba;
2963 /* AER not supported on OC devices yet */
2964 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
2966 if (!isdigit(buf[0]))
2968 if (sscanf(buf, "%i", &val) != 1)
2973 if (phba->hba_flag & HBA_AER_ENABLED)
2974 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
2982 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
2983 lpfc_aer_cleanup_state);
2986 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2987 # Value range is [2,3]. Default value is 3.
2989 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
2990 "Select Fibre Channel class of service for FCP sequences");
2993 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2994 # is [0,1]. Default value is 0.
2996 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
2997 "Use ADISC on rediscovery to authenticate FCP devices");
3000 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3001 # depth. Default value is 0. When the value of this parameter is zero the
3002 # SCSI command completion time is not used for controlling I/O queue depth. When
3003 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3004 # to limit the I/O completion time to the parameter value.
3005 # The value is set in milliseconds.
3007 static int lpfc_max_scsicmpl_time;
3008 module_param(lpfc_max_scsicmpl_time, int, 0);
3009 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3010 "Use command completion time to control queue depth");
3011 lpfc_vport_param_show(max_scsicmpl_time);
3012 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3014 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3016 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3017 struct lpfc_nodelist *ndlp, *next_ndlp;
3019 if (val == vport->cfg_max_scsicmpl_time)
3021 if ((val < 0) || (val > 60000))
3023 vport->cfg_max_scsicmpl_time = val;
3025 spin_lock_irq(shost->host_lock);
3026 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3027 if (!NLP_CHK_NODE_ACT(ndlp))
3029 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3031 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
3033 spin_unlock_irq(shost->host_lock);
3036 lpfc_vport_param_store(max_scsicmpl_time);
3037 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3038 lpfc_max_scsicmpl_time_show,
3039 lpfc_max_scsicmpl_time_store);
3042 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3043 # range is [0,1]. Default value is 0.
3045 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3048 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3049 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3050 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3051 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3052 # cr_delay is set to 0.
3054 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3055 "interrupt response is generated");
3057 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3058 "interrupt response is generated");
3061 # lpfc_multi_ring_support: Determines how many rings to spread available
3062 # cmd/rsp IOCB entries across.
3063 # Value range is [1,2]. Default value is 1.
3065 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3066 "SLI rings to spread IOCB entries across");
3069 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3070 # identifies what rctl value to configure the additional ring for.
3071 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3073 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3074 255, "Identifies RCTL for additional ring configuration");
3077 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3078 # identifies what type value to configure the additional ring for.
3079 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3081 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3082 255, "Identifies TYPE for additional ring configuration");
3085 # lpfc_fdmi_on: controls FDMI support.
3086 # 0 = no FDMI support
3087 # 1 = support FDMI without attribute of hostname
3088 # 2 = support FDMI with attribute of hostname
3089 # Value range [0,2]. Default value is 0.
3091 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3094 # Specifies the maximum number of ELS cmds we can have outstanding (for
3095 # discovery). Value range is [1,64]. Default value = 32.
3097 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3098 "during discovery");
3101 # lpfc_max_luns: maximum allowed LUN.
3102 # Value range is [0,65535]. Default value is 255.
3103 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3105 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3108 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3109 # Value range is [1,255], default value is 10.
3111 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3112 "Milliseconds driver will wait between polling FCP ring");
3115 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3116 # support this feature
3117 # 0 = MSI disabled (default)
3120 # Value range is [0,2]. Default value is 0.
3122 LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
3123 "MSI-X (2), if possible");
3126 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3128 # Value range is [636,651042]. Default value is 10000.
3130 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3131 "Set the maximum number of fast-path FCP interrupts per second");
3134 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3136 # Value range is [1,31]. Default value is 4.
3138 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3139 "Set the number of fast-path FCP work queues, if possible");
3142 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3144 # Value range is [1,7]. Default value is 1.
3146 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3147 "Set the number of fast-path FCP event queues, if possible");
3150 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3151 # 0 = HBA resets disabled
3152 # 1 = HBA resets enabled (default)
3153 # Value range is [0,1]. Default value is 1.
3155 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3158 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3159 # 0 = HBA Heartbeat disabled
3160 # 1 = HBA Heartbeat enabled (default)
3161 # Value range is [0,1]. Default value is 1.
3163 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
3166 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3167 # 0 = BlockGuard disabled (default)
3168 # 1 = BlockGuard enabled
3169 # Value range is [0,1]. Default value is 0.
3171 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3175 # - Bit mask of host protection capabilities used to register with the
3177 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3178 # - Allows you to ultimately specify which profiles to use
3179 # - Default will result in registering capabilities for all profiles.
3182 unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3184 module_param(lpfc_prot_mask, uint, 0);
3185 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3188 # lpfc_prot_guard: i
3189 # - Bit mask of protection guard types to register with the SCSI mid-layer
3190 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3191 # - Allows you to ultimately specify which profiles to use
3192 # - Default will result in registering capabilities for all guard types
3195 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3196 module_param(lpfc_prot_guard, byte, 0);
3197 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3201 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3202 * This value can be set to values between 64 and 256. The default value is
3203 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3204 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3206 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3207 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3209 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3210 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3211 "Max Protection Scatter Gather Segment Count");
3213 struct device_attribute *lpfc_hba_attrs[] = {
3215 &dev_attr_bg_guard_err,
3216 &dev_attr_bg_apptag_err,
3217 &dev_attr_bg_reftag_err,
3219 &dev_attr_serialnum,
3220 &dev_attr_modeldesc,
3221 &dev_attr_modelname,
3222 &dev_attr_programtype,
3226 &dev_attr_option_rom_version,
3227 &dev_attr_link_state,
3228 &dev_attr_num_discovered_ports,
3229 &dev_attr_menlo_mgmt_mode,
3230 &dev_attr_lpfc_drvr_version,
3231 &dev_attr_lpfc_enable_fip,
3232 &dev_attr_lpfc_temp_sensor,
3233 &dev_attr_lpfc_log_verbose,
3234 &dev_attr_lpfc_lun_queue_depth,
3235 &dev_attr_lpfc_hba_queue_depth,
3236 &dev_attr_lpfc_peer_port_login,
3237 &dev_attr_lpfc_nodev_tmo,
3238 &dev_attr_lpfc_devloss_tmo,
3239 &dev_attr_lpfc_fcp_class,
3240 &dev_attr_lpfc_use_adisc,
3241 &dev_attr_lpfc_ack0,
3242 &dev_attr_lpfc_topology,
3243 &dev_attr_lpfc_scan_down,
3244 &dev_attr_lpfc_link_speed,
3245 &dev_attr_lpfc_cr_delay,
3246 &dev_attr_lpfc_cr_count,
3247 &dev_attr_lpfc_multi_ring_support,
3248 &dev_attr_lpfc_multi_ring_rctl,
3249 &dev_attr_lpfc_multi_ring_type,
3250 &dev_attr_lpfc_fdmi_on,
3251 &dev_attr_lpfc_max_luns,
3252 &dev_attr_lpfc_enable_npiv,
3253 &dev_attr_nport_evt_cnt,
3254 &dev_attr_board_mode,
3261 &dev_attr_npiv_info,
3262 &dev_attr_issue_reset,
3263 &dev_attr_lpfc_poll,
3264 &dev_attr_lpfc_poll_tmo,
3265 &dev_attr_lpfc_use_msi,
3266 &dev_attr_lpfc_fcp_imax,
3267 &dev_attr_lpfc_fcp_wq_count,
3268 &dev_attr_lpfc_fcp_eq_count,
3269 &dev_attr_lpfc_enable_bg,
3270 &dev_attr_lpfc_soft_wwnn,
3271 &dev_attr_lpfc_soft_wwpn,
3272 &dev_attr_lpfc_soft_wwn_enable,
3273 &dev_attr_lpfc_enable_hba_reset,
3274 &dev_attr_lpfc_enable_hba_heartbeat,
3275 &dev_attr_lpfc_sg_seg_cnt,
3276 &dev_attr_lpfc_max_scsicmpl_time,
3277 &dev_attr_lpfc_stat_data_ctrl,
3278 &dev_attr_lpfc_prot_sg_seg_cnt,
3279 &dev_attr_lpfc_aer_support,
3280 &dev_attr_lpfc_aer_state_cleanup,
3284 struct device_attribute *lpfc_vport_attrs[] = {
3286 &dev_attr_link_state,
3287 &dev_attr_num_discovered_ports,
3288 &dev_attr_lpfc_drvr_version,
3289 &dev_attr_lpfc_log_verbose,
3290 &dev_attr_lpfc_lun_queue_depth,
3291 &dev_attr_lpfc_nodev_tmo,
3292 &dev_attr_lpfc_devloss_tmo,
3293 &dev_attr_lpfc_hba_queue_depth,
3294 &dev_attr_lpfc_peer_port_login,
3295 &dev_attr_lpfc_restrict_login,
3296 &dev_attr_lpfc_fcp_class,
3297 &dev_attr_lpfc_use_adisc,
3298 &dev_attr_lpfc_fdmi_on,
3299 &dev_attr_lpfc_max_luns,
3300 &dev_attr_nport_evt_cnt,
3301 &dev_attr_npiv_info,
3302 &dev_attr_lpfc_enable_da_id,
3303 &dev_attr_lpfc_max_scsicmpl_time,
3304 &dev_attr_lpfc_stat_data_ctrl,
3305 &dev_attr_lpfc_static_vport,
3310 * sysfs_ctlreg_write - Write method for writing to ctlreg
3311 * @kobj: kernel kobject that contains the kernel class device.
3312 * @bin_attr: kernel attributes passed to us.
3313 * @buf: contains the data to be written to the adapter IOREG space.
3314 * @off: offset into buffer to beginning of data.
3315 * @count: bytes to transfer.
3318 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3319 * Uses the adapter io control registers to send buf contents to the adapter.
3322 * -ERANGE off and count combo out of range
3323 * -EINVAL off, count or buff address invalid
3324 * -EPERM adapter is offline
3325 * value of count, buf contents written
3328 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3329 char *buf, loff_t off, size_t count)
3332 struct device *dev = container_of(kobj, struct device, kobj);
3333 struct Scsi_Host *shost = class_to_shost(dev);
3334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3335 struct lpfc_hba *phba = vport->phba;
3337 if (phba->sli_rev >= LPFC_SLI_REV4)
3340 if ((off + count) > FF_REG_AREA_SIZE)
3343 if (count == 0) return 0;
3345 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3348 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3352 spin_lock_irq(&phba->hbalock);
3353 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3354 writel(*((uint32_t *)(buf + buf_off)),
3355 phba->ctrl_regs_memmap_p + off + buf_off);
3357 spin_unlock_irq(&phba->hbalock);
3363 * sysfs_ctlreg_read - Read method for reading from ctlreg
3364 * @kobj: kernel kobject that contains the kernel class device.
3365 * @bin_attr: kernel attributes passed to us.
3366 * @buf: if successful contains the data from the adapter IOREG space.
3367 * @off: offset into buffer to beginning of data.
3368 * @count: bytes to transfer.
3371 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3372 * Uses the adapter io control registers to read data into buf.
3375 * -ERANGE off and count combo out of range
3376 * -EINVAL off, count or buff address invalid
3377 * value of count, buf contents read
3380 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3381 char *buf, loff_t off, size_t count)
3385 struct device *dev = container_of(kobj, struct device, kobj);
3386 struct Scsi_Host *shost = class_to_shost(dev);
3387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3388 struct lpfc_hba *phba = vport->phba;
3390 if (phba->sli_rev >= LPFC_SLI_REV4)
3393 if (off > FF_REG_AREA_SIZE)
3396 if ((off + count) > FF_REG_AREA_SIZE)
3397 count = FF_REG_AREA_SIZE - off;
3399 if (count == 0) return 0;
3401 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3404 spin_lock_irq(&phba->hbalock);
3406 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3407 tmp_ptr = (uint32_t *)(buf + buf_off);
3408 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3411 spin_unlock_irq(&phba->hbalock);
3416 static struct bin_attribute sysfs_ctlreg_attr = {
3419 .mode = S_IRUSR | S_IWUSR,
3422 .read = sysfs_ctlreg_read,
3423 .write = sysfs_ctlreg_write,
3427 * sysfs_mbox_idle - frees the sysfs mailbox
3428 * @phba: lpfc_hba pointer
3431 sysfs_mbox_idle(struct lpfc_hba *phba)
3433 phba->sysfs_mbox.state = SMBOX_IDLE;
3434 phba->sysfs_mbox.offset = 0;
3436 if (phba->sysfs_mbox.mbox) {
3437 mempool_free(phba->sysfs_mbox.mbox,
3438 phba->mbox_mem_pool);
3439 phba->sysfs_mbox.mbox = NULL;
3444 * sysfs_mbox_write - Write method for writing information via mbox
3445 * @kobj: kernel kobject that contains the kernel class device.
3446 * @bin_attr: kernel attributes passed to us.
3447 * @buf: contains the data to be written to sysfs mbox.
3448 * @off: offset into buffer to beginning of data.
3449 * @count: bytes to transfer.
3452 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3453 * Uses the sysfs mbox to send buf contents to the adapter.
3456 * -ERANGE off and count combo out of range
3457 * -EINVAL off, count or buff address invalid
3458 * zero if count is zero
3459 * -EPERM adapter is offline
3460 * -ENOMEM failed to allocate memory for the mail box
3461 * -EAGAIN offset, state or mbox is NULL
3462 * count number of bytes transferred
3465 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3466 char *buf, loff_t off, size_t count)
3468 struct device *dev = container_of(kobj, struct device, kobj);
3469 struct Scsi_Host *shost = class_to_shost(dev);
3470 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3471 struct lpfc_hba *phba = vport->phba;
3472 struct lpfcMboxq *mbox = NULL;
3474 if ((count + off) > MAILBOX_CMD_SIZE)
3477 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3484 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3487 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3490 spin_lock_irq(&phba->hbalock);
3493 if (phba->sysfs_mbox.mbox)
3494 mempool_free(mbox, phba->mbox_mem_pool);
3496 phba->sysfs_mbox.mbox = mbox;
3497 phba->sysfs_mbox.state = SMBOX_WRITING;
3499 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3500 phba->sysfs_mbox.offset != off ||
3501 phba->sysfs_mbox.mbox == NULL) {
3502 sysfs_mbox_idle(phba);
3503 spin_unlock_irq(&phba->hbalock);
3508 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3511 phba->sysfs_mbox.offset = off + count;
3513 spin_unlock_irq(&phba->hbalock);
3519 * sysfs_mbox_read - Read method for reading information via mbox
3520 * @kobj: kernel kobject that contains the kernel class device.
3521 * @bin_attr: kernel attributes passed to us.
3522 * @buf: contains the data to be read from sysfs mbox.
3523 * @off: offset into buffer to beginning of data.
3524 * @count: bytes to transfer.
3527 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3528 * Uses the sysfs mbox to receive data from to the adapter.
3531 * -ERANGE off greater than mailbox command size
3532 * -EINVAL off, count or buff address invalid
3533 * zero if off and count are zero
3534 * -EACCES adapter over temp
3535 * -EPERM garbage can value to catch a multitude of errors
3536 * -EAGAIN management IO not permitted, state or off error
3537 * -ETIME mailbox timeout
3538 * -ENODEV mailbox error
3539 * count number of bytes transferred
3542 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3543 char *buf, loff_t off, size_t count)
3545 struct device *dev = container_of(kobj, struct device, kobj);
3546 struct Scsi_Host *shost = class_to_shost(dev);
3547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3548 struct lpfc_hba *phba = vport->phba;
3552 if (off > MAILBOX_CMD_SIZE)
3555 if ((count + off) > MAILBOX_CMD_SIZE)
3556 count = MAILBOX_CMD_SIZE - off;
3558 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3561 if (off && count == 0)
3564 spin_lock_irq(&phba->hbalock);
3566 if (phba->over_temp_state == HBA_OVER_TEMP) {
3567 sysfs_mbox_idle(phba);
3568 spin_unlock_irq(&phba->hbalock);
3573 phba->sysfs_mbox.state == SMBOX_WRITING &&
3574 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3575 pmb = &phba->sysfs_mbox.mbox->u.mb;
3576 switch (pmb->mbxCommand) {
3580 case MBX_CONFIG_LINK:
3581 case MBX_CONFIG_RING:
3582 case MBX_RESET_RING:
3583 case MBX_UNREG_LOGIN:
3585 case MBX_DUMP_CONTEXT:
3590 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3591 printk(KERN_WARNING "mbox_read:Command 0x%x "
3592 "is illegal in on-line state\n",
3594 sysfs_mbox_idle(phba);
3595 spin_unlock_irq(&phba->hbalock);
3599 case MBX_WRITE_VPARMS:
3602 case MBX_READ_CONFIG:
3603 case MBX_READ_RCONFIG:
3604 case MBX_READ_STATUS:
3607 case MBX_READ_LNK_STAT:
3608 case MBX_DUMP_MEMORY:
3610 case MBX_UPDATE_CFG:
3611 case MBX_KILL_BOARD:
3613 case MBX_LOAD_EXP_ROM:
3615 case MBX_DEL_LD_ENTRY:
3616 case MBX_SET_VARIABLE:
3618 case MBX_PORT_CAPABILITIES:
3619 case MBX_PORT_IOV_CONTROL:
3621 case MBX_READ_SPARM64:
3625 case MBX_REG_LOGIN64:
3626 case MBX_CONFIG_PORT:
3627 case MBX_RUN_BIU_DIAG:
3628 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3630 sysfs_mbox_idle(phba);
3631 spin_unlock_irq(&phba->hbalock);
3634 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3636 sysfs_mbox_idle(phba);
3637 spin_unlock_irq(&phba->hbalock);
3641 /* If HBA encountered an error attention, allow only DUMP
3642 * or RESTART mailbox commands until the HBA is restarted.
3644 if (phba->pport->stopped &&
3645 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3646 pmb->mbxCommand != MBX_RESTART &&
3647 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3648 pmb->mbxCommand != MBX_WRITE_WWN)
3649 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3650 "1259 mbox: Issued mailbox cmd "
3651 "0x%x while in stopped state.\n",
3654 phba->sysfs_mbox.mbox->vport = vport;
3656 /* Don't allow mailbox commands to be sent when blocked
3657 * or when in the middle of discovery
3659 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3660 sysfs_mbox_idle(phba);
3661 spin_unlock_irq(&phba->hbalock);
3665 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3666 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3668 spin_unlock_irq(&phba->hbalock);
3669 rc = lpfc_sli_issue_mbox (phba,
3670 phba->sysfs_mbox.mbox,
3672 spin_lock_irq(&phba->hbalock);
3675 spin_unlock_irq(&phba->hbalock);
3676 rc = lpfc_sli_issue_mbox_wait (phba,
3677 phba->sysfs_mbox.mbox,
3678 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3679 spin_lock_irq(&phba->hbalock);
3682 if (rc != MBX_SUCCESS) {
3683 if (rc == MBX_TIMEOUT) {
3684 phba->sysfs_mbox.mbox = NULL;
3686 sysfs_mbox_idle(phba);
3687 spin_unlock_irq(&phba->hbalock);
3688 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3690 phba->sysfs_mbox.state = SMBOX_READING;
3692 else if (phba->sysfs_mbox.offset != off ||
3693 phba->sysfs_mbox.state != SMBOX_READING) {
3694 printk(KERN_WARNING "mbox_read: Bad State\n");
3695 sysfs_mbox_idle(phba);
3696 spin_unlock_irq(&phba->hbalock);
3700 memcpy(buf, (uint8_t *) &pmb + off, count);
3702 phba->sysfs_mbox.offset = off + count;
3704 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3705 sysfs_mbox_idle(phba);
3707 spin_unlock_irq(&phba->hbalock);
3712 static struct bin_attribute sysfs_mbox_attr = {
3715 .mode = S_IRUSR | S_IWUSR,
3717 .size = MAILBOX_CMD_SIZE,
3718 .read = sysfs_mbox_read,
3719 .write = sysfs_mbox_write,
3723 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3724 * @vport: address of lpfc vport structure.
3728 * error return code from sysfs_create_bin_file()
3731 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3733 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3736 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3737 &sysfs_drvr_stat_data_attr);
3739 /* Virtual ports do not need ctrl_reg and mbox */
3740 if (error || vport->port_type == LPFC_NPIV_PORT)
3743 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3744 &sysfs_ctlreg_attr);
3746 goto out_remove_stat_attr;
3748 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3751 goto out_remove_ctlreg_attr;
3754 out_remove_ctlreg_attr:
3755 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3756 out_remove_stat_attr:
3757 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3758 &sysfs_drvr_stat_data_attr);
3764 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
3765 * @vport: address of lpfc vport structure.
3768 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
3770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3771 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3772 &sysfs_drvr_stat_data_attr);
3773 /* Virtual ports do not need ctrl_reg and mbox */
3774 if (vport->port_type == LPFC_NPIV_PORT)
3776 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3777 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3782 * Dynamic FC Host Attributes Support
3786 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
3787 * @shost: kernel scsi host pointer.
3790 lpfc_get_host_port_id(struct Scsi_Host *shost)
3792 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3794 /* note: fc_myDID already in cpu endianness */
3795 fc_host_port_id(shost) = vport->fc_myDID;
3799 * lpfc_get_host_port_type - Set the value of the scsi host port type
3800 * @shost: kernel scsi host pointer.
3803 lpfc_get_host_port_type(struct Scsi_Host *shost)
3805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3806 struct lpfc_hba *phba = vport->phba;
3808 spin_lock_irq(shost->host_lock);
3810 if (vport->port_type == LPFC_NPIV_PORT) {
3811 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3812 } else if (lpfc_is_link_up(phba)) {
3813 if (phba->fc_topology == TOPOLOGY_LOOP) {
3814 if (vport->fc_flag & FC_PUBLIC_LOOP)
3815 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3817 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3819 if (vport->fc_flag & FC_FABRIC)
3820 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3822 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3825 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3827 spin_unlock_irq(shost->host_lock);
3831 * lpfc_get_host_port_state - Set the value of the scsi host port state
3832 * @shost: kernel scsi host pointer.
3835 lpfc_get_host_port_state(struct Scsi_Host *shost)
3837 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3838 struct lpfc_hba *phba = vport->phba;
3840 spin_lock_irq(shost->host_lock);
3842 if (vport->fc_flag & FC_OFFLINE_MODE)
3843 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3845 switch (phba->link_state) {
3846 case LPFC_LINK_UNKNOWN:
3847 case LPFC_LINK_DOWN:
3848 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3852 case LPFC_HBA_READY:
3853 /* Links up, beyond this port_type reports state */
3854 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3856 case LPFC_HBA_ERROR:
3857 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3860 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3865 spin_unlock_irq(shost->host_lock);
3869 * lpfc_get_host_speed - Set the value of the scsi host speed
3870 * @shost: kernel scsi host pointer.
3873 lpfc_get_host_speed(struct Scsi_Host *shost)
3875 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3876 struct lpfc_hba *phba = vport->phba;
3878 spin_lock_irq(shost->host_lock);
3880 if (lpfc_is_link_up(phba)) {
3881 switch(phba->fc_linkspeed) {
3883 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3886 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3889 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3892 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3895 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3898 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3902 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3904 spin_unlock_irq(shost->host_lock);
3908 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
3909 * @shost: kernel scsi host pointer.
3912 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3915 struct lpfc_hba *phba = vport->phba;
3918 spin_lock_irq(shost->host_lock);
3920 if ((vport->fc_flag & FC_FABRIC) ||
3921 ((phba->fc_topology == TOPOLOGY_LOOP) &&
3922 (vport->fc_flag & FC_PUBLIC_LOOP)))
3923 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
3925 /* fabric is local port if there is no F/FL_Port */
3928 spin_unlock_irq(shost->host_lock);
3930 fc_host_fabric_name(shost) = node_name;
3934 * lpfc_get_stats - Return statistical information about the adapter
3935 * @shost: kernel scsi host pointer.
3938 * NULL on error for link down, no mbox pool, sli2 active,
3939 * management not allowed, memory allocation error, or mbox error.
3943 * address of the adapter host statistics
3945 static struct fc_host_statistics *
3946 lpfc_get_stats(struct Scsi_Host *shost)
3948 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3949 struct lpfc_hba *phba = vport->phba;
3950 struct lpfc_sli *psli = &phba->sli;
3951 struct fc_host_statistics *hs = &phba->link_stats;
3952 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
3953 LPFC_MBOXQ_t *pmboxq;
3955 unsigned long seconds;
3959 * prevent udev from issuing mailbox commands until the port is
3962 if (phba->link_state < LPFC_LINK_DOWN ||
3963 !phba->mbox_mem_pool ||
3964 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
3967 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
3970 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3973 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
3975 pmb = &pmboxq->u.mb;
3976 pmb->mbxCommand = MBX_READ_STATUS;
3977 pmb->mbxOwner = OWN_HOST;
3978 pmboxq->context1 = NULL;
3979 pmboxq->vport = vport;
3981 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3982 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
3983 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
3985 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
3987 if (rc != MBX_SUCCESS) {
3988 if (rc != MBX_TIMEOUT)
3989 mempool_free(pmboxq, phba->mbox_mem_pool);
3993 memset(hs, 0, sizeof (struct fc_host_statistics));
3995 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
3996 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
3997 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
3998 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4000 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4001 pmb->mbxCommand = MBX_READ_LNK_STAT;
4002 pmb->mbxOwner = OWN_HOST;
4003 pmboxq->context1 = NULL;
4004 pmboxq->vport = vport;
4006 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4007 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4008 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4010 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4012 if (rc != MBX_SUCCESS) {
4013 if (rc != MBX_TIMEOUT)
4014 mempool_free(pmboxq, phba->mbox_mem_pool);
4018 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4019 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4020 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4021 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4022 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4023 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4024 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4026 hs->link_failure_count -= lso->link_failure_count;
4027 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4028 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4029 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4030 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4031 hs->invalid_crc_count -= lso->invalid_crc_count;
4032 hs->error_frames -= lso->error_frames;
4034 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4036 hs->nos_count = (phba->link_events >> 1);
4037 hs->nos_count -= lso->link_events;
4038 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
4039 hs->lip_count = (phba->fc_eventTag >> 1);
4040 hs->lip_count -= lso->link_events;
4044 hs->nos_count = (phba->fc_eventTag >> 1);
4045 hs->nos_count -= lso->link_events;
4048 hs->dumped_frames = -1;
4050 seconds = get_seconds();
4051 if (seconds < psli->stats_start)
4052 hs->seconds_since_last_reset = seconds +
4053 ((unsigned long)-1 - psli->stats_start);
4055 hs->seconds_since_last_reset = seconds - psli->stats_start;
4057 mempool_free(pmboxq, phba->mbox_mem_pool);
4063 * lpfc_reset_stats - Copy the adapter link stats information
4064 * @shost: kernel scsi host pointer.
4067 lpfc_reset_stats(struct Scsi_Host *shost)
4069 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4070 struct lpfc_hba *phba = vport->phba;
4071 struct lpfc_sli *psli = &phba->sli;
4072 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4073 LPFC_MBOXQ_t *pmboxq;
4077 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4080 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4083 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4085 pmb = &pmboxq->u.mb;
4086 pmb->mbxCommand = MBX_READ_STATUS;
4087 pmb->mbxOwner = OWN_HOST;
4088 pmb->un.varWords[0] = 0x1; /* reset request */
4089 pmboxq->context1 = NULL;
4090 pmboxq->vport = vport;
4092 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4093 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4094 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4096 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4098 if (rc != MBX_SUCCESS) {
4099 if (rc != MBX_TIMEOUT)
4100 mempool_free(pmboxq, phba->mbox_mem_pool);
4104 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4105 pmb->mbxCommand = MBX_READ_LNK_STAT;
4106 pmb->mbxOwner = OWN_HOST;
4107 pmboxq->context1 = NULL;
4108 pmboxq->vport = vport;
4110 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4111 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4112 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4114 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4116 if (rc != MBX_SUCCESS) {
4117 if (rc != MBX_TIMEOUT)
4118 mempool_free( pmboxq, phba->mbox_mem_pool);
4122 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4123 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4124 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4125 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4126 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4127 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4128 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4129 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4130 lso->link_events = (phba->link_events >> 1);
4132 lso->link_events = (phba->fc_eventTag >> 1);
4134 psli->stats_start = get_seconds();
4136 mempool_free(pmboxq, phba->mbox_mem_pool);
4142 * The LPFC driver treats linkdown handling as target loss events so there
4143 * are no sysfs handlers for link_down_tmo.
4147 * lpfc_get_node_by_target - Return the nodelist for a target
4148 * @starget: kernel scsi target pointer.
4151 * address of the node list if found
4152 * NULL target not found
4154 static struct lpfc_nodelist *
4155 lpfc_get_node_by_target(struct scsi_target *starget)
4157 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4159 struct lpfc_nodelist *ndlp;
4161 spin_lock_irq(shost->host_lock);
4162 /* Search for this, mapped, target ID */
4163 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4164 if (NLP_CHK_NODE_ACT(ndlp) &&
4165 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4166 starget->id == ndlp->nlp_sid) {
4167 spin_unlock_irq(shost->host_lock);
4171 spin_unlock_irq(shost->host_lock);
4176 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4177 * @starget: kernel scsi target pointer.
4180 lpfc_get_starget_port_id(struct scsi_target *starget)
4182 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4184 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4188 * lpfc_get_starget_node_name - Set the target node name
4189 * @starget: kernel scsi target pointer.
4191 * Description: Set the target node name to the ndlp node name wwn or zero.
4194 lpfc_get_starget_node_name(struct scsi_target *starget)
4196 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4198 fc_starget_node_name(starget) =
4199 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4203 * lpfc_get_starget_port_name - Set the target port name
4204 * @starget: kernel scsi target pointer.
4206 * Description: set the target port name to the ndlp port name wwn or zero.
4209 lpfc_get_starget_port_name(struct scsi_target *starget)
4211 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4213 fc_starget_port_name(starget) =
4214 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4218 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4219 * @rport: fc rport address.
4220 * @timeout: new value for dev loss tmo.
4223 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4224 * dev_loss_tmo to one.
4227 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4230 rport->dev_loss_tmo = timeout;
4232 rport->dev_loss_tmo = 1;
4236 * lpfc_rport_show_function - Return rport target information
4239 * Macro that uses field to generate a function with the name lpfc_show_rport_
4241 * lpfc_show_rport_##field: returns the bytes formatted in buf
4242 * @cdev: class converted to an fc_rport.
4243 * @buf: on return contains the target_field or zero.
4245 * Returns: size of formatted string.
4247 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4249 lpfc_show_rport_##field (struct device *dev, \
4250 struct device_attribute *attr, \
4253 struct fc_rport *rport = transport_class_to_rport(dev); \
4254 struct lpfc_rport_data *rdata = rport->hostdata; \
4255 return snprintf(buf, sz, format_string, \
4256 (rdata->target) ? cast rdata->target->field : 0); \
4259 #define lpfc_rport_rd_attr(field, format_string, sz) \
4260 lpfc_rport_show_function(field, format_string, sz, ) \
4261 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4264 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4265 * @fc_vport: The fc_vport who's symbolic name has been changed.
4268 * This function is called by the transport after the @fc_vport's symbolic name
4269 * has been changed. This function re-registers the symbolic name with the
4270 * switch to propogate the change into the fabric if the vport is active.
4273 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4275 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4277 if (vport->port_state == LPFC_VPORT_READY)
4278 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4282 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4283 * @phba: Pointer to lpfc_hba struct.
4285 * This function is called by the lpfc_get_cfgparam() routine to set the
4286 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4287 * log messsage according to the module's lpfc_log_verbose parameter setting
4288 * before hba port or vport created.
4291 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4293 phba->cfg_log_verbose = verbose;
4296 struct fc_function_template lpfc_transport_functions = {
4297 /* fixed attributes the driver supports */
4298 .show_host_node_name = 1,
4299 .show_host_port_name = 1,
4300 .show_host_supported_classes = 1,
4301 .show_host_supported_fc4s = 1,
4302 .show_host_supported_speeds = 1,
4303 .show_host_maxframe_size = 1,
4304 .show_host_symbolic_name = 1,
4306 /* dynamic attributes the driver supports */
4307 .get_host_port_id = lpfc_get_host_port_id,
4308 .show_host_port_id = 1,
4310 .get_host_port_type = lpfc_get_host_port_type,
4311 .show_host_port_type = 1,
4313 .get_host_port_state = lpfc_get_host_port_state,
4314 .show_host_port_state = 1,
4316 /* active_fc4s is shown but doesn't change (thus no get function) */
4317 .show_host_active_fc4s = 1,
4319 .get_host_speed = lpfc_get_host_speed,
4320 .show_host_speed = 1,
4322 .get_host_fabric_name = lpfc_get_host_fabric_name,
4323 .show_host_fabric_name = 1,
4326 * The LPFC driver treats linkdown handling as target loss events
4327 * so there are no sysfs handlers for link_down_tmo.
4330 .get_fc_host_stats = lpfc_get_stats,
4331 .reset_fc_host_stats = lpfc_reset_stats,
4333 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4334 .show_rport_maxframe_size = 1,
4335 .show_rport_supported_classes = 1,
4337 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4338 .show_rport_dev_loss_tmo = 1,
4340 .get_starget_port_id = lpfc_get_starget_port_id,
4341 .show_starget_port_id = 1,
4343 .get_starget_node_name = lpfc_get_starget_node_name,
4344 .show_starget_node_name = 1,
4346 .get_starget_port_name = lpfc_get_starget_port_name,
4347 .show_starget_port_name = 1,
4349 .issue_fc_host_lip = lpfc_issue_lip,
4350 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4351 .terminate_rport_io = lpfc_terminate_rport_io,
4353 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4355 .vport_disable = lpfc_vport_disable,
4357 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4359 .bsg_request = lpfc_bsg_request,
4360 .bsg_timeout = lpfc_bsg_timeout,
4363 struct fc_function_template lpfc_vport_transport_functions = {
4364 /* fixed attributes the driver supports */
4365 .show_host_node_name = 1,
4366 .show_host_port_name = 1,
4367 .show_host_supported_classes = 1,
4368 .show_host_supported_fc4s = 1,
4369 .show_host_supported_speeds = 1,
4370 .show_host_maxframe_size = 1,
4371 .show_host_symbolic_name = 1,
4373 /* dynamic attributes the driver supports */
4374 .get_host_port_id = lpfc_get_host_port_id,
4375 .show_host_port_id = 1,
4377 .get_host_port_type = lpfc_get_host_port_type,
4378 .show_host_port_type = 1,
4380 .get_host_port_state = lpfc_get_host_port_state,
4381 .show_host_port_state = 1,
4383 /* active_fc4s is shown but doesn't change (thus no get function) */
4384 .show_host_active_fc4s = 1,
4386 .get_host_speed = lpfc_get_host_speed,
4387 .show_host_speed = 1,
4389 .get_host_fabric_name = lpfc_get_host_fabric_name,
4390 .show_host_fabric_name = 1,
4393 * The LPFC driver treats linkdown handling as target loss events
4394 * so there are no sysfs handlers for link_down_tmo.
4397 .get_fc_host_stats = lpfc_get_stats,
4398 .reset_fc_host_stats = lpfc_reset_stats,
4400 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4401 .show_rport_maxframe_size = 1,
4402 .show_rport_supported_classes = 1,
4404 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4405 .show_rport_dev_loss_tmo = 1,
4407 .get_starget_port_id = lpfc_get_starget_port_id,
4408 .show_starget_port_id = 1,
4410 .get_starget_node_name = lpfc_get_starget_node_name,
4411 .show_starget_node_name = 1,
4413 .get_starget_port_name = lpfc_get_starget_port_name,
4414 .show_starget_port_name = 1,
4416 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4417 .terminate_rport_io = lpfc_terminate_rport_io,
4419 .vport_disable = lpfc_vport_disable,
4421 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4425 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4426 * @phba: lpfc_hba pointer.
4429 lpfc_get_cfgparam(struct lpfc_hba *phba)
4431 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4432 lpfc_cr_count_init(phba, lpfc_cr_count);
4433 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4434 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4435 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4436 lpfc_ack0_init(phba, lpfc_ack0);
4437 lpfc_topology_init(phba, lpfc_topology);
4438 lpfc_link_speed_init(phba, lpfc_link_speed);
4439 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4440 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4441 lpfc_use_msi_init(phba, lpfc_use_msi);
4442 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4443 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4444 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4445 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4446 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4447 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4448 if (phba->sli_rev == LPFC_SLI_REV4)
4451 phba->cfg_poll = lpfc_poll;
4452 phba->cfg_soft_wwnn = 0L;
4453 phba->cfg_soft_wwpn = 0L;
4454 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4455 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4456 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4457 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4458 lpfc_aer_support_init(phba, lpfc_aer_support);
4464 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4465 * @vport: lpfc_vport pointer.
4468 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4470 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4471 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4472 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4473 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4474 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4475 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4476 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4477 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4478 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4479 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4480 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4481 lpfc_max_luns_init(vport, lpfc_max_luns);
4482 lpfc_scan_down_init(vport, lpfc_scan_down);
4483 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);