1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/aer.h>
27 #include <linux/gfp.h>
28 #include <linux/kernel.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_tcq.h>
34 #include <scsi/scsi_transport_fc.h>
35 #include <scsi/fc/fc_fs.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_version.h"
47 #include "lpfc_compat.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_vport.h"
51 #define LPFC_DEF_DEVLOSS_TMO 30
52 #define LPFC_MIN_DEVLOSS_TMO 1
53 #define LPFC_MAX_DEVLOSS_TMO 255
56 * Write key size should be multiple of 4. If write key is changed
57 * make sure that library write key is also changed.
59 #define LPFC_REG_WRITE_KEY_SIZE 4
60 #define LPFC_REG_WRITE_KEY "EMLX"
63 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
64 * @incr: integer to convert.
65 * @hdw: ascii string holding converted integer plus a string terminator.
68 * JEDEC Joint Electron Device Engineering Council.
69 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
70 * character string. The string is then terminated with a NULL in byte 9.
71 * Hex 0-9 becomes ascii '0' to '9'.
72 * Hex a-f becomes ascii '=' to 'B' capital B.
75 * Coded for 32 bit integers only.
78 lpfc_jedec_to_ascii(int incr, char hdw[])
81 for (i = 0; i < 8; i++) {
84 hdw[7 - i] = 0x30 + j;
86 hdw[7 - i] = 0x61 + j - 10;
94 * lpfc_drvr_version_show - Return the Emulex driver string with version number
95 * @dev: class unused variable.
96 * @attr: device attribute, not used.
97 * @buf: on return contains the module description text.
99 * Returns: size of formatted string.
102 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
105 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
109 * lpfc_enable_fip_show - Return the fip mode of the HBA
110 * @dev: class unused variable.
111 * @attr: device attribute, not used.
112 * @buf: on return contains the module description text.
114 * Returns: size of formatted string.
117 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
120 struct Scsi_Host *shost = class_to_shost(dev);
121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
122 struct lpfc_hba *phba = vport->phba;
124 if (phba->hba_flag & HBA_FIP_SUPPORT)
125 return snprintf(buf, PAGE_SIZE, "1\n");
127 return snprintf(buf, PAGE_SIZE, "0\n");
131 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
134 struct Scsi_Host *shost = class_to_shost(dev);
135 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
136 struct lpfc_hba *phba = vport->phba;
138 if (phba->cfg_enable_bg)
139 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
140 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142 return snprintf(buf, PAGE_SIZE,
143 "BlockGuard Not Supported\n");
145 return snprintf(buf, PAGE_SIZE,
146 "BlockGuard Disabled\n");
150 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
153 struct Scsi_Host *shost = class_to_shost(dev);
154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
155 struct lpfc_hba *phba = vport->phba;
157 return snprintf(buf, PAGE_SIZE, "%llu\n",
158 (unsigned long long)phba->bg_guard_err_cnt);
162 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
165 struct Scsi_Host *shost = class_to_shost(dev);
166 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
167 struct lpfc_hba *phba = vport->phba;
169 return snprintf(buf, PAGE_SIZE, "%llu\n",
170 (unsigned long long)phba->bg_apptag_err_cnt);
174 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
177 struct Scsi_Host *shost = class_to_shost(dev);
178 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
179 struct lpfc_hba *phba = vport->phba;
181 return snprintf(buf, PAGE_SIZE, "%llu\n",
182 (unsigned long long)phba->bg_reftag_err_cnt);
186 * lpfc_info_show - Return some pci info about the host in ascii
187 * @dev: class converted to a Scsi_host structure.
188 * @attr: device attribute, not used.
189 * @buf: on return contains the formatted text from lpfc_info().
191 * Returns: size of formatted string.
194 lpfc_info_show(struct device *dev, struct device_attribute *attr,
197 struct Scsi_Host *host = class_to_shost(dev);
199 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
203 * lpfc_serialnum_show - Return the hba serial number in ascii
204 * @dev: class converted to a Scsi_host structure.
205 * @attr: device attribute, not used.
206 * @buf: on return contains the formatted text serial number.
208 * Returns: size of formatted string.
211 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
214 struct Scsi_Host *shost = class_to_shost(dev);
215 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
216 struct lpfc_hba *phba = vport->phba;
218 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
222 * lpfc_temp_sensor_show - Return the temperature sensor level
223 * @dev: class converted to a Scsi_host structure.
224 * @attr: device attribute, not used.
225 * @buf: on return contains the formatted support level.
228 * Returns a number indicating the temperature sensor level currently
229 * supported, zero or one in ascii.
231 * Returns: size of formatted string.
234 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
237 struct Scsi_Host *shost = class_to_shost(dev);
238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
239 struct lpfc_hba *phba = vport->phba;
240 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
244 * lpfc_modeldesc_show - Return the model description of the hba
245 * @dev: class converted to a Scsi_host structure.
246 * @attr: device attribute, not used.
247 * @buf: on return contains the scsi vpd model description.
249 * Returns: size of formatted string.
252 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
255 struct Scsi_Host *shost = class_to_shost(dev);
256 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
257 struct lpfc_hba *phba = vport->phba;
259 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
263 * lpfc_modelname_show - Return the model name of the hba
264 * @dev: class converted to a Scsi_host structure.
265 * @attr: device attribute, not used.
266 * @buf: on return contains the scsi vpd model name.
268 * Returns: size of formatted string.
271 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
274 struct Scsi_Host *shost = class_to_shost(dev);
275 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
276 struct lpfc_hba *phba = vport->phba;
278 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
282 * lpfc_programtype_show - Return the program type of the hba
283 * @dev: class converted to a Scsi_host structure.
284 * @attr: device attribute, not used.
285 * @buf: on return contains the scsi vpd program type.
287 * Returns: size of formatted string.
290 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
293 struct Scsi_Host *shost = class_to_shost(dev);
294 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
295 struct lpfc_hba *phba = vport->phba;
297 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
301 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
302 * @dev: class converted to a Scsi_host structure.
303 * @attr: device attribute, not used.
304 * @buf: on return contains the Menlo Maintenance sli flag.
306 * Returns: size of formatted string.
309 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311 struct Scsi_Host *shost = class_to_shost(dev);
312 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
313 struct lpfc_hba *phba = vport->phba;
315 return snprintf(buf, PAGE_SIZE, "%d\n",
316 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
320 * lpfc_vportnum_show - Return the port number in ascii of the hba
321 * @dev: class converted to a Scsi_host structure.
322 * @attr: device attribute, not used.
323 * @buf: on return contains scsi vpd program type.
325 * Returns: size of formatted string.
328 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
331 struct Scsi_Host *shost = class_to_shost(dev);
332 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
333 struct lpfc_hba *phba = vport->phba;
335 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
339 * lpfc_fwrev_show - Return the firmware rev running in the hba
340 * @dev: class converted to a Scsi_host structure.
341 * @attr: device attribute, not used.
342 * @buf: on return contains the scsi vpd program type.
344 * Returns: size of formatted string.
347 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
350 struct Scsi_Host *shost = class_to_shost(dev);
351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
352 struct lpfc_hba *phba = vport->phba;
355 lpfc_decode_firmware_rev(phba, fwrev, 1);
356 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
360 * lpfc_hdw_show - Return the jedec information about the hba
361 * @dev: class converted to a Scsi_host structure.
362 * @attr: device attribute, not used.
363 * @buf: on return contains the scsi vpd program type.
365 * Returns: size of formatted string.
368 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
371 struct Scsi_Host *shost = class_to_shost(dev);
372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
373 struct lpfc_hba *phba = vport->phba;
374 lpfc_vpd_t *vp = &phba->vpd;
376 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
377 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
381 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
382 * @dev: class converted to a Scsi_host structure.
383 * @attr: device attribute, not used.
384 * @buf: on return contains the ROM and FCode ascii strings.
386 * Returns: size of formatted string.
389 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
392 struct Scsi_Host *shost = class_to_shost(dev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
396 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
400 * lpfc_state_show - Return the link state of the port
401 * @dev: class converted to a Scsi_host structure.
402 * @attr: device attribute, not used.
403 * @buf: on return contains text describing the state of the link.
406 * The switch statement has no default so zero will be returned.
408 * Returns: size of formatted string.
411 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
414 struct Scsi_Host *shost = class_to_shost(dev);
415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
416 struct lpfc_hba *phba = vport->phba;
419 switch (phba->link_state) {
420 case LPFC_LINK_UNKNOWN:
421 case LPFC_WARM_START:
422 case LPFC_INIT_START:
423 case LPFC_INIT_MBX_CMDS:
426 if (phba->hba_flag & LINK_DISABLED)
427 len += snprintf(buf + len, PAGE_SIZE-len,
428 "Link Down - User disabled\n");
430 len += snprintf(buf + len, PAGE_SIZE-len,
436 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
438 switch (vport->port_state) {
439 case LPFC_LOCAL_CFG_LINK:
440 len += snprintf(buf + len, PAGE_SIZE-len,
441 "Configuring Link\n");
445 case LPFC_FABRIC_CFG_LINK:
448 case LPFC_BUILD_DISC_LIST:
450 len += snprintf(buf + len, PAGE_SIZE - len,
453 case LPFC_VPORT_READY:
454 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
457 case LPFC_VPORT_FAILED:
458 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
461 case LPFC_VPORT_UNKNOWN:
462 len += snprintf(buf + len, PAGE_SIZE - len,
466 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Menlo Maint Mode\n");
469 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
470 if (vport->fc_flag & FC_PUBLIC_LOOP)
471 len += snprintf(buf + len, PAGE_SIZE-len,
474 len += snprintf(buf + len, PAGE_SIZE-len,
477 if (vport->fc_flag & FC_FABRIC)
478 len += snprintf(buf + len, PAGE_SIZE-len,
481 len += snprintf(buf + len, PAGE_SIZE-len,
490 * lpfc_link_state_store - Transition the link_state on an HBA port
491 * @dev: class device that is converted into a Scsi_host.
492 * @attr: device attribute, not used.
493 * @buf: one or more lpfc_polling_flags values.
497 * -EINVAL if the buffer is not "up" or "down"
498 * return from link state change function if non-zero
499 * length of the buf on success
502 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
503 const char *buf, size_t count)
505 struct Scsi_Host *shost = class_to_shost(dev);
506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
507 struct lpfc_hba *phba = vport->phba;
509 int status = -EINVAL;
511 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
512 (phba->link_state == LPFC_LINK_DOWN))
513 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
514 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
515 (phba->link_state >= LPFC_LINK_UP))
516 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
525 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
526 * @dev: class device that is converted into a Scsi_host.
527 * @attr: device attribute, not used.
528 * @buf: on return contains the sum of fc mapped and unmapped.
531 * Returns the ascii text number of the sum of the fc mapped and unmapped
534 * Returns: size of formatted string.
537 lpfc_num_discovered_ports_show(struct device *dev,
538 struct device_attribute *attr, char *buf)
540 struct Scsi_Host *shost = class_to_shost(dev);
541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
543 return snprintf(buf, PAGE_SIZE, "%d\n",
544 vport->fc_map_cnt + vport->fc_unmap_cnt);
548 * lpfc_issue_lip - Misnomer, name carried over from long ago
549 * @shost: Scsi_Host pointer.
552 * Bring the link down gracefully then re-init the link. The firmware will
553 * re-init the fiber channel interface as required. Does not issue a LIP.
556 * -EPERM port offline or management commands are being blocked
557 * -ENOMEM cannot allocate memory for the mailbox command
558 * -EIO error sending the mailbox command
562 lpfc_issue_lip(struct Scsi_Host *shost)
564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
565 struct lpfc_hba *phba = vport->phba;
566 LPFC_MBOXQ_t *pmboxq;
567 int mbxstatus = MBXERR_ERROR;
569 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
570 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
573 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
578 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
579 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
580 pmboxq->u.mb.mbxOwner = OWN_HOST;
582 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
584 if ((mbxstatus == MBX_SUCCESS) &&
585 (pmboxq->u.mb.mbxStatus == 0 ||
586 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
587 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
588 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
589 phba->cfg_link_speed);
590 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
592 if ((mbxstatus == MBX_SUCCESS) &&
593 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
594 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
595 "2859 SLI authentication is required "
596 "for INIT_LINK but has not done yet\n");
599 lpfc_set_loopback_flag(phba);
600 if (mbxstatus != MBX_TIMEOUT)
601 mempool_free(pmboxq, phba->mbox_mem_pool);
603 if (mbxstatus == MBXERR_ERROR)
610 * lpfc_do_offline - Issues a mailbox command to bring the link down
611 * @phba: lpfc_hba pointer.
612 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
615 * Assumes any error from lpfc_do_offline() will be negative.
616 * Can wait up to 5 seconds for the port ring buffers count
617 * to reach zero, prints a warning if it is not zero and continues.
618 * lpfc_workq_post_event() returns a non-zero return code if call fails.
621 * -EIO error posting the event
625 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
627 struct completion online_compl;
628 struct lpfc_sli_ring *pring;
629 struct lpfc_sli *psli;
635 init_completion(&online_compl);
636 rc = lpfc_workq_post_event(phba, &status, &online_compl,
637 LPFC_EVT_OFFLINE_PREP);
641 wait_for_completion(&online_compl);
648 /* Wait a little for things to settle down, but not
649 * long enough for dev loss timeout to expire.
651 for (i = 0; i < psli->num_rings; i++) {
652 pring = &psli->ring[i];
653 while (pring->txcmplq_cnt) {
655 if (cnt++ > 500) { /* 5 secs */
656 lpfc_printf_log(phba,
657 KERN_WARNING, LOG_INIT,
658 "0466 Outstanding IO when "
659 "bringing Adapter offline\n");
665 init_completion(&online_compl);
666 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
670 wait_for_completion(&online_compl);
679 * lpfc_selective_reset - Offline then onlines the port
680 * @phba: lpfc_hba pointer.
683 * If the port is configured to allow a reset then the hba is brought
684 * offline then online.
687 * Assumes any error from lpfc_do_offline() will be negative.
688 * Do not make this function static.
691 * lpfc_do_offline() return code if not zero
692 * -EIO reset not configured or error posting the event
696 lpfc_selective_reset(struct lpfc_hba *phba)
698 struct completion online_compl;
702 if (!phba->cfg_enable_hba_reset)
705 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
710 init_completion(&online_compl);
711 rc = lpfc_workq_post_event(phba, &status, &online_compl,
716 wait_for_completion(&online_compl);
725 * lpfc_issue_reset - Selectively resets an adapter
726 * @dev: class device that is converted into a Scsi_host.
727 * @attr: device attribute, not used.
728 * @buf: containing the string "selective".
729 * @count: unused variable.
732 * If the buf contains the string "selective" then lpfc_selective_reset()
733 * is called to perform the reset.
736 * Assumes any error from lpfc_selective_reset() will be negative.
737 * If lpfc_selective_reset() returns zero then the length of the buffer
738 * is returned which indicates success
741 * -EINVAL if the buffer does not contain the string "selective"
742 * length of buf if lpfc-selective_reset() if the call succeeds
743 * return value of lpfc_selective_reset() if the call fails
746 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
747 const char *buf, size_t count)
749 struct Scsi_Host *shost = class_to_shost(dev);
750 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
751 struct lpfc_hba *phba = vport->phba;
752 int status = -EINVAL;
754 if (!phba->cfg_enable_hba_reset)
757 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
758 status = phba->lpfc_selective_reset(phba);
767 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
768 * @phba: lpfc_hba pointer.
771 * SLI4 interface type-2 device to wait on the sliport status register for
772 * the readyness after performing a firmware reset.
778 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
780 struct lpfc_register portstat_reg = {0};
784 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
785 &portstat_reg.word0);
787 /* verify if privilaged for the request operation */
788 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
789 !bf_get(lpfc_sliport_status_err, &portstat_reg))
792 /* wait for the SLI port firmware ready after firmware reset */
793 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
795 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
796 &portstat_reg.word0);
797 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
799 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
801 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
806 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
813 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
814 * @phba: lpfc_hba pointer.
817 * Request SLI4 interface type-2 device to perform a physical register set
824 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
826 struct completion online_compl;
827 struct pci_dev *pdev = phba->pcidev;
832 if (!phba->cfg_enable_hba_reset)
835 if ((phba->sli_rev < LPFC_SLI_REV4) ||
836 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
837 LPFC_SLI_INTF_IF_TYPE_2))
840 /* Disable SR-IOV virtual functions if enabled */
841 if (phba->cfg_sriov_nr_virtfn) {
842 pci_disable_sriov(pdev);
843 phba->cfg_sriov_nr_virtfn = 0;
845 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
850 /* wait for the device to be quiesced before firmware reset */
853 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
854 LPFC_CTL_PDEV_CTL_OFFSET);
856 if (opcode == LPFC_FW_DUMP)
857 reg_val |= LPFC_FW_DUMP_REQUEST;
858 else if (opcode == LPFC_FW_RESET)
859 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
860 else if (opcode == LPFC_DV_RESET)
861 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
863 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
864 LPFC_CTL_PDEV_CTL_OFFSET);
866 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
868 /* delay driver action following IF_TYPE_2 reset */
869 rc = lpfc_sli4_pdev_status_reg_wait(phba);
874 init_completion(&online_compl);
875 rc = lpfc_workq_post_event(phba, &status, &online_compl,
880 wait_for_completion(&online_compl);
889 * lpfc_nport_evt_cnt_show - Return the number of nport events
890 * @dev: class device that is converted into a Scsi_host.
891 * @attr: device attribute, not used.
892 * @buf: on return contains the ascii number of nport events.
894 * Returns: size of formatted string.
897 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
900 struct Scsi_Host *shost = class_to_shost(dev);
901 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
902 struct lpfc_hba *phba = vport->phba;
904 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
908 * lpfc_board_mode_show - Return the state of the board
909 * @dev: class device that is converted into a Scsi_host.
910 * @attr: device attribute, not used.
911 * @buf: on return contains the state of the adapter.
913 * Returns: size of formatted string.
916 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
919 struct Scsi_Host *shost = class_to_shost(dev);
920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
921 struct lpfc_hba *phba = vport->phba;
924 if (phba->link_state == LPFC_HBA_ERROR)
926 else if (phba->link_state == LPFC_WARM_START)
927 state = "warm start";
928 else if (phba->link_state == LPFC_INIT_START)
933 return snprintf(buf, PAGE_SIZE, "%s\n", state);
937 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
938 * @dev: class device that is converted into a Scsi_host.
939 * @attr: device attribute, not used.
940 * @buf: containing one of the strings "online", "offline", "warm" or "error".
941 * @count: unused variable.
944 * -EACCES if enable hba reset not enabled
945 * -EINVAL if the buffer does not contain a valid string (see above)
946 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
947 * buf length greater than zero indicates success
950 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
951 const char *buf, size_t count)
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;
956 struct completion online_compl;
960 if (!phba->cfg_enable_hba_reset)
963 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
964 "3050 lpfc_board_mode set to %s\n", buf);
966 init_completion(&online_compl);
968 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
969 rc = lpfc_workq_post_event(phba, &status, &online_compl,
973 wait_for_completion(&online_compl);
974 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
975 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
976 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
977 if (phba->sli_rev == LPFC_SLI_REV4)
980 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
981 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
982 if (phba->sli_rev == LPFC_SLI_REV4)
985 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
986 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
987 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
988 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
989 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
990 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
991 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1002 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1003 * @phba: pointer to the adapter structure.
1004 * @mxri: max xri count.
1005 * @axri: available xri count.
1006 * @mrpi: max rpi count.
1007 * @arpi: available rpi count.
1008 * @mvpi: max vpi count.
1009 * @avpi: available vpi count.
1012 * If an integer pointer for an count is not null then the value for the
1013 * count is returned.
1020 lpfc_get_hba_info(struct lpfc_hba *phba,
1021 uint32_t *mxri, uint32_t *axri,
1022 uint32_t *mrpi, uint32_t *arpi,
1023 uint32_t *mvpi, uint32_t *avpi)
1025 struct lpfc_mbx_read_config *rd_config;
1026 LPFC_MBOXQ_t *pmboxq;
1032 * prevent udev from issuing mailbox commands until the port is
1035 if (phba->link_state < LPFC_LINK_DOWN ||
1036 !phba->mbox_mem_pool ||
1037 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1040 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1043 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1046 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1048 pmb = &pmboxq->u.mb;
1049 pmb->mbxCommand = MBX_READ_CONFIG;
1050 pmb->mbxOwner = OWN_HOST;
1051 pmboxq->context1 = NULL;
1053 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1054 rc = MBX_NOT_FINISHED;
1056 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1058 if (rc != MBX_SUCCESS) {
1059 if (rc != MBX_TIMEOUT)
1060 mempool_free(pmboxq, phba->mbox_mem_pool);
1064 if (phba->sli_rev == LPFC_SLI_REV4) {
1065 rd_config = &pmboxq->u.mqe.un.rd_config;
1067 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1069 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1070 phba->sli4_hba.max_cfg_param.rpi_used;
1072 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1074 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1075 phba->sli4_hba.max_cfg_param.xri_used;
1077 /* Account for differences with SLI-3. Get vpi count from
1078 * mailbox data and subtract one for max vpi value.
1080 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1081 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1086 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1089 *mrpi = pmb->un.varRdConfig.max_rpi;
1091 *arpi = pmb->un.varRdConfig.avail_rpi;
1093 *mxri = pmb->un.varRdConfig.max_xri;
1095 *axri = pmb->un.varRdConfig.avail_xri;
1097 *mvpi = pmb->un.varRdConfig.max_vpi;
1099 *avpi = pmb->un.varRdConfig.avail_vpi;
1102 mempool_free(pmboxq, phba->mbox_mem_pool);
1107 * lpfc_max_rpi_show - Return maximum rpi
1108 * @dev: class device that is converted into a Scsi_host.
1109 * @attr: device attribute, not used.
1110 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1113 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1114 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1115 * to "Unknown" and the buffer length is returned, therefore the caller
1116 * must check for "Unknown" in the buffer to detect a failure.
1118 * Returns: size of formatted string.
1121 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1124 struct Scsi_Host *shost = class_to_shost(dev);
1125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1126 struct lpfc_hba *phba = vport->phba;
1129 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1130 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1131 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1135 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1136 * @dev: class device that is converted into a Scsi_host.
1137 * @attr: device attribute, not used.
1138 * @buf: containing the used rpi count in decimal or "Unknown".
1141 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1142 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1143 * to "Unknown" and the buffer length is returned, therefore the caller
1144 * must check for "Unknown" in the buffer to detect a failure.
1146 * Returns: size of formatted string.
1149 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1152 struct Scsi_Host *shost = class_to_shost(dev);
1153 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1154 struct lpfc_hba *phba = vport->phba;
1157 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1158 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1159 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1163 * lpfc_max_xri_show - Return maximum xri
1164 * @dev: class device that is converted into a Scsi_host.
1165 * @attr: device attribute, not used.
1166 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1169 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1170 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1171 * to "Unknown" and the buffer length is returned, therefore the caller
1172 * must check for "Unknown" in the buffer to detect a failure.
1174 * Returns: size of formatted string.
1177 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1180 struct Scsi_Host *shost = class_to_shost(dev);
1181 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1182 struct lpfc_hba *phba = vport->phba;
1185 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1186 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1187 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1191 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1192 * @dev: class device that is converted into a Scsi_host.
1193 * @attr: device attribute, not used.
1194 * @buf: on return contains the used xri count in decimal or "Unknown".
1197 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1198 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1199 * to "Unknown" and the buffer length is returned, therefore the caller
1200 * must check for "Unknown" in the buffer to detect a failure.
1202 * Returns: size of formatted string.
1205 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1208 struct Scsi_Host *shost = class_to_shost(dev);
1209 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1210 struct lpfc_hba *phba = vport->phba;
1213 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1214 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1215 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1219 * lpfc_max_vpi_show - Return maximum vpi
1220 * @dev: class device that is converted into a Scsi_host.
1221 * @attr: device attribute, not used.
1222 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1225 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1226 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1227 * to "Unknown" and the buffer length is returned, therefore the caller
1228 * must check for "Unknown" in the buffer to detect a failure.
1230 * Returns: size of formatted string.
1233 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1236 struct Scsi_Host *shost = class_to_shost(dev);
1237 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1238 struct lpfc_hba *phba = vport->phba;
1241 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1242 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1243 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1247 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1248 * @dev: class device that is converted into a Scsi_host.
1249 * @attr: device attribute, not used.
1250 * @buf: on return contains the used vpi count in decimal or "Unknown".
1253 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1254 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1255 * to "Unknown" and the buffer length is returned, therefore the caller
1256 * must check for "Unknown" in the buffer to detect a failure.
1258 * Returns: size of formatted string.
1261 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1264 struct Scsi_Host *shost = class_to_shost(dev);
1265 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1266 struct lpfc_hba *phba = vport->phba;
1269 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1270 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1271 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1275 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1276 * @dev: class device that is converted into a Scsi_host.
1277 * @attr: device attribute, not used.
1278 * @buf: text that must be interpreted to determine if npiv is supported.
1281 * Buffer will contain text indicating npiv is not suppoerted on the port,
1282 * the port is an NPIV physical port, or it is an npiv virtual port with
1283 * the id of the vport.
1285 * Returns: size of formatted string.
1288 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1291 struct Scsi_Host *shost = class_to_shost(dev);
1292 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1293 struct lpfc_hba *phba = vport->phba;
1295 if (!(phba->max_vpi))
1296 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1297 if (vport->port_type == LPFC_PHYSICAL_PORT)
1298 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1299 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1303 * lpfc_poll_show - Return text about poll support for the adapter
1304 * @dev: class device that is converted into a Scsi_host.
1305 * @attr: device attribute, not used.
1306 * @buf: on return contains the cfg_poll in hex.
1309 * cfg_poll should be a lpfc_polling_flags type.
1311 * Returns: size of formatted string.
1314 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1317 struct Scsi_Host *shost = class_to_shost(dev);
1318 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1319 struct lpfc_hba *phba = vport->phba;
1321 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1325 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1326 * @dev: class device that is converted into a Scsi_host.
1327 * @attr: device attribute, not used.
1328 * @buf: one or more lpfc_polling_flags values.
1332 * buf contents converted to integer and checked for a valid value.
1335 * -EINVAL if the buffer connot be converted or is out of range
1336 * length of the buf on success
1339 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1340 const char *buf, size_t count)
1342 struct Scsi_Host *shost = class_to_shost(dev);
1343 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1344 struct lpfc_hba *phba = vport->phba;
1349 if (!isdigit(buf[0]))
1352 if (sscanf(buf, "%i", &val) != 1)
1355 if ((val & 0x3) != val)
1358 if (phba->sli_rev == LPFC_SLI_REV4)
1361 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1362 "3051 lpfc_poll changed from %d to %d\n",
1363 phba->cfg_poll, val);
1365 spin_lock_irq(&phba->hbalock);
1367 old_val = phba->cfg_poll;
1369 if (val & ENABLE_FCP_RING_POLLING) {
1370 if ((val & DISABLE_FCP_RING_INT) &&
1371 !(old_val & DISABLE_FCP_RING_INT)) {
1372 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1373 spin_unlock_irq(&phba->hbalock);
1376 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1377 writel(creg_val, phba->HCregaddr);
1378 readl(phba->HCregaddr); /* flush */
1380 lpfc_poll_start_timer(phba);
1382 } else if (val != 0x0) {
1383 spin_unlock_irq(&phba->hbalock);
1387 if (!(val & DISABLE_FCP_RING_INT) &&
1388 (old_val & DISABLE_FCP_RING_INT))
1390 spin_unlock_irq(&phba->hbalock);
1391 del_timer(&phba->fcp_poll_timer);
1392 spin_lock_irq(&phba->hbalock);
1393 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1394 spin_unlock_irq(&phba->hbalock);
1397 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1398 writel(creg_val, phba->HCregaddr);
1399 readl(phba->HCregaddr); /* flush */
1402 phba->cfg_poll = val;
1404 spin_unlock_irq(&phba->hbalock);
1410 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1411 * @dev: class unused variable.
1412 * @attr: device attribute, not used.
1413 * @buf: on return contains the module description text.
1415 * Returns: size of formatted string.
1418 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1421 struct Scsi_Host *shost = class_to_shost(dev);
1422 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1423 struct lpfc_hba *phba = vport->phba;
1425 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1429 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1430 * @dev: class unused variable.
1431 * @attr: device attribute, not used.
1432 * @buf: on return contains the module description text.
1434 * Returns: size of formatted string.
1437 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1440 struct Scsi_Host *shost = class_to_shost(dev);
1441 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1442 struct lpfc_hba *phba = vport->phba;
1444 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1448 * lpfc_dss_show - Return the current state of dss and the configured state
1449 * @dev: class converted to a Scsi_host structure.
1450 * @attr: device attribute, not used.
1451 * @buf: on return contains the formatted text.
1453 * Returns: size of formatted string.
1456 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1459 struct Scsi_Host *shost = class_to_shost(dev);
1460 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1461 struct lpfc_hba *phba = vport->phba;
1463 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1464 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1465 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1470 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1471 * @dev: class converted to a Scsi_host structure.
1472 * @attr: device attribute, not used.
1473 * @buf: on return contains the formatted support level.
1476 * Returns the maximum number of virtual functions a physical function can
1477 * support, 0 will be returned if called on virtual function.
1479 * Returns: size of formatted string.
1482 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1483 struct device_attribute *attr,
1486 struct Scsi_Host *shost = class_to_shost(dev);
1487 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1488 struct lpfc_hba *phba = vport->phba;
1489 uint16_t max_nr_virtfn;
1491 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1492 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1496 * lpfc_param_show - Return a cfg attribute value in decimal
1499 * Macro that given an attr e.g. hba_queue_depth expands
1500 * into a function with the name lpfc_hba_queue_depth_show.
1502 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1503 * @dev: class device that is converted into a Scsi_host.
1504 * @attr: device attribute, not used.
1505 * @buf: on return contains the attribute value in decimal.
1507 * Returns: size of formatted string.
1509 #define lpfc_param_show(attr) \
1511 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1514 struct Scsi_Host *shost = class_to_shost(dev);\
1515 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1516 struct lpfc_hba *phba = vport->phba;\
1518 val = phba->cfg_##attr;\
1519 return snprintf(buf, PAGE_SIZE, "%d\n",\
1524 * lpfc_param_hex_show - Return a cfg attribute value in hex
1527 * Macro that given an attr e.g. hba_queue_depth expands
1528 * into a function with the name lpfc_hba_queue_depth_show
1530 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1531 * @dev: class device that is converted into a Scsi_host.
1532 * @attr: device attribute, not used.
1533 * @buf: on return contains the attribute value in hexadecimal.
1535 * Returns: size of formatted string.
1537 #define lpfc_param_hex_show(attr) \
1539 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1542 struct Scsi_Host *shost = class_to_shost(dev);\
1543 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1544 struct lpfc_hba *phba = vport->phba;\
1546 val = phba->cfg_##attr;\
1547 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1552 * lpfc_param_init - Initializes a cfg attribute
1555 * Macro that given an attr e.g. hba_queue_depth expands
1556 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1557 * takes a default argument, a minimum and maximum argument.
1559 * lpfc_##attr##_init: Initializes an attribute.
1560 * @phba: pointer the the adapter structure.
1561 * @val: integer attribute value.
1563 * Validates the min and max values then sets the adapter config field
1564 * accordingly, or uses the default if out of range and prints an error message.
1568 * -EINVAL if default used
1570 #define lpfc_param_init(attr, default, minval, maxval) \
1572 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1574 if (val >= minval && val <= maxval) {\
1575 phba->cfg_##attr = val;\
1578 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1579 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1580 "allowed range is ["#minval", "#maxval"]\n", val); \
1581 phba->cfg_##attr = default;\
1586 * lpfc_param_set - Set a cfg attribute value
1589 * Macro that given an attr e.g. hba_queue_depth expands
1590 * into a function with the name lpfc_hba_queue_depth_set
1592 * lpfc_##attr##_set: Sets an attribute value.
1593 * @phba: pointer the the adapter structure.
1594 * @val: integer attribute value.
1597 * Validates the min and max values then sets the
1598 * adapter config field if in the valid range. prints error message
1599 * and does not set the parameter if invalid.
1603 * -EINVAL if val is invalid
1605 #define lpfc_param_set(attr, default, minval, maxval) \
1607 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1609 if (val >= minval && val <= maxval) {\
1610 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1611 "3052 lpfc_" #attr " changed from %d to %d\n", \
1612 phba->cfg_##attr, val); \
1613 phba->cfg_##attr = val;\
1616 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1617 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1618 "allowed range is ["#minval", "#maxval"]\n", val); \
1623 * lpfc_param_store - Set a vport attribute value
1626 * Macro that given an attr e.g. hba_queue_depth expands
1627 * into a function with the name lpfc_hba_queue_depth_store.
1629 * lpfc_##attr##_store: Set an sttribute value.
1630 * @dev: class device that is converted into a Scsi_host.
1631 * @attr: device attribute, not used.
1632 * @buf: contains the attribute value in ascii.
1636 * Convert the ascii text number to an integer, then
1637 * use the lpfc_##attr##_set function to set the value.
1640 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1641 * length of buffer upon success.
1643 #define lpfc_param_store(attr) \
1645 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1646 const char *buf, size_t count) \
1648 struct Scsi_Host *shost = class_to_shost(dev);\
1649 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1650 struct lpfc_hba *phba = vport->phba;\
1652 if (!isdigit(buf[0]))\
1654 if (sscanf(buf, "%i", &val) != 1)\
1656 if (lpfc_##attr##_set(phba, val) == 0) \
1657 return strlen(buf);\
1663 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1666 * Macro that given an attr e.g. hba_queue_depth expands
1667 * into a function with the name lpfc_hba_queue_depth_show
1669 * lpfc_##attr##_show: prints the attribute value in decimal.
1670 * @dev: class device that is converted into a Scsi_host.
1671 * @attr: device attribute, not used.
1672 * @buf: on return contains the attribute value in decimal.
1674 * Returns: length of formatted string.
1676 #define lpfc_vport_param_show(attr) \
1678 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1681 struct Scsi_Host *shost = class_to_shost(dev);\
1682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1684 val = vport->cfg_##attr;\
1685 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1689 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1692 * Macro that given an attr e.g.
1693 * hba_queue_depth expands into a function with the name
1694 * lpfc_hba_queue_depth_show
1696 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1697 * @dev: class device that is converted into a Scsi_host.
1698 * @attr: device attribute, not used.
1699 * @buf: on return contains the attribute value in hexadecimal.
1701 * Returns: length of formatted string.
1703 #define lpfc_vport_param_hex_show(attr) \
1705 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1708 struct Scsi_Host *shost = class_to_shost(dev);\
1709 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1711 val = vport->cfg_##attr;\
1712 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1716 * lpfc_vport_param_init - Initialize a vport cfg attribute
1719 * Macro that given an attr e.g. hba_queue_depth expands
1720 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1721 * takes a default argument, a minimum and maximum argument.
1723 * lpfc_##attr##_init: validates the min and max values then sets the
1724 * adapter config field accordingly, or uses the default if out of range
1725 * and prints an error message.
1726 * @phba: pointer the the adapter structure.
1727 * @val: integer attribute value.
1731 * -EINVAL if default used
1733 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1735 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1737 if (val >= minval && val <= maxval) {\
1738 vport->cfg_##attr = val;\
1741 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1742 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1743 "allowed range is ["#minval", "#maxval"]\n", val); \
1744 vport->cfg_##attr = default;\
1749 * lpfc_vport_param_set - Set a vport cfg attribute
1752 * Macro that given an attr e.g. hba_queue_depth expands
1753 * into a function with the name lpfc_hba_queue_depth_set
1755 * lpfc_##attr##_set: validates the min and max values then sets the
1756 * adapter config field if in the valid range. prints error message
1757 * and does not set the parameter if invalid.
1758 * @phba: pointer the the adapter structure.
1759 * @val: integer attribute value.
1763 * -EINVAL if val is invalid
1765 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1767 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1769 if (val >= minval && val <= maxval) {\
1770 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1771 "3053 lpfc_" #attr " changed from %d to %d\n", \
1772 vport->cfg_##attr, val); \
1773 vport->cfg_##attr = val;\
1776 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1777 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1778 "allowed range is ["#minval", "#maxval"]\n", val); \
1783 * lpfc_vport_param_store - Set a vport attribute
1786 * Macro that given an attr e.g. hba_queue_depth
1787 * expands into a function with the name lpfc_hba_queue_depth_store
1789 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1790 * use the lpfc_##attr##_set function to set the value.
1791 * @cdev: class device that is converted into a Scsi_host.
1792 * @buf: contains the attribute value in decimal.
1796 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1797 * length of buffer upon success.
1799 #define lpfc_vport_param_store(attr) \
1801 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1802 const char *buf, size_t count) \
1804 struct Scsi_Host *shost = class_to_shost(dev);\
1805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1807 if (!isdigit(buf[0]))\
1809 if (sscanf(buf, "%i", &val) != 1)\
1811 if (lpfc_##attr##_set(vport, val) == 0) \
1812 return strlen(buf);\
1818 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1819 static uint lpfc_##name = defval;\
1820 module_param(lpfc_##name, uint, S_IRUGO);\
1821 MODULE_PARM_DESC(lpfc_##name, desc);\
1822 lpfc_param_init(name, defval, minval, maxval)
1824 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1825 static uint lpfc_##name = defval;\
1826 module_param(lpfc_##name, uint, S_IRUGO);\
1827 MODULE_PARM_DESC(lpfc_##name, desc);\
1828 lpfc_param_show(name)\
1829 lpfc_param_init(name, defval, minval, maxval)\
1830 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1832 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1833 static uint lpfc_##name = defval;\
1834 module_param(lpfc_##name, uint, S_IRUGO);\
1835 MODULE_PARM_DESC(lpfc_##name, desc);\
1836 lpfc_param_show(name)\
1837 lpfc_param_init(name, defval, minval, maxval)\
1838 lpfc_param_set(name, defval, minval, maxval)\
1839 lpfc_param_store(name)\
1840 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1841 lpfc_##name##_show, lpfc_##name##_store)
1843 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1844 static uint lpfc_##name = defval;\
1845 module_param(lpfc_##name, uint, S_IRUGO);\
1846 MODULE_PARM_DESC(lpfc_##name, desc);\
1847 lpfc_param_hex_show(name)\
1848 lpfc_param_init(name, defval, minval, maxval)\
1849 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1851 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1852 static uint lpfc_##name = defval;\
1853 module_param(lpfc_##name, uint, S_IRUGO);\
1854 MODULE_PARM_DESC(lpfc_##name, desc);\
1855 lpfc_param_hex_show(name)\
1856 lpfc_param_init(name, defval, minval, maxval)\
1857 lpfc_param_set(name, defval, minval, maxval)\
1858 lpfc_param_store(name)\
1859 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1860 lpfc_##name##_show, lpfc_##name##_store)
1862 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1863 static uint lpfc_##name = defval;\
1864 module_param(lpfc_##name, uint, S_IRUGO);\
1865 MODULE_PARM_DESC(lpfc_##name, desc);\
1866 lpfc_vport_param_init(name, defval, minval, maxval)
1868 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1869 static uint lpfc_##name = defval;\
1870 module_param(lpfc_##name, uint, S_IRUGO);\
1871 MODULE_PARM_DESC(lpfc_##name, desc);\
1872 lpfc_vport_param_show(name)\
1873 lpfc_vport_param_init(name, defval, minval, maxval)\
1874 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1876 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1877 static uint lpfc_##name = defval;\
1878 module_param(lpfc_##name, uint, S_IRUGO);\
1879 MODULE_PARM_DESC(lpfc_##name, desc);\
1880 lpfc_vport_param_show(name)\
1881 lpfc_vport_param_init(name, defval, minval, maxval)\
1882 lpfc_vport_param_set(name, defval, minval, maxval)\
1883 lpfc_vport_param_store(name)\
1884 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1885 lpfc_##name##_show, lpfc_##name##_store)
1887 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1888 static uint lpfc_##name = defval;\
1889 module_param(lpfc_##name, uint, S_IRUGO);\
1890 MODULE_PARM_DESC(lpfc_##name, desc);\
1891 lpfc_vport_param_hex_show(name)\
1892 lpfc_vport_param_init(name, defval, minval, maxval)\
1893 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1895 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1896 static uint lpfc_##name = defval;\
1897 module_param(lpfc_##name, uint, S_IRUGO);\
1898 MODULE_PARM_DESC(lpfc_##name, desc);\
1899 lpfc_vport_param_hex_show(name)\
1900 lpfc_vport_param_init(name, defval, minval, maxval)\
1901 lpfc_vport_param_set(name, defval, minval, maxval)\
1902 lpfc_vport_param_store(name)\
1903 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1904 lpfc_##name##_show, lpfc_##name##_store)
1906 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1907 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1908 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1909 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1910 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1911 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1912 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1913 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1914 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1915 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1916 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1917 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1918 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1919 lpfc_link_state_store);
1920 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1921 lpfc_option_rom_version_show, NULL);
1922 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1923 lpfc_num_discovered_ports_show, NULL);
1924 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1925 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1926 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1927 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1928 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1929 lpfc_board_mode_show, lpfc_board_mode_store);
1930 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1931 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1932 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1933 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1934 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1935 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1936 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1937 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1938 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1939 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1940 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1941 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1942 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1943 lpfc_sriov_hw_max_virtfn_show, NULL);
1945 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1948 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1949 * @dev: class device that is converted into a Scsi_host.
1950 * @attr: device attribute, not used.
1951 * @buf: containing the string lpfc_soft_wwn_key.
1952 * @count: must be size of lpfc_soft_wwn_key.
1955 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1956 * length of buf indicates success
1959 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1960 const char *buf, size_t count)
1962 struct Scsi_Host *shost = class_to_shost(dev);
1963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1964 struct lpfc_hba *phba = vport->phba;
1965 unsigned int cnt = count;
1968 * We're doing a simple sanity check for soft_wwpn setting.
1969 * We require that the user write a specific key to enable
1970 * the soft_wwpn attribute to be settable. Once the attribute
1971 * is written, the enable key resets. If further updates are
1972 * desired, the key must be written again to re-enable the
1975 * The "key" is not secret - it is a hardcoded string shown
1976 * here. The intent is to protect against the random user or
1977 * application that is just writing attributes.
1980 /* count may include a LF at end of string */
1981 if (buf[cnt-1] == '\n')
1984 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1985 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1988 phba->soft_wwn_enable = 1;
1991 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1992 lpfc_soft_wwn_enable_store);
1995 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1996 * @dev: class device that is converted into a Scsi_host.
1997 * @attr: device attribute, not used.
1998 * @buf: on return contains the wwpn in hexadecimal.
2000 * Returns: size of formatted string.
2003 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2006 struct Scsi_Host *shost = class_to_shost(dev);
2007 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2008 struct lpfc_hba *phba = vport->phba;
2010 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2011 (unsigned long long)phba->cfg_soft_wwpn);
2015 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2016 * @dev class device that is converted into a Scsi_host.
2017 * @attr: device attribute, not used.
2018 * @buf: contains the wwpn in hexadecimal.
2019 * @count: number of wwpn bytes in buf
2022 * -EACCES hba reset not enabled, adapter over temp
2023 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2024 * -EIO error taking adapter offline or online
2025 * value of count on success
2028 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2029 const char *buf, size_t count)
2031 struct Scsi_Host *shost = class_to_shost(dev);
2032 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2033 struct lpfc_hba *phba = vport->phba;
2034 struct completion online_compl;
2035 int stat1=0, stat2=0;
2036 unsigned int i, j, cnt=count;
2040 if (!phba->cfg_enable_hba_reset)
2042 spin_lock_irq(&phba->hbalock);
2043 if (phba->over_temp_state == HBA_OVER_TEMP) {
2044 spin_unlock_irq(&phba->hbalock);
2047 spin_unlock_irq(&phba->hbalock);
2048 /* count may include a LF at end of string */
2049 if (buf[cnt-1] == '\n')
2052 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2053 ((cnt == 17) && (*buf++ != 'x')) ||
2054 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2057 phba->soft_wwn_enable = 0;
2059 memset(wwpn, 0, sizeof(wwpn));
2061 /* Validate and store the new name */
2062 for (i=0, j=0; i < 16; i++) {
2065 value = hex_to_bin(*buf++);
2067 j = (j << 4) | value;
2071 wwpn[i/2] = j & 0xff;
2075 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2076 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2077 if (phba->cfg_soft_wwnn)
2078 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2080 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2081 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2083 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2086 "0463 lpfc_soft_wwpn attribute set failed to "
2087 "reinit adapter - %d\n", stat1);
2088 init_completion(&online_compl);
2089 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2094 wait_for_completion(&online_compl);
2096 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2097 "0464 lpfc_soft_wwpn attribute set failed to "
2098 "reinit adapter - %d\n", stat2);
2099 return (stat1 || stat2) ? -EIO : count;
2101 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2102 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2105 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2106 * @dev: class device that is converted into a Scsi_host.
2107 * @attr: device attribute, not used.
2108 * @buf: on return contains the wwnn in hexadecimal.
2110 * Returns: size of formatted string.
2113 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2116 struct Scsi_Host *shost = class_to_shost(dev);
2117 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2118 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2119 (unsigned long long)phba->cfg_soft_wwnn);
2123 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2124 * @cdev: class device that is converted into a Scsi_host.
2125 * @buf: contains the ww node name in hexadecimal.
2126 * @count: number of wwnn bytes in buf.
2129 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2130 * value of count on success
2133 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2134 const char *buf, size_t count)
2136 struct Scsi_Host *shost = class_to_shost(dev);
2137 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2138 unsigned int i, j, cnt=count;
2141 /* count may include a LF at end of string */
2142 if (buf[cnt-1] == '\n')
2145 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2146 ((cnt == 17) && (*buf++ != 'x')) ||
2147 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2151 * Allow wwnn to be set many times, as long as the enable is set.
2152 * However, once the wwpn is set, everything locks.
2155 memset(wwnn, 0, sizeof(wwnn));
2157 /* Validate and store the new name */
2158 for (i=0, j=0; i < 16; i++) {
2161 value = hex_to_bin(*buf++);
2163 j = (j << 4) | value;
2167 wwnn[i/2] = j & 0xff;
2171 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2173 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2174 "lpfc%d: soft_wwnn set. Value will take effect upon "
2175 "setting of the soft_wwpn\n", phba->brd_no);
2179 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2180 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2183 static int lpfc_poll = 0;
2184 module_param(lpfc_poll, int, S_IRUGO);
2185 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2187 " 1 - poll with interrupts enabled"
2188 " 3 - poll and disable FCP ring interrupts");
2190 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2191 lpfc_poll_show, lpfc_poll_store);
2193 int lpfc_sli_mode = 0;
2194 module_param(lpfc_sli_mode, int, S_IRUGO);
2195 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2196 " 0 - auto (SLI-3 if supported),"
2197 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2198 " 3 - select SLI-3");
2200 int lpfc_enable_npiv = 1;
2201 module_param(lpfc_enable_npiv, int, S_IRUGO);
2202 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2203 lpfc_param_show(enable_npiv);
2204 lpfc_param_init(enable_npiv, 1, 0, 1);
2205 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2207 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2208 "FCF Fast failover=1 Priority failover=2");
2210 int lpfc_enable_rrq;
2211 module_param(lpfc_enable_rrq, int, S_IRUGO);
2212 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2213 lpfc_param_show(enable_rrq);
2214 lpfc_param_init(enable_rrq, 0, 0, 1);
2215 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2218 # lpfc_suppress_link_up: Bring link up at initialization
2219 # 0x0 = bring link up (issue MBX_INIT_LINK)
2220 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2221 # 0x2 = never bring up link
2222 # Default value is 0.
2224 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2225 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2226 "Suppress Link Up at initialization");
2228 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2236 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2238 struct Scsi_Host *shost = class_to_shost(dev);
2239 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2241 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2244 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2245 lpfc_iocb_hw_show, NULL);
2247 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2249 struct Scsi_Host *shost = class_to_shost(dev);
2250 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2252 return snprintf(buf, PAGE_SIZE, "%d\n",
2253 phba->sli.ring[LPFC_ELS_RING].txq_max);
2256 static DEVICE_ATTR(txq_hw, S_IRUGO,
2257 lpfc_txq_hw_show, NULL);
2259 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2262 struct Scsi_Host *shost = class_to_shost(dev);
2263 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2265 return snprintf(buf, PAGE_SIZE, "%d\n",
2266 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2269 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2270 lpfc_txcmplq_hw_show, NULL);
2272 int lpfc_iocb_cnt = 2;
2273 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2274 MODULE_PARM_DESC(lpfc_iocb_cnt,
2275 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2276 lpfc_param_show(iocb_cnt);
2277 lpfc_param_init(iocb_cnt, 2, 1, 5);
2278 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2279 lpfc_iocb_cnt_show, NULL);
2282 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2283 # until the timer expires. Value range is [0,255]. Default value is 30.
2285 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2286 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2287 module_param(lpfc_nodev_tmo, int, 0);
2288 MODULE_PARM_DESC(lpfc_nodev_tmo,
2289 "Seconds driver will hold I/O waiting "
2290 "for a device to come back");
2293 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2294 * @dev: class converted to a Scsi_host structure.
2295 * @attr: device attribute, not used.
2296 * @buf: on return contains the dev loss timeout in decimal.
2298 * Returns: size of formatted string.
2301 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2304 struct Scsi_Host *shost = class_to_shost(dev);
2305 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2307 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2311 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2312 * @vport: lpfc vport structure pointer.
2313 * @val: contains the nodev timeout value.
2316 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2317 * a kernel error message is printed and zero is returned.
2318 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2319 * Otherwise nodev tmo is set to the default value.
2322 * zero if already set or if val is in range
2323 * -EINVAL val out of range
2326 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2328 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2329 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2330 if (val != LPFC_DEF_DEVLOSS_TMO)
2331 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2332 "0407 Ignoring nodev_tmo module "
2333 "parameter because devloss_tmo is "
2338 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2339 vport->cfg_nodev_tmo = val;
2340 vport->cfg_devloss_tmo = val;
2343 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2344 "0400 lpfc_nodev_tmo attribute cannot be set to"
2345 " %d, allowed range is [%d, %d]\n",
2346 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2347 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2352 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2353 * @vport: lpfc vport structure pointer.
2356 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2359 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2361 struct Scsi_Host *shost;
2362 struct lpfc_nodelist *ndlp;
2364 shost = lpfc_shost_from_vport(vport);
2365 spin_lock_irq(shost->host_lock);
2366 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2367 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2368 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2369 spin_unlock_irq(shost->host_lock);
2373 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2374 * @vport: lpfc vport structure pointer.
2375 * @val: contains the tmo value.
2378 * If the devloss tmo is already set or the vport dev loss tmo has changed
2379 * then a kernel error message is printed and zero is returned.
2380 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2381 * Otherwise nodev tmo is set to the default value.
2384 * zero if already set or if val is in range
2385 * -EINVAL val out of range
2388 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2390 if (vport->dev_loss_tmo_changed ||
2391 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2392 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2393 "0401 Ignoring change to nodev_tmo "
2394 "because devloss_tmo is set.\n");
2397 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2398 vport->cfg_nodev_tmo = val;
2399 vport->cfg_devloss_tmo = val;
2401 * For compat: set the fc_host dev loss so new rports
2402 * will get the value.
2404 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2405 lpfc_update_rport_devloss_tmo(vport);
2408 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2409 "0403 lpfc_nodev_tmo attribute cannot be set to"
2410 "%d, allowed range is [%d, %d]\n",
2411 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2415 lpfc_vport_param_store(nodev_tmo)
2417 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2418 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2421 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2422 # disappear until the timer expires. Value range is [0,255]. Default
2425 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2426 MODULE_PARM_DESC(lpfc_devloss_tmo,
2427 "Seconds driver will hold I/O waiting "
2428 "for a device to come back");
2429 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2430 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2431 lpfc_vport_param_show(devloss_tmo)
2434 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2435 * @vport: lpfc vport structure pointer.
2436 * @val: contains the tmo value.
2439 * If val is in a valid range then set the vport nodev tmo,
2440 * devloss tmo, also set the vport dev loss tmo changed flag.
2441 * Else a kernel error message is printed.
2444 * zero if val is in range
2445 * -EINVAL val out of range
2448 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2450 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2451 vport->cfg_nodev_tmo = val;
2452 vport->cfg_devloss_tmo = val;
2453 vport->dev_loss_tmo_changed = 1;
2454 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2455 lpfc_update_rport_devloss_tmo(vport);
2459 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2460 "0404 lpfc_devloss_tmo attribute cannot be set to"
2461 " %d, allowed range is [%d, %d]\n",
2462 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2466 lpfc_vport_param_store(devloss_tmo)
2467 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2468 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2471 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2472 # deluged with LOTS of information.
2473 # You can set a bit mask to record specific types of verbose messages:
2474 # See lpfc_logmsh.h for definitions.
2476 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2477 "Verbose logging bit-mask");
2480 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2481 # objects that have been registered with the nameserver after login.
2483 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2484 "Deregister nameserver objects before LOGO");
2487 # lun_queue_depth: This parameter is used to limit the number of outstanding
2488 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2490 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2491 "Max number of FCP commands we can queue to a specific LUN");
2494 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2495 # commands per target port. Value range is [10,65535]. Default value is 65535.
2497 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2498 "Max number of FCP commands we can queue to a specific target port");
2501 # hba_queue_depth: This parameter is used to limit the number of outstanding
2502 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2503 # value is greater than the maximum number of exchanges supported by the HBA,
2504 # then maximum number of exchanges supported by the HBA is used to determine
2505 # the hba_queue_depth.
2507 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2508 "Max number of FCP commands we can queue to a lpfc HBA");
2511 # peer_port_login: This parameter allows/prevents logins
2512 # between peer ports hosted on the same physical port.
2513 # When this parameter is set 0 peer ports of same physical port
2514 # are not allowed to login to each other.
2515 # When this parameter is set 1 peer ports of same physical port
2516 # are allowed to login to each other.
2517 # Default value of this parameter is 0.
2519 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2520 "Allow peer ports on the same physical port to login to each "
2524 # restrict_login: This parameter allows/prevents logins
2525 # between Virtual Ports and remote initiators.
2526 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2527 # other initiators and will attempt to PLOGI all remote ports.
2528 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2529 # remote ports and will not attempt to PLOGI to other initiators.
2530 # This parameter does not restrict to the physical port.
2531 # This parameter does not restrict logins to Fabric resident remote ports.
2532 # Default value of this parameter is 1.
2534 static int lpfc_restrict_login = 1;
2535 module_param(lpfc_restrict_login, int, S_IRUGO);
2536 MODULE_PARM_DESC(lpfc_restrict_login,
2537 "Restrict virtual ports login to remote initiators.");
2538 lpfc_vport_param_show(restrict_login);
2541 * lpfc_restrict_login_init - Set the vport restrict login flag
2542 * @vport: lpfc vport structure pointer.
2543 * @val: contains the restrict login value.
2546 * If val is not in a valid range then log a kernel error message and set
2547 * the vport restrict login to one.
2548 * If the port type is physical clear the restrict login flag and return.
2549 * Else set the restrict login flag to val.
2552 * zero if val is in range
2553 * -EINVAL val out of range
2556 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2558 if (val < 0 || val > 1) {
2559 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2560 "0422 lpfc_restrict_login attribute cannot "
2561 "be set to %d, allowed range is [0, 1]\n",
2563 vport->cfg_restrict_login = 1;
2566 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2567 vport->cfg_restrict_login = 0;
2570 vport->cfg_restrict_login = val;
2575 * lpfc_restrict_login_set - Set the vport restrict login flag
2576 * @vport: lpfc vport structure pointer.
2577 * @val: contains the restrict login value.
2580 * If val is not in a valid range then log a kernel error message and set
2581 * the vport restrict login to one.
2582 * If the port type is physical and the val is not zero log a kernel
2583 * error message, clear the restrict login flag and return zero.
2584 * Else set the restrict login flag to val.
2587 * zero if val is in range
2588 * -EINVAL val out of range
2591 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2593 if (val < 0 || val > 1) {
2594 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2595 "0425 lpfc_restrict_login attribute cannot "
2596 "be set to %d, allowed range is [0, 1]\n",
2598 vport->cfg_restrict_login = 1;
2601 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2602 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2603 "0468 lpfc_restrict_login must be 0 for "
2604 "Physical ports.\n");
2605 vport->cfg_restrict_login = 0;
2608 vport->cfg_restrict_login = val;
2611 lpfc_vport_param_store(restrict_login);
2612 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2613 lpfc_restrict_login_show, lpfc_restrict_login_store);
2616 # Some disk devices have a "select ID" or "select Target" capability.
2617 # From a protocol standpoint "select ID" usually means select the
2618 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2619 # annex" which contains a table that maps a "select ID" (a number
2620 # between 0 and 7F) to an ALPA. By default, for compatibility with
2621 # older drivers, the lpfc driver scans this table from low ALPA to high
2624 # Turning on the scan-down variable (on = 1, off = 0) will
2625 # cause the lpfc driver to use an inverted table, effectively
2626 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2628 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2629 # and will not work across a fabric. Also this parameter will take
2630 # effect only in the case when ALPA map is not available.)
2632 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2633 "Start scanning for devices from highest ALPA to lowest");
2636 # lpfc_topology: link topology for init link
2637 # 0x0 = attempt loop mode then point-to-point
2638 # 0x01 = internal loopback mode
2639 # 0x02 = attempt point-to-point mode only
2640 # 0x04 = attempt loop mode only
2641 # 0x06 = attempt point-to-point mode then loop
2642 # Set point-to-point mode if you want to run as an N_Port.
2643 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2644 # Default value is 0.
2648 * lpfc_topology_set - Set the adapters topology field
2649 * @phba: lpfc_hba pointer.
2650 * @val: topology value.
2653 * If val is in a valid range then set the adapter's topology field and
2654 * issue a lip; if the lip fails reset the topology to the old value.
2656 * If the value is not in range log a kernel error message and return an error.
2659 * zero if val is in range and lip okay
2660 * non-zero return value from lpfc_issue_lip()
2661 * -EINVAL val out of range
2664 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2665 const char *buf, size_t count)
2667 struct Scsi_Host *shost = class_to_shost(dev);
2668 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2669 struct lpfc_hba *phba = vport->phba;
2672 const char *val_buf = buf;
2676 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2678 val_buf = &buf[strlen("nolip ")];
2681 if (!isdigit(val_buf[0]))
2683 if (sscanf(val_buf, "%i", &val) != 1)
2686 if (val >= 0 && val <= 6) {
2687 prev_val = phba->cfg_topology;
2688 phba->cfg_topology = val;
2692 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2693 "3054 lpfc_topology changed from %d to %d\n",
2695 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2697 phba->cfg_topology = prev_val;
2702 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2703 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2704 "allowed range is [0, 6]\n",
2708 static int lpfc_topology = 0;
2709 module_param(lpfc_topology, int, S_IRUGO);
2710 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2711 lpfc_param_show(topology)
2712 lpfc_param_init(topology, 0, 0, 6)
2713 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2714 lpfc_topology_show, lpfc_topology_store);
2717 * lpfc_static_vport_show: Read callback function for
2718 * lpfc_static_vport sysfs file.
2719 * @dev: Pointer to class device object.
2720 * @attr: device attribute structure.
2721 * @buf: Data buffer.
2723 * This function is the read call back function for
2724 * lpfc_static_vport sysfs file. The lpfc_static_vport
2725 * sysfs file report the mageability of the vport.
2728 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2731 struct Scsi_Host *shost = class_to_shost(dev);
2732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2733 if (vport->vport_flag & STATIC_VPORT)
2734 sprintf(buf, "1\n");
2736 sprintf(buf, "0\n");
2742 * Sysfs attribute to control the statistical data collection.
2744 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2745 lpfc_static_vport_show, NULL);
2748 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2749 * @dev: Pointer to class device.
2750 * @buf: Data buffer.
2751 * @count: Size of the data buffer.
2753 * This function get called when an user write to the lpfc_stat_data_ctrl
2754 * sysfs file. This function parse the command written to the sysfs file
2755 * and take appropriate action. These commands are used for controlling
2756 * driver statistical data collection.
2757 * Following are the command this function handles.
2759 * setbucket <bucket_type> <base> <step>
2760 * = Set the latency buckets.
2761 * destroybucket = destroy all the buckets.
2762 * start = start data collection
2763 * stop = stop data collection
2764 * reset = reset the collected data
2767 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2768 const char *buf, size_t count)
2770 struct Scsi_Host *shost = class_to_shost(dev);
2771 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2772 struct lpfc_hba *phba = vport->phba;
2773 #define LPFC_MAX_DATA_CTRL_LEN 1024
2774 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2776 char *str_ptr, *token;
2777 struct lpfc_vport **vports;
2778 struct Scsi_Host *v_shost;
2779 char *bucket_type_str, *base_str, *step_str;
2780 unsigned long base, step, bucket_type;
2782 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2783 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2786 strcpy(bucket_data, buf);
2787 str_ptr = &bucket_data[0];
2788 /* Ignore this token - this is command token */
2789 token = strsep(&str_ptr, "\t ");
2793 bucket_type_str = strsep(&str_ptr, "\t ");
2794 if (!bucket_type_str)
2797 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2798 bucket_type = LPFC_LINEAR_BUCKET;
2799 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2800 bucket_type = LPFC_POWER2_BUCKET;
2804 base_str = strsep(&str_ptr, "\t ");
2807 base = simple_strtoul(base_str, NULL, 0);
2809 step_str = strsep(&str_ptr, "\t ");
2812 step = simple_strtoul(step_str, NULL, 0);
2816 /* Block the data collection for every vport */
2817 vports = lpfc_create_vport_work_array(phba);
2821 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2822 v_shost = lpfc_shost_from_vport(vports[i]);
2823 spin_lock_irq(v_shost->host_lock);
2824 /* Block and reset data collection */
2825 vports[i]->stat_data_blocked = 1;
2826 if (vports[i]->stat_data_enabled)
2827 lpfc_vport_reset_stat_data(vports[i]);
2828 spin_unlock_irq(v_shost->host_lock);
2831 /* Set the bucket attributes */
2832 phba->bucket_type = bucket_type;
2833 phba->bucket_base = base;
2834 phba->bucket_step = step;
2836 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2837 v_shost = lpfc_shost_from_vport(vports[i]);
2839 /* Unblock data collection */
2840 spin_lock_irq(v_shost->host_lock);
2841 vports[i]->stat_data_blocked = 0;
2842 spin_unlock_irq(v_shost->host_lock);
2844 lpfc_destroy_vport_work_array(phba, vports);
2848 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2849 vports = lpfc_create_vport_work_array(phba);
2853 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2854 v_shost = lpfc_shost_from_vport(vports[i]);
2855 spin_lock_irq(shost->host_lock);
2856 vports[i]->stat_data_blocked = 1;
2857 lpfc_free_bucket(vport);
2858 vport->stat_data_enabled = 0;
2859 vports[i]->stat_data_blocked = 0;
2860 spin_unlock_irq(shost->host_lock);
2862 lpfc_destroy_vport_work_array(phba, vports);
2863 phba->bucket_type = LPFC_NO_BUCKET;
2864 phba->bucket_base = 0;
2865 phba->bucket_step = 0;
2869 if (!strncmp(buf, "start", strlen("start"))) {
2870 /* If no buckets configured return error */
2871 if (phba->bucket_type == LPFC_NO_BUCKET)
2873 spin_lock_irq(shost->host_lock);
2874 if (vport->stat_data_enabled) {
2875 spin_unlock_irq(shost->host_lock);
2878 lpfc_alloc_bucket(vport);
2879 vport->stat_data_enabled = 1;
2880 spin_unlock_irq(shost->host_lock);
2884 if (!strncmp(buf, "stop", strlen("stop"))) {
2885 spin_lock_irq(shost->host_lock);
2886 if (vport->stat_data_enabled == 0) {
2887 spin_unlock_irq(shost->host_lock);
2890 lpfc_free_bucket(vport);
2891 vport->stat_data_enabled = 0;
2892 spin_unlock_irq(shost->host_lock);
2896 if (!strncmp(buf, "reset", strlen("reset"))) {
2897 if ((phba->bucket_type == LPFC_NO_BUCKET)
2898 || !vport->stat_data_enabled)
2900 spin_lock_irq(shost->host_lock);
2901 vport->stat_data_blocked = 1;
2902 lpfc_vport_reset_stat_data(vport);
2903 vport->stat_data_blocked = 0;
2904 spin_unlock_irq(shost->host_lock);
2912 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2913 * @dev: Pointer to class device object.
2914 * @buf: Data buffer.
2916 * This function is the read call back function for
2917 * lpfc_stat_data_ctrl sysfs file. This function report the
2918 * current statistical data collection state.
2921 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2924 struct Scsi_Host *shost = class_to_shost(dev);
2925 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2926 struct lpfc_hba *phba = vport->phba;
2930 unsigned long bucket_value;
2932 switch (phba->bucket_type) {
2933 case LPFC_LINEAR_BUCKET:
2934 bucket_type = "linear";
2936 case LPFC_POWER2_BUCKET:
2937 bucket_type = "power2";
2940 bucket_type = "No Bucket";
2944 sprintf(&buf[index], "Statistical Data enabled :%d, "
2945 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2946 " Bucket step :%d\nLatency Ranges :",
2947 vport->stat_data_enabled, vport->stat_data_blocked,
2948 bucket_type, phba->bucket_base, phba->bucket_step);
2949 index = strlen(buf);
2950 if (phba->bucket_type != LPFC_NO_BUCKET) {
2951 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2952 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2953 bucket_value = phba->bucket_base +
2954 phba->bucket_step * i;
2956 bucket_value = phba->bucket_base +
2957 (1 << i) * phba->bucket_step;
2959 if (index + 10 > PAGE_SIZE)
2961 sprintf(&buf[index], "%08ld ", bucket_value);
2962 index = strlen(buf);
2965 sprintf(&buf[index], "\n");
2970 * Sysfs attribute to control the statistical data collection.
2972 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2973 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2976 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2980 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2983 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2984 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2985 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2989 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2991 * @kobj: Pointer to the kernel object
2992 * @bin_attr: Attribute object
2993 * @buff: Buffer pointer
2995 * @count: Buffer size
2997 * This function is the read call back function for lpfc_drvr_stat_data
2998 * sysfs file. This function export the statistical data to user
3002 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3003 struct bin_attribute *bin_attr,
3004 char *buf, loff_t off, size_t count)
3006 struct device *dev = container_of(kobj, struct device,
3008 struct Scsi_Host *shost = class_to_shost(dev);
3009 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3010 struct lpfc_hba *phba = vport->phba;
3011 int i = 0, index = 0;
3012 unsigned long nport_index;
3013 struct lpfc_nodelist *ndlp = NULL;
3014 nport_index = (unsigned long)off /
3015 MAX_STAT_DATA_SIZE_PER_TARGET;
3017 if (!vport->stat_data_enabled || vport->stat_data_blocked
3018 || (phba->bucket_type == LPFC_NO_BUCKET))
3021 spin_lock_irq(shost->host_lock);
3022 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3023 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3026 if (nport_index > 0) {
3031 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3035 if (!ndlp->lat_data)
3039 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3040 ndlp->nlp_portname.u.wwn[0],
3041 ndlp->nlp_portname.u.wwn[1],
3042 ndlp->nlp_portname.u.wwn[2],
3043 ndlp->nlp_portname.u.wwn[3],
3044 ndlp->nlp_portname.u.wwn[4],
3045 ndlp->nlp_portname.u.wwn[5],
3046 ndlp->nlp_portname.u.wwn[6],
3047 ndlp->nlp_portname.u.wwn[7]);
3049 index = strlen(buf);
3051 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3052 sprintf(&buf[index], "%010u,",
3053 ndlp->lat_data[i].cmd_count);
3054 index = strlen(buf);
3056 sprintf(&buf[index], "\n");
3057 index = strlen(buf);
3059 spin_unlock_irq(shost->host_lock);
3063 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3065 .name = "lpfc_drvr_stat_data",
3068 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3069 .read = sysfs_drvr_stat_data_read,
3074 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3076 # Value range is [0,16]. Default value is 0.
3079 * lpfc_link_speed_set - Set the adapters link speed
3080 * @phba: lpfc_hba pointer.
3081 * @val: link speed value.
3084 * If val is in a valid range then set the adapter's link speed field and
3085 * issue a lip; if the lip fails reset the link speed to the old value.
3088 * If the value is not in range log a kernel error message and return an error.
3091 * zero if val is in range and lip okay.
3092 * non-zero return value from lpfc_issue_lip()
3093 * -EINVAL val out of range
3096 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3097 const char *buf, size_t count)
3099 struct Scsi_Host *shost = class_to_shost(dev);
3100 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3101 struct lpfc_hba *phba = vport->phba;
3102 int val = LPFC_USER_LINK_SPEED_AUTO;
3104 const char *val_buf = buf;
3108 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3110 val_buf = &buf[strlen("nolip ")];
3113 if (!isdigit(val_buf[0]))
3115 if (sscanf(val_buf, "%i", &val) != 1)
3118 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3119 "3055 lpfc_link_speed changed from %d to %d %s\n",
3120 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3122 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3123 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3124 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3125 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3126 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3127 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3128 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3129 "2879 lpfc_link_speed attribute cannot be set "
3130 "to %d. Speed is not supported by this port.\n",
3134 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3135 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3136 prev_val = phba->cfg_link_speed;
3137 phba->cfg_link_speed = val;
3141 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3143 phba->cfg_link_speed = prev_val;
3148 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3149 "0469 lpfc_link_speed attribute cannot be set to %d, "
3150 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3154 static int lpfc_link_speed = 0;
3155 module_param(lpfc_link_speed, int, S_IRUGO);
3156 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3157 lpfc_param_show(link_speed)
3160 * lpfc_link_speed_init - Set the adapters link speed
3161 * @phba: lpfc_hba pointer.
3162 * @val: link speed value.
3165 * If val is in a valid range then set the adapter's link speed field.
3168 * If the value is not in range log a kernel error message, clear the link
3169 * speed and return an error.
3172 * zero if val saved.
3173 * -EINVAL val out of range
3176 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3178 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3179 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3180 phba->cfg_link_speed = val;
3183 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3184 "0405 lpfc_link_speed attribute cannot "
3185 "be set to %d, allowed values are "
3186 "["LPFC_LINK_SPEED_STRING"]\n", val);
3187 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3191 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3192 lpfc_link_speed_show, lpfc_link_speed_store);
3195 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3196 # 0 = aer disabled or not supported
3197 # 1 = aer supported and enabled (default)
3198 # Value range is [0,1]. Default value is 1.
3202 * lpfc_aer_support_store - Set the adapter for aer support
3204 * @dev: class device that is converted into a Scsi_host.
3205 * @attr: device attribute, not used.
3206 * @buf: containing enable or disable aer flag.
3207 * @count: unused variable.
3210 * If the val is 1 and currently the device's AER capability was not
3211 * enabled, invoke the kernel's enable AER helper routine, trying to
3212 * enable the device's AER capability. If the helper routine enabling
3213 * AER returns success, update the device's cfg_aer_support flag to
3214 * indicate AER is supported by the device; otherwise, if the device
3215 * AER capability is already enabled to support AER, then do nothing.
3217 * If the val is 0 and currently the device's AER support was enabled,
3218 * invoke the kernel's disable AER helper routine. After that, update
3219 * the device's cfg_aer_support flag to indicate AER is not supported
3220 * by the device; otherwise, if the device AER capability is already
3221 * disabled from supporting AER, then do nothing.
3224 * length of the buf on success if val is in range the intended mode
3226 * -EINVAL if val out of range or intended mode is not supported.
3229 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3230 const char *buf, size_t count)
3232 struct Scsi_Host *shost = class_to_shost(dev);
3233 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3234 struct lpfc_hba *phba = vport->phba;
3235 int val = 0, rc = -EINVAL;
3237 if (!isdigit(buf[0]))
3239 if (sscanf(buf, "%i", &val) != 1)
3244 if (phba->hba_flag & HBA_AER_ENABLED) {
3245 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3247 spin_lock_irq(&phba->hbalock);
3248 phba->hba_flag &= ~HBA_AER_ENABLED;
3249 spin_unlock_irq(&phba->hbalock);
3250 phba->cfg_aer_support = 0;
3255 phba->cfg_aer_support = 0;
3260 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3261 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3263 spin_lock_irq(&phba->hbalock);
3264 phba->hba_flag |= HBA_AER_ENABLED;
3265 spin_unlock_irq(&phba->hbalock);
3266 phba->cfg_aer_support = 1;
3271 phba->cfg_aer_support = 1;
3282 static int lpfc_aer_support = 1;
3283 module_param(lpfc_aer_support, int, S_IRUGO);
3284 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3285 lpfc_param_show(aer_support)
3288 * lpfc_aer_support_init - Set the initial adapters aer support flag
3289 * @phba: lpfc_hba pointer.
3290 * @val: enable aer or disable aer flag.
3293 * If val is in a valid range [0,1], then set the adapter's initial
3294 * cfg_aer_support field. It will be up to the driver's probe_one
3295 * routine to determine whether the device's AER support can be set
3299 * If the value is not in range log a kernel error message, and
3300 * choose the default value of setting AER support and return.
3303 * zero if val saved.
3304 * -EINVAL val out of range
3307 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3309 if (val == 0 || val == 1) {
3310 phba->cfg_aer_support = val;
3313 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3314 "2712 lpfc_aer_support attribute value %d out "
3315 "of range, allowed values are 0|1, setting it "
3316 "to default value of 1\n", val);
3317 /* By default, try to enable AER on a device */
3318 phba->cfg_aer_support = 1;
3322 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3323 lpfc_aer_support_show, lpfc_aer_support_store);
3326 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3327 * @dev: class device that is converted into a Scsi_host.
3328 * @attr: device attribute, not used.
3329 * @buf: containing flag 1 for aer cleanup state.
3330 * @count: unused variable.
3333 * If the @buf contains 1 and the device currently has the AER support
3334 * enabled, then invokes the kernel AER helper routine
3335 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3336 * error status register.
3341 * -EINVAL if the buf does not contain the 1 or the device is not currently
3342 * enabled with the AER support.
3345 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3346 const char *buf, size_t count)
3348 struct Scsi_Host *shost = class_to_shost(dev);
3349 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3350 struct lpfc_hba *phba = vport->phba;
3353 if (!isdigit(buf[0]))
3355 if (sscanf(buf, "%i", &val) != 1)
3360 if (phba->hba_flag & HBA_AER_ENABLED)
3361 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3369 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3370 lpfc_aer_cleanup_state);
3373 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3375 * @dev: class device that is converted into a Scsi_host.
3376 * @attr: device attribute, not used.
3377 * @buf: containing the string the number of vfs to be enabled.
3378 * @count: unused variable.
3381 * When this api is called either through user sysfs, the driver shall
3382 * try to enable or disable SR-IOV virtual functions according to the
3385 * If zero virtual function has been enabled to the physical function,
3386 * the driver shall invoke the pci enable virtual function api trying
3387 * to enable the virtual functions. If the nr_vfn provided is greater
3388 * than the maximum supported, the maximum virtual function number will
3389 * be used for invoking the api; otherwise, the nr_vfn provided shall
3390 * be used for invoking the api. If the api call returned success, the
3391 * actual number of virtual functions enabled will be set to the driver
3392 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3393 * cfg_sriov_nr_virtfn remains zero.
3395 * If none-zero virtual functions have already been enabled to the
3396 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3397 * -EINVAL will be returned and the driver does nothing;
3399 * If the nr_vfn provided is zero and none-zero virtual functions have
3400 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3401 * disabling virtual function api shall be invoded to disable all the
3402 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3403 * zero. Otherwise, if zero virtual function has been enabled, do
3407 * length of the buf on success if val is in range the intended mode
3409 * -EINVAL if val out of range or intended mode is not supported.
3412 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3413 const char *buf, size_t count)
3415 struct Scsi_Host *shost = class_to_shost(dev);
3416 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3417 struct lpfc_hba *phba = vport->phba;
3418 struct pci_dev *pdev = phba->pcidev;
3419 int val = 0, rc = -EINVAL;
3421 /* Sanity check on user data */
3422 if (!isdigit(buf[0]))
3424 if (sscanf(buf, "%i", &val) != 1)
3429 /* Request disabling virtual functions */
3431 if (phba->cfg_sriov_nr_virtfn > 0) {
3432 pci_disable_sriov(pdev);
3433 phba->cfg_sriov_nr_virtfn = 0;
3438 /* Request enabling virtual functions */
3439 if (phba->cfg_sriov_nr_virtfn > 0) {
3440 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3441 "3018 There are %d virtual functions "
3442 "enabled on physical function.\n",
3443 phba->cfg_sriov_nr_virtfn);
3447 if (val <= LPFC_MAX_VFN_PER_PFN)
3448 phba->cfg_sriov_nr_virtfn = val;
3450 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3451 "3019 Enabling %d virtual functions is not "
3456 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3458 phba->cfg_sriov_nr_virtfn = 0;
3466 static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3467 module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3468 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3469 lpfc_param_show(sriov_nr_virtfn)
3472 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3473 * @phba: lpfc_hba pointer.
3474 * @val: link speed value.
3477 * If val is in a valid range [0,255], then set the adapter's initial
3478 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3479 * number shall be used instead. It will be up to the driver's probe_one
3480 * routine to determine whether the device's SR-IOV is supported or not.
3483 * zero if val saved.
3484 * -EINVAL val out of range
3487 lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3489 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3490 phba->cfg_sriov_nr_virtfn = val;
3494 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3495 "3017 Enabling %d virtual functions is not "
3499 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3500 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3503 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3504 # Value range is [2,3]. Default value is 3.
3506 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3507 "Select Fibre Channel class of service for FCP sequences");
3510 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3511 # is [0,1]. Default value is 0.
3513 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3514 "Use ADISC on rediscovery to authenticate FCP devices");
3517 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3518 # depth. Default value is 0. When the value of this parameter is zero the
3519 # SCSI command completion time is not used for controlling I/O queue depth. When
3520 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3521 # to limit the I/O completion time to the parameter value.
3522 # The value is set in milliseconds.
3524 static int lpfc_max_scsicmpl_time;
3525 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3526 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3527 "Use command completion time to control queue depth");
3528 lpfc_vport_param_show(max_scsicmpl_time);
3529 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3531 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3533 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3534 struct lpfc_nodelist *ndlp, *next_ndlp;
3536 if (val == vport->cfg_max_scsicmpl_time)
3538 if ((val < 0) || (val > 60000))
3540 vport->cfg_max_scsicmpl_time = val;
3542 spin_lock_irq(shost->host_lock);
3543 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3544 if (!NLP_CHK_NODE_ACT(ndlp))
3546 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3548 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3550 spin_unlock_irq(shost->host_lock);
3553 lpfc_vport_param_store(max_scsicmpl_time);
3554 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3555 lpfc_max_scsicmpl_time_show,
3556 lpfc_max_scsicmpl_time_store);
3559 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3560 # range is [0,1]. Default value is 0.
3562 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3565 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3566 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3567 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3568 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3569 # cr_delay is set to 0.
3571 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3572 "interrupt response is generated");
3574 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3575 "interrupt response is generated");
3578 # lpfc_multi_ring_support: Determines how many rings to spread available
3579 # cmd/rsp IOCB entries across.
3580 # Value range is [1,2]. Default value is 1.
3582 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3583 "SLI rings to spread IOCB entries across");
3586 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3587 # identifies what rctl value to configure the additional ring for.
3588 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3590 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3591 255, "Identifies RCTL for additional ring configuration");
3594 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3595 # identifies what type value to configure the additional ring for.
3596 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3598 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3599 255, "Identifies TYPE for additional ring configuration");
3602 # lpfc_fdmi_on: controls FDMI support.
3603 # 0 = no FDMI support
3604 # 1 = support FDMI without attribute of hostname
3605 # 2 = support FDMI with attribute of hostname
3606 # Value range [0,2]. Default value is 0.
3608 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3611 # Specifies the maximum number of ELS cmds we can have outstanding (for
3612 # discovery). Value range is [1,64]. Default value = 32.
3614 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3615 "during discovery");
3618 # lpfc_max_luns: maximum allowed LUN.
3619 # Value range is [0,65535]. Default value is 255.
3620 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3622 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3625 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3626 # Value range is [1,255], default value is 10.
3628 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3629 "Milliseconds driver will wait between polling FCP ring");
3632 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3633 # support this feature
3636 # 2 = MSI-X enabled (default)
3637 # Value range is [0,2]. Default value is 2.
3639 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3640 "MSI-X (2), if possible");
3643 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3645 # Value range is [636,651042]. Default value is 10000.
3647 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3648 "Set the maximum number of fast-path FCP interrupts per second");
3651 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3653 # Value range is [1,31]. Default value is 4.
3655 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3656 "Set the number of fast-path FCP work queues, if possible");
3659 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3661 # Value range is [1,7]. Default value is 1.
3663 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3664 "Set the number of fast-path FCP event queues, if possible");
3667 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3668 # 0 = HBA resets disabled
3669 # 1 = HBA resets enabled (default)
3670 # Value range is [0,1]. Default value is 1.
3672 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3675 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3676 # 0 = HBA Heartbeat disabled
3677 # 1 = HBA Heartbeat enabled (default)
3678 # Value range is [0,1]. Default value is 1.
3680 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3683 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3684 # 0 = BlockGuard disabled (default)
3685 # 1 = BlockGuard enabled
3686 # Value range is [0,1]. Default value is 0.
3688 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3692 # - Bit mask of host protection capabilities used to register with the
3694 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3695 # - Allows you to ultimately specify which profiles to use
3696 # - Default will result in registering capabilities for all profiles.
3699 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3700 SHOST_DIX_TYPE0_PROTECTION |
3701 SHOST_DIX_TYPE1_PROTECTION;
3703 module_param(lpfc_prot_mask, uint, S_IRUGO);
3704 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3707 # lpfc_prot_guard: i
3708 # - Bit mask of protection guard types to register with the SCSI mid-layer
3709 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3710 # - Allows you to ultimately specify which profiles to use
3711 # - Default will result in registering capabilities for all guard types
3714 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3715 module_param(lpfc_prot_guard, byte, S_IRUGO);
3716 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3719 * Delay initial NPort discovery when Clean Address bit is cleared in
3720 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3721 * This parameter can have value 0 or 1.
3722 * When this parameter is set to 0, no delay is added to the initial
3724 * When this parameter is set to non-zero value, initial Nport discovery is
3725 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3726 * accept and FCID/Fabric name/Fabric portname is changed.
3727 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3728 * when Clean Address bit is cleared in FLOGI/FDISC
3729 * accept and FCID/Fabric name/Fabric portname is changed.
3730 * Default value is 0.
3732 int lpfc_delay_discovery;
3733 module_param(lpfc_delay_discovery, int, S_IRUGO);
3734 MODULE_PARM_DESC(lpfc_delay_discovery,
3735 "Delay NPort discovery when Clean Address bit is cleared. "
3736 "Allowed values: 0,1.");
3739 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3740 * This value can be set to values between 64 and 256. The default value is
3741 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3742 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3744 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3745 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3747 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3748 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3749 "Max Protection Scatter Gather Segment Count");
3751 struct device_attribute *lpfc_hba_attrs[] = {
3753 &dev_attr_bg_guard_err,
3754 &dev_attr_bg_apptag_err,
3755 &dev_attr_bg_reftag_err,
3757 &dev_attr_serialnum,
3758 &dev_attr_modeldesc,
3759 &dev_attr_modelname,
3760 &dev_attr_programtype,
3764 &dev_attr_option_rom_version,
3765 &dev_attr_link_state,
3766 &dev_attr_num_discovered_ports,
3767 &dev_attr_menlo_mgmt_mode,
3768 &dev_attr_lpfc_drvr_version,
3769 &dev_attr_lpfc_enable_fip,
3770 &dev_attr_lpfc_temp_sensor,
3771 &dev_attr_lpfc_log_verbose,
3772 &dev_attr_lpfc_lun_queue_depth,
3773 &dev_attr_lpfc_tgt_queue_depth,
3774 &dev_attr_lpfc_hba_queue_depth,
3775 &dev_attr_lpfc_peer_port_login,
3776 &dev_attr_lpfc_nodev_tmo,
3777 &dev_attr_lpfc_devloss_tmo,
3778 &dev_attr_lpfc_fcp_class,
3779 &dev_attr_lpfc_use_adisc,
3780 &dev_attr_lpfc_ack0,
3781 &dev_attr_lpfc_topology,
3782 &dev_attr_lpfc_scan_down,
3783 &dev_attr_lpfc_link_speed,
3784 &dev_attr_lpfc_cr_delay,
3785 &dev_attr_lpfc_cr_count,
3786 &dev_attr_lpfc_multi_ring_support,
3787 &dev_attr_lpfc_multi_ring_rctl,
3788 &dev_attr_lpfc_multi_ring_type,
3789 &dev_attr_lpfc_fdmi_on,
3790 &dev_attr_lpfc_max_luns,
3791 &dev_attr_lpfc_enable_npiv,
3792 &dev_attr_lpfc_fcf_failover_policy,
3793 &dev_attr_lpfc_enable_rrq,
3794 &dev_attr_nport_evt_cnt,
3795 &dev_attr_board_mode,
3802 &dev_attr_npiv_info,
3803 &dev_attr_issue_reset,
3804 &dev_attr_lpfc_poll,
3805 &dev_attr_lpfc_poll_tmo,
3806 &dev_attr_lpfc_use_msi,
3807 &dev_attr_lpfc_fcp_imax,
3808 &dev_attr_lpfc_fcp_wq_count,
3809 &dev_attr_lpfc_fcp_eq_count,
3810 &dev_attr_lpfc_enable_bg,
3811 &dev_attr_lpfc_soft_wwnn,
3812 &dev_attr_lpfc_soft_wwpn,
3813 &dev_attr_lpfc_soft_wwn_enable,
3814 &dev_attr_lpfc_enable_hba_reset,
3815 &dev_attr_lpfc_enable_hba_heartbeat,
3816 &dev_attr_lpfc_sg_seg_cnt,
3817 &dev_attr_lpfc_max_scsicmpl_time,
3818 &dev_attr_lpfc_stat_data_ctrl,
3819 &dev_attr_lpfc_prot_sg_seg_cnt,
3820 &dev_attr_lpfc_aer_support,
3821 &dev_attr_lpfc_aer_state_cleanup,
3822 &dev_attr_lpfc_sriov_nr_virtfn,
3823 &dev_attr_lpfc_suppress_link_up,
3824 &dev_attr_lpfc_iocb_cnt,
3827 &dev_attr_txcmplq_hw,
3828 &dev_attr_lpfc_fips_level,
3829 &dev_attr_lpfc_fips_rev,
3831 &dev_attr_lpfc_sriov_hw_max_virtfn,
3835 struct device_attribute *lpfc_vport_attrs[] = {
3837 &dev_attr_link_state,
3838 &dev_attr_num_discovered_ports,
3839 &dev_attr_lpfc_drvr_version,
3840 &dev_attr_lpfc_log_verbose,
3841 &dev_attr_lpfc_lun_queue_depth,
3842 &dev_attr_lpfc_tgt_queue_depth,
3843 &dev_attr_lpfc_nodev_tmo,
3844 &dev_attr_lpfc_devloss_tmo,
3845 &dev_attr_lpfc_hba_queue_depth,
3846 &dev_attr_lpfc_peer_port_login,
3847 &dev_attr_lpfc_restrict_login,
3848 &dev_attr_lpfc_fcp_class,
3849 &dev_attr_lpfc_use_adisc,
3850 &dev_attr_lpfc_fdmi_on,
3851 &dev_attr_lpfc_max_luns,
3852 &dev_attr_nport_evt_cnt,
3853 &dev_attr_npiv_info,
3854 &dev_attr_lpfc_enable_da_id,
3855 &dev_attr_lpfc_max_scsicmpl_time,
3856 &dev_attr_lpfc_stat_data_ctrl,
3857 &dev_attr_lpfc_static_vport,
3858 &dev_attr_lpfc_fips_level,
3859 &dev_attr_lpfc_fips_rev,
3864 * sysfs_ctlreg_write - Write method for writing to ctlreg
3865 * @filp: open sysfs file
3866 * @kobj: kernel kobject that contains the kernel class device.
3867 * @bin_attr: kernel attributes passed to us.
3868 * @buf: contains the data to be written to the adapter IOREG space.
3869 * @off: offset into buffer to beginning of data.
3870 * @count: bytes to transfer.
3873 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3874 * Uses the adapter io control registers to send buf contents to the adapter.
3877 * -ERANGE off and count combo out of range
3878 * -EINVAL off, count or buff address invalid
3879 * -EPERM adapter is offline
3880 * value of count, buf contents written
3883 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3884 struct bin_attribute *bin_attr,
3885 char *buf, loff_t off, size_t count)
3888 struct device *dev = container_of(kobj, struct device, kobj);
3889 struct Scsi_Host *shost = class_to_shost(dev);
3890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3891 struct lpfc_hba *phba = vport->phba;
3893 if (phba->sli_rev >= LPFC_SLI_REV4)
3896 if ((off + count) > FF_REG_AREA_SIZE)
3899 if (count <= LPFC_REG_WRITE_KEY_SIZE)
3902 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3905 /* This is to protect HBA registers from accidental writes. */
3906 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3909 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3912 spin_lock_irq(&phba->hbalock);
3913 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
3914 buf_off += sizeof(uint32_t))
3915 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
3916 phba->ctrl_regs_memmap_p + off + buf_off);
3918 spin_unlock_irq(&phba->hbalock);
3924 * sysfs_ctlreg_read - Read method for reading from ctlreg
3925 * @filp: open sysfs file
3926 * @kobj: kernel kobject that contains the kernel class device.
3927 * @bin_attr: kernel attributes passed to us.
3928 * @buf: if successful contains the data from the adapter IOREG space.
3929 * @off: offset into buffer to beginning of data.
3930 * @count: bytes to transfer.
3933 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3934 * Uses the adapter io control registers to read data into buf.
3937 * -ERANGE off and count combo out of range
3938 * -EINVAL off, count or buff address invalid
3939 * value of count, buf contents read
3942 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3943 struct bin_attribute *bin_attr,
3944 char *buf, loff_t off, size_t count)
3948 struct device *dev = container_of(kobj, struct device, kobj);
3949 struct Scsi_Host *shost = class_to_shost(dev);
3950 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3951 struct lpfc_hba *phba = vport->phba;
3953 if (phba->sli_rev >= LPFC_SLI_REV4)
3956 if (off > FF_REG_AREA_SIZE)
3959 if ((off + count) > FF_REG_AREA_SIZE)
3960 count = FF_REG_AREA_SIZE - off;
3962 if (count == 0) return 0;
3964 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3967 spin_lock_irq(&phba->hbalock);
3969 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3970 tmp_ptr = (uint32_t *)(buf + buf_off);
3971 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3974 spin_unlock_irq(&phba->hbalock);
3979 static struct bin_attribute sysfs_ctlreg_attr = {
3982 .mode = S_IRUSR | S_IWUSR,
3985 .read = sysfs_ctlreg_read,
3986 .write = sysfs_ctlreg_write,
3990 * sysfs_mbox_idle - frees the sysfs mailbox
3991 * @phba: lpfc_hba pointer
3994 sysfs_mbox_idle(struct lpfc_hba *phba)
3996 phba->sysfs_mbox.state = SMBOX_IDLE;
3997 phba->sysfs_mbox.offset = 0;
3999 if (phba->sysfs_mbox.mbox) {
4000 mempool_free(phba->sysfs_mbox.mbox,
4001 phba->mbox_mem_pool);
4002 phba->sysfs_mbox.mbox = NULL;
4007 * sysfs_mbox_write - Write method for writing information via mbox
4008 * @filp: open sysfs file
4009 * @kobj: kernel kobject that contains the kernel class device.
4010 * @bin_attr: kernel attributes passed to us.
4011 * @buf: contains the data to be written to sysfs mbox.
4012 * @off: offset into buffer to beginning of data.
4013 * @count: bytes to transfer.
4016 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4017 * Uses the sysfs mbox to send buf contents to the adapter.
4020 * -ERANGE off and count combo out of range
4021 * -EINVAL off, count or buff address invalid
4022 * zero if count is zero
4023 * -EPERM adapter is offline
4024 * -ENOMEM failed to allocate memory for the mail box
4025 * -EAGAIN offset, state or mbox is NULL
4026 * count number of bytes transferred
4029 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4030 struct bin_attribute *bin_attr,
4031 char *buf, loff_t off, size_t count)
4033 struct device *dev = container_of(kobj, struct device, kobj);
4034 struct Scsi_Host *shost = class_to_shost(dev);
4035 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4036 struct lpfc_hba *phba = vport->phba;
4037 struct lpfcMboxq *mbox = NULL;
4039 if ((count + off) > MAILBOX_CMD_SIZE)
4042 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4049 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4052 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
4055 spin_lock_irq(&phba->hbalock);
4058 if (phba->sysfs_mbox.mbox)
4059 mempool_free(mbox, phba->mbox_mem_pool);
4061 phba->sysfs_mbox.mbox = mbox;
4062 phba->sysfs_mbox.state = SMBOX_WRITING;
4064 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4065 phba->sysfs_mbox.offset != off ||
4066 phba->sysfs_mbox.mbox == NULL) {
4067 sysfs_mbox_idle(phba);
4068 spin_unlock_irq(&phba->hbalock);
4073 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
4076 phba->sysfs_mbox.offset = off + count;
4078 spin_unlock_irq(&phba->hbalock);
4084 * sysfs_mbox_read - Read method for reading information via mbox
4085 * @filp: open sysfs file
4086 * @kobj: kernel kobject that contains the kernel class device.
4087 * @bin_attr: kernel attributes passed to us.
4088 * @buf: contains the data to be read from sysfs mbox.
4089 * @off: offset into buffer to beginning of data.
4090 * @count: bytes to transfer.
4093 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4094 * Uses the sysfs mbox to receive data from to the adapter.
4097 * -ERANGE off greater than mailbox command size
4098 * -EINVAL off, count or buff address invalid
4099 * zero if off and count are zero
4100 * -EACCES adapter over temp
4101 * -EPERM garbage can value to catch a multitude of errors
4102 * -EAGAIN management IO not permitted, state or off error
4103 * -ETIME mailbox timeout
4104 * -ENODEV mailbox error
4105 * count number of bytes transferred
4108 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4109 struct bin_attribute *bin_attr,
4110 char *buf, loff_t off, size_t count)
4112 struct device *dev = container_of(kobj, struct device, kobj);
4113 struct Scsi_Host *shost = class_to_shost(dev);
4114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4115 struct lpfc_hba *phba = vport->phba;
4116 LPFC_MBOXQ_t *mboxq;
4121 if (off > MAILBOX_CMD_SIZE)
4124 if ((count + off) > MAILBOX_CMD_SIZE)
4125 count = MAILBOX_CMD_SIZE - off;
4127 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4130 if (off && count == 0)
4133 spin_lock_irq(&phba->hbalock);
4135 if (phba->over_temp_state == HBA_OVER_TEMP) {
4136 sysfs_mbox_idle(phba);
4137 spin_unlock_irq(&phba->hbalock);
4142 phba->sysfs_mbox.state == SMBOX_WRITING &&
4143 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
4144 mboxq = (LPFC_MBOXQ_t *)&phba->sysfs_mbox.mbox;
4146 switch (pmb->mbxCommand) {
4150 case MBX_CONFIG_LINK:
4151 case MBX_CONFIG_RING:
4152 case MBX_RESET_RING:
4153 case MBX_UNREG_LOGIN:
4155 case MBX_DUMP_CONTEXT:
4160 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
4161 printk(KERN_WARNING "mbox_read:Command 0x%x "
4162 "is illegal in on-line state\n",
4164 sysfs_mbox_idle(phba);
4165 spin_unlock_irq(&phba->hbalock);
4169 case MBX_WRITE_VPARMS:
4172 case MBX_READ_CONFIG:
4173 case MBX_READ_RCONFIG:
4174 case MBX_READ_STATUS:
4177 case MBX_READ_LNK_STAT:
4178 case MBX_DUMP_MEMORY:
4180 case MBX_UPDATE_CFG:
4181 case MBX_KILL_BOARD:
4183 case MBX_LOAD_EXP_ROM:
4185 case MBX_DEL_LD_ENTRY:
4186 case MBX_SET_VARIABLE:
4188 case MBX_PORT_CAPABILITIES:
4189 case MBX_PORT_IOV_CONTROL:
4191 case MBX_SECURITY_MGMT:
4193 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4194 printk(KERN_WARNING "mbox_read:Command 0x%x "
4195 "is not permitted\n", pmb->mbxCommand);
4196 sysfs_mbox_idle(phba);
4197 spin_unlock_irq(&phba->hbalock);
4201 case MBX_READ_SPARM64:
4202 case MBX_READ_TOPOLOGY:
4204 case MBX_REG_LOGIN64:
4205 case MBX_CONFIG_PORT:
4206 case MBX_RUN_BIU_DIAG:
4207 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
4209 sysfs_mbox_idle(phba);
4210 spin_unlock_irq(&phba->hbalock);
4213 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
4215 sysfs_mbox_idle(phba);
4216 spin_unlock_irq(&phba->hbalock);
4220 /* If HBA encountered an error attention, allow only DUMP
4221 * or RESTART mailbox commands until the HBA is restarted.
4223 if (phba->pport->stopped &&
4224 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4225 pmb->mbxCommand != MBX_RESTART &&
4226 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4227 pmb->mbxCommand != MBX_WRITE_WWN)
4228 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4229 "1259 mbox: Issued mailbox cmd "
4230 "0x%x while in stopped state.\n",
4233 phba->sysfs_mbox.mbox->vport = vport;
4235 /* Don't allow mailbox commands to be sent when blocked
4236 * or when in the middle of discovery
4238 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
4239 sysfs_mbox_idle(phba);
4240 spin_unlock_irq(&phba->hbalock);
4244 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4245 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
4247 spin_unlock_irq(&phba->hbalock);
4248 rc = lpfc_sli_issue_mbox (phba,
4249 phba->sysfs_mbox.mbox,
4251 spin_lock_irq(&phba->hbalock);
4254 spin_unlock_irq(&phba->hbalock);
4255 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
4256 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
4257 spin_lock_irq(&phba->hbalock);
4260 if (rc != MBX_SUCCESS) {
4261 if (rc == MBX_TIMEOUT) {
4262 phba->sysfs_mbox.mbox = NULL;
4264 sysfs_mbox_idle(phba);
4265 spin_unlock_irq(&phba->hbalock);
4266 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
4268 phba->sysfs_mbox.state = SMBOX_READING;
4270 else if (phba->sysfs_mbox.offset != off ||
4271 phba->sysfs_mbox.state != SMBOX_READING) {
4272 printk(KERN_WARNING "mbox_read: Bad State\n");
4273 sysfs_mbox_idle(phba);
4274 spin_unlock_irq(&phba->hbalock);
4278 memcpy(buf, (uint8_t *) &pmb + off, count);
4280 phba->sysfs_mbox.offset = off + count;
4282 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
4283 sysfs_mbox_idle(phba);
4285 spin_unlock_irq(&phba->hbalock);
4290 static struct bin_attribute sysfs_mbox_attr = {
4293 .mode = S_IRUSR | S_IWUSR,
4295 .size = MAILBOX_SYSFS_MAX,
4296 .read = sysfs_mbox_read,
4297 .write = sysfs_mbox_write,
4301 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
4302 * @vport: address of lpfc vport structure.
4306 * error return code from sysfs_create_bin_file()
4309 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
4311 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4314 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4315 &sysfs_drvr_stat_data_attr);
4317 /* Virtual ports do not need ctrl_reg and mbox */
4318 if (error || vport->port_type == LPFC_NPIV_PORT)
4321 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4322 &sysfs_ctlreg_attr);
4324 goto out_remove_stat_attr;
4326 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4329 goto out_remove_ctlreg_attr;
4332 out_remove_ctlreg_attr:
4333 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4334 out_remove_stat_attr:
4335 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4336 &sysfs_drvr_stat_data_attr);
4342 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4343 * @vport: address of lpfc vport structure.
4346 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4348 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4349 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4350 &sysfs_drvr_stat_data_attr);
4351 /* Virtual ports do not need ctrl_reg and mbox */
4352 if (vport->port_type == LPFC_NPIV_PORT)
4354 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4355 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4360 * Dynamic FC Host Attributes Support
4364 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4365 * @shost: kernel scsi host pointer.
4368 lpfc_get_host_port_id(struct Scsi_Host *shost)
4370 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4372 /* note: fc_myDID already in cpu endianness */
4373 fc_host_port_id(shost) = vport->fc_myDID;
4377 * lpfc_get_host_port_type - Set the value of the scsi host port type
4378 * @shost: kernel scsi host pointer.
4381 lpfc_get_host_port_type(struct Scsi_Host *shost)
4383 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4384 struct lpfc_hba *phba = vport->phba;
4386 spin_lock_irq(shost->host_lock);
4388 if (vport->port_type == LPFC_NPIV_PORT) {
4389 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4390 } else if (lpfc_is_link_up(phba)) {
4391 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4392 if (vport->fc_flag & FC_PUBLIC_LOOP)
4393 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4395 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4397 if (vport->fc_flag & FC_FABRIC)
4398 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4400 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4403 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4405 spin_unlock_irq(shost->host_lock);
4409 * lpfc_get_host_port_state - Set the value of the scsi host port state
4410 * @shost: kernel scsi host pointer.
4413 lpfc_get_host_port_state(struct Scsi_Host *shost)
4415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4416 struct lpfc_hba *phba = vport->phba;
4418 spin_lock_irq(shost->host_lock);
4420 if (vport->fc_flag & FC_OFFLINE_MODE)
4421 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4423 switch (phba->link_state) {
4424 case LPFC_LINK_UNKNOWN:
4425 case LPFC_LINK_DOWN:
4426 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4430 case LPFC_HBA_READY:
4431 /* Links up, beyond this port_type reports state */
4432 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4434 case LPFC_HBA_ERROR:
4435 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4438 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4443 spin_unlock_irq(shost->host_lock);
4447 * lpfc_get_host_speed - Set the value of the scsi host speed
4448 * @shost: kernel scsi host pointer.
4451 lpfc_get_host_speed(struct Scsi_Host *shost)
4453 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4454 struct lpfc_hba *phba = vport->phba;
4456 spin_lock_irq(shost->host_lock);
4458 if (lpfc_is_link_up(phba)) {
4459 switch(phba->fc_linkspeed) {
4460 case LPFC_LINK_SPEED_1GHZ:
4461 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4463 case LPFC_LINK_SPEED_2GHZ:
4464 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4466 case LPFC_LINK_SPEED_4GHZ:
4467 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4469 case LPFC_LINK_SPEED_8GHZ:
4470 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4472 case LPFC_LINK_SPEED_10GHZ:
4473 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4475 case LPFC_LINK_SPEED_16GHZ:
4476 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4479 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4483 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4485 spin_unlock_irq(shost->host_lock);
4489 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4490 * @shost: kernel scsi host pointer.
4493 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4495 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4496 struct lpfc_hba *phba = vport->phba;
4499 spin_lock_irq(shost->host_lock);
4501 if ((vport->port_state > LPFC_FLOGI) &&
4502 ((vport->fc_flag & FC_FABRIC) ||
4503 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4504 (vport->fc_flag & FC_PUBLIC_LOOP))))
4505 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4507 /* fabric is local port if there is no F/FL_Port */
4510 spin_unlock_irq(shost->host_lock);
4512 fc_host_fabric_name(shost) = node_name;
4516 * lpfc_get_stats - Return statistical information about the adapter
4517 * @shost: kernel scsi host pointer.
4520 * NULL on error for link down, no mbox pool, sli2 active,
4521 * management not allowed, memory allocation error, or mbox error.
4525 * address of the adapter host statistics
4527 static struct fc_host_statistics *
4528 lpfc_get_stats(struct Scsi_Host *shost)
4530 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4531 struct lpfc_hba *phba = vport->phba;
4532 struct lpfc_sli *psli = &phba->sli;
4533 struct fc_host_statistics *hs = &phba->link_stats;
4534 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4535 LPFC_MBOXQ_t *pmboxq;
4537 unsigned long seconds;
4541 * prevent udev from issuing mailbox commands until the port is
4544 if (phba->link_state < LPFC_LINK_DOWN ||
4545 !phba->mbox_mem_pool ||
4546 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4549 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4552 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4555 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4557 pmb = &pmboxq->u.mb;
4558 pmb->mbxCommand = MBX_READ_STATUS;
4559 pmb->mbxOwner = OWN_HOST;
4560 pmboxq->context1 = NULL;
4561 pmboxq->vport = vport;
4563 if (vport->fc_flag & FC_OFFLINE_MODE)
4564 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4566 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4568 if (rc != MBX_SUCCESS) {
4569 if (rc != MBX_TIMEOUT)
4570 mempool_free(pmboxq, phba->mbox_mem_pool);
4574 memset(hs, 0, sizeof (struct fc_host_statistics));
4576 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4578 * The MBX_READ_STATUS returns tx_k_bytes which has to
4579 * converted to words
4581 hs->tx_words = (uint64_t)
4582 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4584 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4585 hs->rx_words = (uint64_t)
4586 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4589 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4590 pmb->mbxCommand = MBX_READ_LNK_STAT;
4591 pmb->mbxOwner = OWN_HOST;
4592 pmboxq->context1 = NULL;
4593 pmboxq->vport = vport;
4595 if (vport->fc_flag & FC_OFFLINE_MODE)
4596 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4598 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4600 if (rc != MBX_SUCCESS) {
4601 if (rc != MBX_TIMEOUT)
4602 mempool_free(pmboxq, phba->mbox_mem_pool);
4606 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4607 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4608 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4609 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4610 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4611 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4612 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4614 hs->link_failure_count -= lso->link_failure_count;
4615 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4616 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4617 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4618 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4619 hs->invalid_crc_count -= lso->invalid_crc_count;
4620 hs->error_frames -= lso->error_frames;
4622 if (phba->hba_flag & HBA_FCOE_MODE) {
4624 hs->nos_count = (phba->link_events >> 1);
4625 hs->nos_count -= lso->link_events;
4626 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4627 hs->lip_count = (phba->fc_eventTag >> 1);
4628 hs->lip_count -= lso->link_events;
4632 hs->nos_count = (phba->fc_eventTag >> 1);
4633 hs->nos_count -= lso->link_events;
4636 hs->dumped_frames = -1;
4638 seconds = get_seconds();
4639 if (seconds < psli->stats_start)
4640 hs->seconds_since_last_reset = seconds +
4641 ((unsigned long)-1 - psli->stats_start);
4643 hs->seconds_since_last_reset = seconds - psli->stats_start;
4645 mempool_free(pmboxq, phba->mbox_mem_pool);
4651 * lpfc_reset_stats - Copy the adapter link stats information
4652 * @shost: kernel scsi host pointer.
4655 lpfc_reset_stats(struct Scsi_Host *shost)
4657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4658 struct lpfc_hba *phba = vport->phba;
4659 struct lpfc_sli *psli = &phba->sli;
4660 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4661 LPFC_MBOXQ_t *pmboxq;
4665 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4668 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4671 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4673 pmb = &pmboxq->u.mb;
4674 pmb->mbxCommand = MBX_READ_STATUS;
4675 pmb->mbxOwner = OWN_HOST;
4676 pmb->un.varWords[0] = 0x1; /* reset request */
4677 pmboxq->context1 = NULL;
4678 pmboxq->vport = vport;
4680 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4681 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4682 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4684 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4686 if (rc != MBX_SUCCESS) {
4687 if (rc != MBX_TIMEOUT)
4688 mempool_free(pmboxq, phba->mbox_mem_pool);
4692 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4693 pmb->mbxCommand = MBX_READ_LNK_STAT;
4694 pmb->mbxOwner = OWN_HOST;
4695 pmboxq->context1 = NULL;
4696 pmboxq->vport = vport;
4698 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4699 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4700 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4702 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4704 if (rc != MBX_SUCCESS) {
4705 if (rc != MBX_TIMEOUT)
4706 mempool_free( pmboxq, phba->mbox_mem_pool);
4710 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4711 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4712 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4713 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4714 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4715 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4716 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4717 if (phba->hba_flag & HBA_FCOE_MODE)
4718 lso->link_events = (phba->link_events >> 1);
4720 lso->link_events = (phba->fc_eventTag >> 1);
4722 psli->stats_start = get_seconds();
4724 mempool_free(pmboxq, phba->mbox_mem_pool);
4730 * The LPFC driver treats linkdown handling as target loss events so there
4731 * are no sysfs handlers for link_down_tmo.
4735 * lpfc_get_node_by_target - Return the nodelist for a target
4736 * @starget: kernel scsi target pointer.
4739 * address of the node list if found
4740 * NULL target not found
4742 static struct lpfc_nodelist *
4743 lpfc_get_node_by_target(struct scsi_target *starget)
4745 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4747 struct lpfc_nodelist *ndlp;
4749 spin_lock_irq(shost->host_lock);
4750 /* Search for this, mapped, target ID */
4751 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4752 if (NLP_CHK_NODE_ACT(ndlp) &&
4753 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4754 starget->id == ndlp->nlp_sid) {
4755 spin_unlock_irq(shost->host_lock);
4759 spin_unlock_irq(shost->host_lock);
4764 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4765 * @starget: kernel scsi target pointer.
4768 lpfc_get_starget_port_id(struct scsi_target *starget)
4770 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4772 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4776 * lpfc_get_starget_node_name - Set the target node name
4777 * @starget: kernel scsi target pointer.
4779 * Description: Set the target node name to the ndlp node name wwn or zero.
4782 lpfc_get_starget_node_name(struct scsi_target *starget)
4784 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4786 fc_starget_node_name(starget) =
4787 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4791 * lpfc_get_starget_port_name - Set the target port name
4792 * @starget: kernel scsi target pointer.
4794 * Description: set the target port name to the ndlp port name wwn or zero.
4797 lpfc_get_starget_port_name(struct scsi_target *starget)
4799 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4801 fc_starget_port_name(starget) =
4802 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4806 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4807 * @rport: fc rport address.
4808 * @timeout: new value for dev loss tmo.
4811 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4812 * dev_loss_tmo to one.
4815 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4818 rport->dev_loss_tmo = timeout;
4820 rport->dev_loss_tmo = 1;
4824 * lpfc_rport_show_function - Return rport target information
4827 * Macro that uses field to generate a function with the name lpfc_show_rport_
4829 * lpfc_show_rport_##field: returns the bytes formatted in buf
4830 * @cdev: class converted to an fc_rport.
4831 * @buf: on return contains the target_field or zero.
4833 * Returns: size of formatted string.
4835 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4837 lpfc_show_rport_##field (struct device *dev, \
4838 struct device_attribute *attr, \
4841 struct fc_rport *rport = transport_class_to_rport(dev); \
4842 struct lpfc_rport_data *rdata = rport->hostdata; \
4843 return snprintf(buf, sz, format_string, \
4844 (rdata->target) ? cast rdata->target->field : 0); \
4847 #define lpfc_rport_rd_attr(field, format_string, sz) \
4848 lpfc_rport_show_function(field, format_string, sz, ) \
4849 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4852 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4853 * @fc_vport: The fc_vport who's symbolic name has been changed.
4856 * This function is called by the transport after the @fc_vport's symbolic name
4857 * has been changed. This function re-registers the symbolic name with the
4858 * switch to propagate the change into the fabric if the vport is active.
4861 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4863 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4865 if (vport->port_state == LPFC_VPORT_READY)
4866 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4870 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4871 * @phba: Pointer to lpfc_hba struct.
4873 * This function is called by the lpfc_get_cfgparam() routine to set the
4874 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4875 * log message according to the module's lpfc_log_verbose parameter setting
4876 * before hba port or vport created.
4879 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4881 phba->cfg_log_verbose = verbose;
4884 struct fc_function_template lpfc_transport_functions = {
4885 /* fixed attributes the driver supports */
4886 .show_host_node_name = 1,
4887 .show_host_port_name = 1,
4888 .show_host_supported_classes = 1,
4889 .show_host_supported_fc4s = 1,
4890 .show_host_supported_speeds = 1,
4891 .show_host_maxframe_size = 1,
4892 .show_host_symbolic_name = 1,
4894 /* dynamic attributes the driver supports */
4895 .get_host_port_id = lpfc_get_host_port_id,
4896 .show_host_port_id = 1,
4898 .get_host_port_type = lpfc_get_host_port_type,
4899 .show_host_port_type = 1,
4901 .get_host_port_state = lpfc_get_host_port_state,
4902 .show_host_port_state = 1,
4904 /* active_fc4s is shown but doesn't change (thus no get function) */
4905 .show_host_active_fc4s = 1,
4907 .get_host_speed = lpfc_get_host_speed,
4908 .show_host_speed = 1,
4910 .get_host_fabric_name = lpfc_get_host_fabric_name,
4911 .show_host_fabric_name = 1,
4914 * The LPFC driver treats linkdown handling as target loss events
4915 * so there are no sysfs handlers for link_down_tmo.
4918 .get_fc_host_stats = lpfc_get_stats,
4919 .reset_fc_host_stats = lpfc_reset_stats,
4921 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4922 .show_rport_maxframe_size = 1,
4923 .show_rport_supported_classes = 1,
4925 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4926 .show_rport_dev_loss_tmo = 1,
4928 .get_starget_port_id = lpfc_get_starget_port_id,
4929 .show_starget_port_id = 1,
4931 .get_starget_node_name = lpfc_get_starget_node_name,
4932 .show_starget_node_name = 1,
4934 .get_starget_port_name = lpfc_get_starget_port_name,
4935 .show_starget_port_name = 1,
4937 .issue_fc_host_lip = lpfc_issue_lip,
4938 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4939 .terminate_rport_io = lpfc_terminate_rport_io,
4941 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4943 .vport_disable = lpfc_vport_disable,
4945 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4947 .bsg_request = lpfc_bsg_request,
4948 .bsg_timeout = lpfc_bsg_timeout,
4951 struct fc_function_template lpfc_vport_transport_functions = {
4952 /* fixed attributes the driver supports */
4953 .show_host_node_name = 1,
4954 .show_host_port_name = 1,
4955 .show_host_supported_classes = 1,
4956 .show_host_supported_fc4s = 1,
4957 .show_host_supported_speeds = 1,
4958 .show_host_maxframe_size = 1,
4959 .show_host_symbolic_name = 1,
4961 /* dynamic attributes the driver supports */
4962 .get_host_port_id = lpfc_get_host_port_id,
4963 .show_host_port_id = 1,
4965 .get_host_port_type = lpfc_get_host_port_type,
4966 .show_host_port_type = 1,
4968 .get_host_port_state = lpfc_get_host_port_state,
4969 .show_host_port_state = 1,
4971 /* active_fc4s is shown but doesn't change (thus no get function) */
4972 .show_host_active_fc4s = 1,
4974 .get_host_speed = lpfc_get_host_speed,
4975 .show_host_speed = 1,
4977 .get_host_fabric_name = lpfc_get_host_fabric_name,
4978 .show_host_fabric_name = 1,
4981 * The LPFC driver treats linkdown handling as target loss events
4982 * so there are no sysfs handlers for link_down_tmo.
4985 .get_fc_host_stats = lpfc_get_stats,
4986 .reset_fc_host_stats = lpfc_reset_stats,
4988 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4989 .show_rport_maxframe_size = 1,
4990 .show_rport_supported_classes = 1,
4992 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4993 .show_rport_dev_loss_tmo = 1,
4995 .get_starget_port_id = lpfc_get_starget_port_id,
4996 .show_starget_port_id = 1,
4998 .get_starget_node_name = lpfc_get_starget_node_name,
4999 .show_starget_node_name = 1,
5001 .get_starget_port_name = lpfc_get_starget_port_name,
5002 .show_starget_port_name = 1,
5004 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5005 .terminate_rport_io = lpfc_terminate_rport_io,
5007 .vport_disable = lpfc_vport_disable,
5009 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5013 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
5014 * @phba: lpfc_hba pointer.
5017 lpfc_get_cfgparam(struct lpfc_hba *phba)
5019 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5020 lpfc_cr_count_init(phba, lpfc_cr_count);
5021 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5022 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5023 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5024 lpfc_ack0_init(phba, lpfc_ack0);
5025 lpfc_topology_init(phba, lpfc_topology);
5026 lpfc_link_speed_init(phba, lpfc_link_speed);
5027 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5028 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5029 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
5030 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5031 lpfc_use_msi_init(phba, lpfc_use_msi);
5032 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5033 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5034 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
5035 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5036 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5037 lpfc_enable_bg_init(phba, lpfc_enable_bg);
5038 if (phba->sli_rev == LPFC_SLI_REV4)
5041 phba->cfg_poll = lpfc_poll;
5042 phba->cfg_soft_wwnn = 0L;
5043 phba->cfg_soft_wwpn = 0L;
5044 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5045 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5046 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5047 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5048 lpfc_aer_support_init(phba, lpfc_aer_support);
5049 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5050 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5051 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5052 phba->cfg_enable_dss = 1;
5057 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5058 * @vport: lpfc_vport pointer.
5061 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5063 lpfc_log_verbose_init(vport, lpfc_log_verbose);
5064 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5065 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5066 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5067 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5068 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5069 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5070 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5071 lpfc_use_adisc_init(vport, lpfc_use_adisc);
5072 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5073 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5074 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5075 lpfc_max_luns_init(vport, lpfc_max_luns);
5076 lpfc_scan_down_init(vport, lpfc_scan_down);
5077 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);