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/module.h>
27 #include <linux/aer.h>
28 #include <linux/gfp.h>
29 #include <linux/kernel.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
41 #include "lpfc_sli4.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_version.h"
48 #include "lpfc_compat.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
52 #define LPFC_DEF_DEVLOSS_TMO 30
53 #define LPFC_MIN_DEVLOSS_TMO 1
54 #define LPFC_MAX_DEVLOSS_TMO 255
57 * Write key size should be multiple of 4. If write key is changed
58 * make sure that library write key is also changed.
60 #define LPFC_REG_WRITE_KEY_SIZE 4
61 #define LPFC_REG_WRITE_KEY "EMLX"
64 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
65 * @incr: integer to convert.
66 * @hdw: ascii string holding converted integer plus a string terminator.
69 * JEDEC Joint Electron Device Engineering Council.
70 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71 * character string. The string is then terminated with a NULL in byte 9.
72 * Hex 0-9 becomes ascii '0' to '9'.
73 * Hex a-f becomes ascii '=' to 'B' capital B.
76 * Coded for 32 bit integers only.
79 lpfc_jedec_to_ascii(int incr, char hdw[])
82 for (i = 0; i < 8; i++) {
85 hdw[7 - i] = 0x30 + j;
87 hdw[7 - i] = 0x61 + j - 10;
95 * lpfc_drvr_version_show - Return the Emulex driver string with version number
96 * @dev: class unused variable.
97 * @attr: device attribute, not used.
98 * @buf: on return contains the module description text.
100 * Returns: size of formatted string.
103 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
106 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
110 * lpfc_enable_fip_show - Return the fip mode of the HBA
111 * @dev: class unused variable.
112 * @attr: device attribute, not used.
113 * @buf: on return contains the module description text.
115 * Returns: size of formatted string.
118 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
121 struct Scsi_Host *shost = class_to_shost(dev);
122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
125 if (phba->hba_flag & HBA_FIP_SUPPORT)
126 return snprintf(buf, PAGE_SIZE, "1\n");
128 return snprintf(buf, PAGE_SIZE, "0\n");
132 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
139 if (phba->cfg_enable_bg)
140 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
143 return snprintf(buf, PAGE_SIZE,
144 "BlockGuard Not Supported\n");
146 return snprintf(buf, PAGE_SIZE,
147 "BlockGuard Disabled\n");
151 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
154 struct Scsi_Host *shost = class_to_shost(dev);
155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156 struct lpfc_hba *phba = vport->phba;
158 return snprintf(buf, PAGE_SIZE, "%llu\n",
159 (unsigned long long)phba->bg_guard_err_cnt);
163 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
166 struct Scsi_Host *shost = class_to_shost(dev);
167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 struct lpfc_hba *phba = vport->phba;
170 return snprintf(buf, PAGE_SIZE, "%llu\n",
171 (unsigned long long)phba->bg_apptag_err_cnt);
175 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
178 struct Scsi_Host *shost = class_to_shost(dev);
179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 struct lpfc_hba *phba = vport->phba;
182 return snprintf(buf, PAGE_SIZE, "%llu\n",
183 (unsigned long long)phba->bg_reftag_err_cnt);
187 * lpfc_info_show - Return some pci info about the host in ascii
188 * @dev: class converted to a Scsi_host structure.
189 * @attr: device attribute, not used.
190 * @buf: on return contains the formatted text from lpfc_info().
192 * Returns: size of formatted string.
195 lpfc_info_show(struct device *dev, struct device_attribute *attr,
198 struct Scsi_Host *host = class_to_shost(dev);
200 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
204 * lpfc_serialnum_show - Return the hba serial number in ascii
205 * @dev: class converted to a Scsi_host structure.
206 * @attr: device attribute, not used.
207 * @buf: on return contains the formatted text serial number.
209 * Returns: size of formatted string.
212 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
215 struct Scsi_Host *shost = class_to_shost(dev);
216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217 struct lpfc_hba *phba = vport->phba;
219 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
223 * lpfc_temp_sensor_show - Return the temperature sensor level
224 * @dev: class converted to a Scsi_host structure.
225 * @attr: device attribute, not used.
226 * @buf: on return contains the formatted support level.
229 * Returns a number indicating the temperature sensor level currently
230 * supported, zero or one in ascii.
232 * Returns: size of formatted string.
235 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
238 struct Scsi_Host *shost = class_to_shost(dev);
239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 struct lpfc_hba *phba = vport->phba;
241 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
245 * lpfc_modeldesc_show - Return the model description of the hba
246 * @dev: class converted to a Scsi_host structure.
247 * @attr: device attribute, not used.
248 * @buf: on return contains the scsi vpd model description.
250 * Returns: size of formatted string.
253 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
256 struct Scsi_Host *shost = class_to_shost(dev);
257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258 struct lpfc_hba *phba = vport->phba;
260 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
264 * lpfc_modelname_show - Return the model name of the hba
265 * @dev: class converted to a Scsi_host structure.
266 * @attr: device attribute, not used.
267 * @buf: on return contains the scsi vpd model name.
269 * Returns: size of formatted string.
272 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
275 struct Scsi_Host *shost = class_to_shost(dev);
276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277 struct lpfc_hba *phba = vport->phba;
279 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
283 * lpfc_programtype_show - Return the program type of the hba
284 * @dev: class converted to a Scsi_host structure.
285 * @attr: device attribute, not used.
286 * @buf: on return contains the scsi vpd program type.
288 * Returns: size of formatted string.
291 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
294 struct Scsi_Host *shost = class_to_shost(dev);
295 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296 struct lpfc_hba *phba = vport->phba;
298 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
302 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
303 * @dev: class converted to a Scsi_host structure.
304 * @attr: device attribute, not used.
305 * @buf: on return contains the Menlo Maintenance sli flag.
307 * Returns: size of formatted string.
310 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
312 struct Scsi_Host *shost = class_to_shost(dev);
313 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314 struct lpfc_hba *phba = vport->phba;
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
321 * lpfc_vportnum_show - Return the port number in ascii of the hba
322 * @dev: class converted to a Scsi_host structure.
323 * @attr: device attribute, not used.
324 * @buf: on return contains scsi vpd program type.
326 * Returns: size of formatted string.
329 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
332 struct Scsi_Host *shost = class_to_shost(dev);
333 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334 struct lpfc_hba *phba = vport->phba;
336 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
340 * lpfc_fwrev_show - Return the firmware rev running in the hba
341 * @dev: class converted to a Scsi_host structure.
342 * @attr: device attribute, not used.
343 * @buf: on return contains the scsi vpd program type.
345 * Returns: size of formatted string.
348 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
351 struct Scsi_Host *shost = class_to_shost(dev);
352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
356 lpfc_decode_firmware_rev(phba, fwrev, 1);
357 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
361 * lpfc_hdw_show - Return the jedec information about the hba
362 * @dev: class converted to a Scsi_host structure.
363 * @attr: device attribute, not used.
364 * @buf: on return contains the scsi vpd program type.
366 * Returns: size of formatted string.
369 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
372 struct Scsi_Host *shost = class_to_shost(dev);
373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
374 struct lpfc_hba *phba = vport->phba;
375 lpfc_vpd_t *vp = &phba->vpd;
377 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
378 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
382 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
383 * @dev: class converted to a Scsi_host structure.
384 * @attr: device attribute, not used.
385 * @buf: on return contains the ROM and FCode ascii strings.
387 * Returns: size of formatted string.
390 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
393 struct Scsi_Host *shost = class_to_shost(dev);
394 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
395 struct lpfc_hba *phba = vport->phba;
397 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
401 * lpfc_state_show - Return the link state of the port
402 * @dev: class converted to a Scsi_host structure.
403 * @attr: device attribute, not used.
404 * @buf: on return contains text describing the state of the link.
407 * The switch statement has no default so zero will be returned.
409 * Returns: size of formatted string.
412 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
415 struct Scsi_Host *shost = class_to_shost(dev);
416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
420 switch (phba->link_state) {
421 case LPFC_LINK_UNKNOWN:
422 case LPFC_WARM_START:
423 case LPFC_INIT_START:
424 case LPFC_INIT_MBX_CMDS:
427 if (phba->hba_flag & LINK_DISABLED)
428 len += snprintf(buf + len, PAGE_SIZE-len,
429 "Link Down - User disabled\n");
431 len += snprintf(buf + len, PAGE_SIZE-len,
437 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
439 switch (vport->port_state) {
440 case LPFC_LOCAL_CFG_LINK:
441 len += snprintf(buf + len, PAGE_SIZE-len,
442 "Configuring Link\n");
446 case LPFC_FABRIC_CFG_LINK:
449 case LPFC_BUILD_DISC_LIST:
451 len += snprintf(buf + len, PAGE_SIZE - len,
454 case LPFC_VPORT_READY:
455 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
458 case LPFC_VPORT_FAILED:
459 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
462 case LPFC_VPORT_UNKNOWN:
463 len += snprintf(buf + len, PAGE_SIZE - len,
467 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
468 len += snprintf(buf + len, PAGE_SIZE-len,
469 " Menlo Maint Mode\n");
470 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
471 if (vport->fc_flag & FC_PUBLIC_LOOP)
472 len += snprintf(buf + len, PAGE_SIZE-len,
475 len += snprintf(buf + len, PAGE_SIZE-len,
478 if (vport->fc_flag & FC_FABRIC)
479 len += snprintf(buf + len, PAGE_SIZE-len,
482 len += snprintf(buf + len, PAGE_SIZE-len,
491 * lpfc_link_state_store - Transition the link_state on an HBA port
492 * @dev: class device that is converted into a Scsi_host.
493 * @attr: device attribute, not used.
494 * @buf: one or more lpfc_polling_flags values.
498 * -EINVAL if the buffer is not "up" or "down"
499 * return from link state change function if non-zero
500 * length of the buf on success
503 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
504 const char *buf, size_t count)
506 struct Scsi_Host *shost = class_to_shost(dev);
507 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
508 struct lpfc_hba *phba = vport->phba;
510 int status = -EINVAL;
512 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
513 (phba->link_state == LPFC_LINK_DOWN))
514 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
515 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
516 (phba->link_state >= LPFC_LINK_UP))
517 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
526 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
527 * @dev: class device that is converted into a Scsi_host.
528 * @attr: device attribute, not used.
529 * @buf: on return contains the sum of fc mapped and unmapped.
532 * Returns the ascii text number of the sum of the fc mapped and unmapped
535 * Returns: size of formatted string.
538 lpfc_num_discovered_ports_show(struct device *dev,
539 struct device_attribute *attr, char *buf)
541 struct Scsi_Host *shost = class_to_shost(dev);
542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
544 return snprintf(buf, PAGE_SIZE, "%d\n",
545 vport->fc_map_cnt + vport->fc_unmap_cnt);
549 * lpfc_issue_lip - Misnomer, name carried over from long ago
550 * @shost: Scsi_Host pointer.
553 * Bring the link down gracefully then re-init the link. The firmware will
554 * re-init the fiber channel interface as required. Does not issue a LIP.
557 * -EPERM port offline or management commands are being blocked
558 * -ENOMEM cannot allocate memory for the mailbox command
559 * -EIO error sending the mailbox command
563 lpfc_issue_lip(struct Scsi_Host *shost)
565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
566 struct lpfc_hba *phba = vport->phba;
567 LPFC_MBOXQ_t *pmboxq;
568 int mbxstatus = MBXERR_ERROR;
570 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
571 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
574 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
579 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
580 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
581 pmboxq->u.mb.mbxOwner = OWN_HOST;
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == 0 ||
587 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
588 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
589 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
590 phba->cfg_link_speed);
591 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
593 if ((mbxstatus == MBX_SUCCESS) &&
594 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
595 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
596 "2859 SLI authentication is required "
597 "for INIT_LINK but has not done yet\n");
600 lpfc_set_loopback_flag(phba);
601 if (mbxstatus != MBX_TIMEOUT)
602 mempool_free(pmboxq, phba->mbox_mem_pool);
604 if (mbxstatus == MBXERR_ERROR)
611 * lpfc_do_offline - Issues a mailbox command to bring the link down
612 * @phba: lpfc_hba pointer.
613 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
616 * Assumes any error from lpfc_do_offline() will be negative.
617 * Can wait up to 5 seconds for the port ring buffers count
618 * to reach zero, prints a warning if it is not zero and continues.
619 * lpfc_workq_post_event() returns a non-zero return code if call fails.
622 * -EIO error posting the event
626 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
628 struct completion online_compl;
629 struct lpfc_sli_ring *pring;
630 struct lpfc_sli *psli;
636 init_completion(&online_compl);
637 rc = lpfc_workq_post_event(phba, &status, &online_compl,
638 LPFC_EVT_OFFLINE_PREP);
642 wait_for_completion(&online_compl);
649 /* Wait a little for things to settle down, but not
650 * long enough for dev loss timeout to expire.
652 for (i = 0; i < psli->num_rings; i++) {
653 pring = &psli->ring[i];
654 while (pring->txcmplq_cnt) {
656 if (cnt++ > 500) { /* 5 secs */
657 lpfc_printf_log(phba,
658 KERN_WARNING, LOG_INIT,
659 "0466 Outstanding IO when "
660 "bringing Adapter offline\n");
666 init_completion(&online_compl);
667 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
671 wait_for_completion(&online_compl);
680 * lpfc_selective_reset - Offline then onlines the port
681 * @phba: lpfc_hba pointer.
684 * If the port is configured to allow a reset then the hba is brought
685 * offline then online.
688 * Assumes any error from lpfc_do_offline() will be negative.
689 * Do not make this function static.
692 * lpfc_do_offline() return code if not zero
693 * -EIO reset not configured or error posting the event
697 lpfc_selective_reset(struct lpfc_hba *phba)
699 struct completion online_compl;
703 if (!phba->cfg_enable_hba_reset)
706 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
711 init_completion(&online_compl);
712 rc = lpfc_workq_post_event(phba, &status, &online_compl,
717 wait_for_completion(&online_compl);
726 * lpfc_issue_reset - Selectively resets an adapter
727 * @dev: class device that is converted into a Scsi_host.
728 * @attr: device attribute, not used.
729 * @buf: containing the string "selective".
730 * @count: unused variable.
733 * If the buf contains the string "selective" then lpfc_selective_reset()
734 * is called to perform the reset.
737 * Assumes any error from lpfc_selective_reset() will be negative.
738 * If lpfc_selective_reset() returns zero then the length of the buffer
739 * is returned which indicates success
742 * -EINVAL if the buffer does not contain the string "selective"
743 * length of buf if lpfc-selective_reset() if the call succeeds
744 * return value of lpfc_selective_reset() if the call fails
747 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
748 const char *buf, size_t count)
750 struct Scsi_Host *shost = class_to_shost(dev);
751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
752 struct lpfc_hba *phba = vport->phba;
753 int status = -EINVAL;
755 if (!phba->cfg_enable_hba_reset)
758 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
759 status = phba->lpfc_selective_reset(phba);
768 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
769 * @phba: lpfc_hba pointer.
772 * SLI4 interface type-2 device to wait on the sliport status register for
773 * the readyness after performing a firmware reset.
779 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
781 struct lpfc_register portstat_reg = {0};
785 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
786 &portstat_reg.word0);
788 /* verify if privilaged for the request operation */
789 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
790 !bf_get(lpfc_sliport_status_err, &portstat_reg))
793 /* wait for the SLI port firmware ready after firmware reset */
794 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
796 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
797 &portstat_reg.word0);
798 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
800 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
802 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
807 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
814 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
815 * @phba: lpfc_hba pointer.
818 * Request SLI4 interface type-2 device to perform a physical register set
825 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
827 struct completion online_compl;
828 struct pci_dev *pdev = phba->pcidev;
833 if (!phba->cfg_enable_hba_reset)
836 if ((phba->sli_rev < LPFC_SLI_REV4) ||
837 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
838 LPFC_SLI_INTF_IF_TYPE_2))
841 /* Disable SR-IOV virtual functions if enabled */
842 if (phba->cfg_sriov_nr_virtfn) {
843 pci_disable_sriov(pdev);
844 phba->cfg_sriov_nr_virtfn = 0;
846 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
851 /* wait for the device to be quiesced before firmware reset */
854 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
855 LPFC_CTL_PDEV_CTL_OFFSET);
857 if (opcode == LPFC_FW_DUMP)
858 reg_val |= LPFC_FW_DUMP_REQUEST;
859 else if (opcode == LPFC_FW_RESET)
860 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
861 else if (opcode == LPFC_DV_RESET)
862 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
864 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
865 LPFC_CTL_PDEV_CTL_OFFSET);
867 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
869 /* delay driver action following IF_TYPE_2 reset */
870 rc = lpfc_sli4_pdev_status_reg_wait(phba);
875 init_completion(&online_compl);
876 rc = lpfc_workq_post_event(phba, &status, &online_compl,
881 wait_for_completion(&online_compl);
890 * lpfc_nport_evt_cnt_show - Return the number of nport events
891 * @dev: class device that is converted into a Scsi_host.
892 * @attr: device attribute, not used.
893 * @buf: on return contains the ascii number of nport events.
895 * Returns: size of formatted string.
898 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
901 struct Scsi_Host *shost = class_to_shost(dev);
902 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
903 struct lpfc_hba *phba = vport->phba;
905 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
909 * lpfc_board_mode_show - Return the state of the board
910 * @dev: class device that is converted into a Scsi_host.
911 * @attr: device attribute, not used.
912 * @buf: on return contains the state of the adapter.
914 * Returns: size of formatted string.
917 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
920 struct Scsi_Host *shost = class_to_shost(dev);
921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
922 struct lpfc_hba *phba = vport->phba;
925 if (phba->link_state == LPFC_HBA_ERROR)
927 else if (phba->link_state == LPFC_WARM_START)
928 state = "warm start";
929 else if (phba->link_state == LPFC_INIT_START)
934 return snprintf(buf, PAGE_SIZE, "%s\n", state);
938 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
939 * @dev: class device that is converted into a Scsi_host.
940 * @attr: device attribute, not used.
941 * @buf: containing one of the strings "online", "offline", "warm" or "error".
942 * @count: unused variable.
945 * -EACCES if enable hba reset not enabled
946 * -EINVAL if the buffer does not contain a valid string (see above)
947 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
948 * buf length greater than zero indicates success
951 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
952 const char *buf, size_t count)
954 struct Scsi_Host *shost = class_to_shost(dev);
955 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
956 struct lpfc_hba *phba = vport->phba;
957 struct completion online_compl;
961 if (!phba->cfg_enable_hba_reset)
964 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
965 "3050 lpfc_board_mode set to %s\n", buf);
967 init_completion(&online_compl);
969 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
970 rc = lpfc_workq_post_event(phba, &status, &online_compl,
974 wait_for_completion(&online_compl);
975 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
976 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
977 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
978 if (phba->sli_rev == LPFC_SLI_REV4)
981 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
982 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
983 if (phba->sli_rev == LPFC_SLI_REV4)
986 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
987 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
988 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
989 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
990 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
991 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
992 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1003 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1004 * @phba: pointer to the adapter structure.
1005 * @mxri: max xri count.
1006 * @axri: available xri count.
1007 * @mrpi: max rpi count.
1008 * @arpi: available rpi count.
1009 * @mvpi: max vpi count.
1010 * @avpi: available vpi count.
1013 * If an integer pointer for an count is not null then the value for the
1014 * count is returned.
1021 lpfc_get_hba_info(struct lpfc_hba *phba,
1022 uint32_t *mxri, uint32_t *axri,
1023 uint32_t *mrpi, uint32_t *arpi,
1024 uint32_t *mvpi, uint32_t *avpi)
1026 struct lpfc_mbx_read_config *rd_config;
1027 LPFC_MBOXQ_t *pmboxq;
1033 * prevent udev from issuing mailbox commands until the port is
1036 if (phba->link_state < LPFC_LINK_DOWN ||
1037 !phba->mbox_mem_pool ||
1038 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1041 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1044 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1047 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1049 pmb = &pmboxq->u.mb;
1050 pmb->mbxCommand = MBX_READ_CONFIG;
1051 pmb->mbxOwner = OWN_HOST;
1052 pmboxq->context1 = NULL;
1054 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1055 rc = MBX_NOT_FINISHED;
1057 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1059 if (rc != MBX_SUCCESS) {
1060 if (rc != MBX_TIMEOUT)
1061 mempool_free(pmboxq, phba->mbox_mem_pool);
1065 if (phba->sli_rev == LPFC_SLI_REV4) {
1066 rd_config = &pmboxq->u.mqe.un.rd_config;
1068 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1070 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1071 phba->sli4_hba.max_cfg_param.rpi_used;
1073 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1075 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1076 phba->sli4_hba.max_cfg_param.xri_used;
1078 /* Account for differences with SLI-3. Get vpi count from
1079 * mailbox data and subtract one for max vpi value.
1081 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1082 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1087 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1090 *mrpi = pmb->un.varRdConfig.max_rpi;
1092 *arpi = pmb->un.varRdConfig.avail_rpi;
1094 *mxri = pmb->un.varRdConfig.max_xri;
1096 *axri = pmb->un.varRdConfig.avail_xri;
1098 *mvpi = pmb->un.varRdConfig.max_vpi;
1100 *avpi = pmb->un.varRdConfig.avail_vpi;
1103 mempool_free(pmboxq, phba->mbox_mem_pool);
1108 * lpfc_max_rpi_show - Return maximum rpi
1109 * @dev: class device that is converted into a Scsi_host.
1110 * @attr: device attribute, not used.
1111 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1114 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1115 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1116 * to "Unknown" and the buffer length is returned, therefore the caller
1117 * must check for "Unknown" in the buffer to detect a failure.
1119 * Returns: size of formatted string.
1122 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1125 struct Scsi_Host *shost = class_to_shost(dev);
1126 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1127 struct lpfc_hba *phba = vport->phba;
1130 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1131 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1132 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1136 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1137 * @dev: class device that is converted into a Scsi_host.
1138 * @attr: device attribute, not used.
1139 * @buf: containing the used rpi count in decimal or "Unknown".
1142 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1143 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1144 * to "Unknown" and the buffer length is returned, therefore the caller
1145 * must check for "Unknown" in the buffer to detect a failure.
1147 * Returns: size of formatted string.
1150 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1153 struct Scsi_Host *shost = class_to_shost(dev);
1154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1155 struct lpfc_hba *phba = vport->phba;
1158 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1159 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1160 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1164 * lpfc_max_xri_show - Return maximum xri
1165 * @dev: class device that is converted into a Scsi_host.
1166 * @attr: device attribute, not used.
1167 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1170 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1171 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1172 * to "Unknown" and the buffer length is returned, therefore the caller
1173 * must check for "Unknown" in the buffer to detect a failure.
1175 * Returns: size of formatted string.
1178 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1181 struct Scsi_Host *shost = class_to_shost(dev);
1182 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1183 struct lpfc_hba *phba = vport->phba;
1186 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1187 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1188 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1192 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1193 * @dev: class device that is converted into a Scsi_host.
1194 * @attr: device attribute, not used.
1195 * @buf: on return contains the used xri count in decimal or "Unknown".
1198 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1199 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1200 * to "Unknown" and the buffer length is returned, therefore the caller
1201 * must check for "Unknown" in the buffer to detect a failure.
1203 * Returns: size of formatted string.
1206 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1209 struct Scsi_Host *shost = class_to_shost(dev);
1210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1211 struct lpfc_hba *phba = vport->phba;
1214 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1215 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1216 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1220 * lpfc_max_vpi_show - Return maximum vpi
1221 * @dev: class device that is converted into a Scsi_host.
1222 * @attr: device attribute, not used.
1223 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1226 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1227 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1228 * to "Unknown" and the buffer length is returned, therefore the caller
1229 * must check for "Unknown" in the buffer to detect a failure.
1231 * Returns: size of formatted string.
1234 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1237 struct Scsi_Host *shost = class_to_shost(dev);
1238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1239 struct lpfc_hba *phba = vport->phba;
1242 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1243 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1244 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1248 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1249 * @dev: class device that is converted into a Scsi_host.
1250 * @attr: device attribute, not used.
1251 * @buf: on return contains the used vpi count in decimal or "Unknown".
1254 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1255 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1256 * to "Unknown" and the buffer length is returned, therefore the caller
1257 * must check for "Unknown" in the buffer to detect a failure.
1259 * Returns: size of formatted string.
1262 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1265 struct Scsi_Host *shost = class_to_shost(dev);
1266 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1267 struct lpfc_hba *phba = vport->phba;
1270 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1271 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1272 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1276 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1277 * @dev: class device that is converted into a Scsi_host.
1278 * @attr: device attribute, not used.
1279 * @buf: text that must be interpreted to determine if npiv is supported.
1282 * Buffer will contain text indicating npiv is not suppoerted on the port,
1283 * the port is an NPIV physical port, or it is an npiv virtual port with
1284 * the id of the vport.
1286 * Returns: size of formatted string.
1289 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1292 struct Scsi_Host *shost = class_to_shost(dev);
1293 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1294 struct lpfc_hba *phba = vport->phba;
1296 if (!(phba->max_vpi))
1297 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1298 if (vport->port_type == LPFC_PHYSICAL_PORT)
1299 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1300 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1304 * lpfc_poll_show - Return text about poll support for the adapter
1305 * @dev: class device that is converted into a Scsi_host.
1306 * @attr: device attribute, not used.
1307 * @buf: on return contains the cfg_poll in hex.
1310 * cfg_poll should be a lpfc_polling_flags type.
1312 * Returns: size of formatted string.
1315 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1318 struct Scsi_Host *shost = class_to_shost(dev);
1319 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1320 struct lpfc_hba *phba = vport->phba;
1322 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1326 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1327 * @dev: class device that is converted into a Scsi_host.
1328 * @attr: device attribute, not used.
1329 * @buf: one or more lpfc_polling_flags values.
1333 * buf contents converted to integer and checked for a valid value.
1336 * -EINVAL if the buffer connot be converted or is out of range
1337 * length of the buf on success
1340 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1341 const char *buf, size_t count)
1343 struct Scsi_Host *shost = class_to_shost(dev);
1344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1345 struct lpfc_hba *phba = vport->phba;
1350 if (!isdigit(buf[0]))
1353 if (sscanf(buf, "%i", &val) != 1)
1356 if ((val & 0x3) != val)
1359 if (phba->sli_rev == LPFC_SLI_REV4)
1362 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1363 "3051 lpfc_poll changed from %d to %d\n",
1364 phba->cfg_poll, val);
1366 spin_lock_irq(&phba->hbalock);
1368 old_val = phba->cfg_poll;
1370 if (val & ENABLE_FCP_RING_POLLING) {
1371 if ((val & DISABLE_FCP_RING_INT) &&
1372 !(old_val & DISABLE_FCP_RING_INT)) {
1373 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1374 spin_unlock_irq(&phba->hbalock);
1377 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1378 writel(creg_val, phba->HCregaddr);
1379 readl(phba->HCregaddr); /* flush */
1381 lpfc_poll_start_timer(phba);
1383 } else if (val != 0x0) {
1384 spin_unlock_irq(&phba->hbalock);
1388 if (!(val & DISABLE_FCP_RING_INT) &&
1389 (old_val & DISABLE_FCP_RING_INT))
1391 spin_unlock_irq(&phba->hbalock);
1392 del_timer(&phba->fcp_poll_timer);
1393 spin_lock_irq(&phba->hbalock);
1394 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1395 spin_unlock_irq(&phba->hbalock);
1398 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1399 writel(creg_val, phba->HCregaddr);
1400 readl(phba->HCregaddr); /* flush */
1403 phba->cfg_poll = val;
1405 spin_unlock_irq(&phba->hbalock);
1411 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1412 * @dev: class unused variable.
1413 * @attr: device attribute, not used.
1414 * @buf: on return contains the module description text.
1416 * Returns: size of formatted string.
1419 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1422 struct Scsi_Host *shost = class_to_shost(dev);
1423 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1424 struct lpfc_hba *phba = vport->phba;
1426 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1430 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1431 * @dev: class unused variable.
1432 * @attr: device attribute, not used.
1433 * @buf: on return contains the module description text.
1435 * Returns: size of formatted string.
1438 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1441 struct Scsi_Host *shost = class_to_shost(dev);
1442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1443 struct lpfc_hba *phba = vport->phba;
1445 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1449 * lpfc_dss_show - Return the current state of dss and the configured state
1450 * @dev: class converted to a Scsi_host structure.
1451 * @attr: device attribute, not used.
1452 * @buf: on return contains the formatted text.
1454 * Returns: size of formatted string.
1457 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1460 struct Scsi_Host *shost = class_to_shost(dev);
1461 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1462 struct lpfc_hba *phba = vport->phba;
1464 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1465 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1466 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1471 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1472 * @dev: class converted to a Scsi_host structure.
1473 * @attr: device attribute, not used.
1474 * @buf: on return contains the formatted support level.
1477 * Returns the maximum number of virtual functions a physical function can
1478 * support, 0 will be returned if called on virtual function.
1480 * Returns: size of formatted string.
1483 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1484 struct device_attribute *attr,
1487 struct Scsi_Host *shost = class_to_shost(dev);
1488 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1489 struct lpfc_hba *phba = vport->phba;
1490 uint16_t max_nr_virtfn;
1492 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1493 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1497 * lpfc_param_show - Return a cfg attribute value in decimal
1500 * Macro that given an attr e.g. hba_queue_depth expands
1501 * into a function with the name lpfc_hba_queue_depth_show.
1503 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1504 * @dev: class device that is converted into a Scsi_host.
1505 * @attr: device attribute, not used.
1506 * @buf: on return contains the attribute value in decimal.
1508 * Returns: size of formatted string.
1510 #define lpfc_param_show(attr) \
1512 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1515 struct Scsi_Host *shost = class_to_shost(dev);\
1516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1517 struct lpfc_hba *phba = vport->phba;\
1519 val = phba->cfg_##attr;\
1520 return snprintf(buf, PAGE_SIZE, "%d\n",\
1525 * lpfc_param_hex_show - Return a cfg attribute value in hex
1528 * Macro that given an attr e.g. hba_queue_depth expands
1529 * into a function with the name lpfc_hba_queue_depth_show
1531 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1532 * @dev: class device that is converted into a Scsi_host.
1533 * @attr: device attribute, not used.
1534 * @buf: on return contains the attribute value in hexadecimal.
1536 * Returns: size of formatted string.
1538 #define lpfc_param_hex_show(attr) \
1540 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1543 struct Scsi_Host *shost = class_to_shost(dev);\
1544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1545 struct lpfc_hba *phba = vport->phba;\
1547 val = phba->cfg_##attr;\
1548 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1553 * lpfc_param_init - Initializes a cfg attribute
1556 * Macro that given an attr e.g. hba_queue_depth expands
1557 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1558 * takes a default argument, a minimum and maximum argument.
1560 * lpfc_##attr##_init: Initializes an attribute.
1561 * @phba: pointer the the adapter structure.
1562 * @val: integer attribute value.
1564 * Validates the min and max values then sets the adapter config field
1565 * accordingly, or uses the default if out of range and prints an error message.
1569 * -EINVAL if default used
1571 #define lpfc_param_init(attr, default, minval, maxval) \
1573 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1575 if (val >= minval && val <= maxval) {\
1576 phba->cfg_##attr = val;\
1579 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1580 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1581 "allowed range is ["#minval", "#maxval"]\n", val); \
1582 phba->cfg_##attr = default;\
1587 * lpfc_param_set - Set a cfg attribute value
1590 * Macro that given an attr e.g. hba_queue_depth expands
1591 * into a function with the name lpfc_hba_queue_depth_set
1593 * lpfc_##attr##_set: Sets an attribute value.
1594 * @phba: pointer the the adapter structure.
1595 * @val: integer attribute value.
1598 * Validates the min and max values then sets the
1599 * adapter config field if in the valid range. prints error message
1600 * and does not set the parameter if invalid.
1604 * -EINVAL if val is invalid
1606 #define lpfc_param_set(attr, default, minval, maxval) \
1608 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1610 if (val >= minval && val <= maxval) {\
1611 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1612 "3052 lpfc_" #attr " changed from %d to %d\n", \
1613 phba->cfg_##attr, val); \
1614 phba->cfg_##attr = val;\
1617 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1618 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1619 "allowed range is ["#minval", "#maxval"]\n", val); \
1624 * lpfc_param_store - Set a vport attribute value
1627 * Macro that given an attr e.g. hba_queue_depth expands
1628 * into a function with the name lpfc_hba_queue_depth_store.
1630 * lpfc_##attr##_store: Set an sttribute value.
1631 * @dev: class device that is converted into a Scsi_host.
1632 * @attr: device attribute, not used.
1633 * @buf: contains the attribute value in ascii.
1637 * Convert the ascii text number to an integer, then
1638 * use the lpfc_##attr##_set function to set the value.
1641 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1642 * length of buffer upon success.
1644 #define lpfc_param_store(attr) \
1646 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1647 const char *buf, size_t count) \
1649 struct Scsi_Host *shost = class_to_shost(dev);\
1650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1651 struct lpfc_hba *phba = vport->phba;\
1653 if (!isdigit(buf[0]))\
1655 if (sscanf(buf, "%i", &val) != 1)\
1657 if (lpfc_##attr##_set(phba, val) == 0) \
1658 return strlen(buf);\
1664 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1667 * Macro that given an attr e.g. hba_queue_depth expands
1668 * into a function with the name lpfc_hba_queue_depth_show
1670 * lpfc_##attr##_show: prints the attribute value in decimal.
1671 * @dev: class device that is converted into a Scsi_host.
1672 * @attr: device attribute, not used.
1673 * @buf: on return contains the attribute value in decimal.
1675 * Returns: length of formatted string.
1677 #define lpfc_vport_param_show(attr) \
1679 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1682 struct Scsi_Host *shost = class_to_shost(dev);\
1683 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1685 val = vport->cfg_##attr;\
1686 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1690 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1693 * Macro that given an attr e.g.
1694 * hba_queue_depth expands into a function with the name
1695 * lpfc_hba_queue_depth_show
1697 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1698 * @dev: class device that is converted into a Scsi_host.
1699 * @attr: device attribute, not used.
1700 * @buf: on return contains the attribute value in hexadecimal.
1702 * Returns: length of formatted string.
1704 #define lpfc_vport_param_hex_show(attr) \
1706 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1709 struct Scsi_Host *shost = class_to_shost(dev);\
1710 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1712 val = vport->cfg_##attr;\
1713 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1717 * lpfc_vport_param_init - Initialize a vport cfg attribute
1720 * Macro that given an attr e.g. hba_queue_depth expands
1721 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1722 * takes a default argument, a minimum and maximum argument.
1724 * lpfc_##attr##_init: validates the min and max values then sets the
1725 * adapter config field accordingly, or uses the default if out of range
1726 * and prints an error message.
1727 * @phba: pointer the the adapter structure.
1728 * @val: integer attribute value.
1732 * -EINVAL if default used
1734 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1736 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1738 if (val >= minval && val <= maxval) {\
1739 vport->cfg_##attr = val;\
1742 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1743 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1744 "allowed range is ["#minval", "#maxval"]\n", val); \
1745 vport->cfg_##attr = default;\
1750 * lpfc_vport_param_set - Set a vport cfg attribute
1753 * Macro that given an attr e.g. hba_queue_depth expands
1754 * into a function with the name lpfc_hba_queue_depth_set
1756 * lpfc_##attr##_set: validates the min and max values then sets the
1757 * adapter config field if in the valid range. prints error message
1758 * and does not set the parameter if invalid.
1759 * @phba: pointer the the adapter structure.
1760 * @val: integer attribute value.
1764 * -EINVAL if val is invalid
1766 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1768 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1770 if (val >= minval && val <= maxval) {\
1771 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1772 "3053 lpfc_" #attr " changed from %d to %d\n", \
1773 vport->cfg_##attr, val); \
1774 vport->cfg_##attr = val;\
1777 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1778 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1779 "allowed range is ["#minval", "#maxval"]\n", val); \
1784 * lpfc_vport_param_store - Set a vport attribute
1787 * Macro that given an attr e.g. hba_queue_depth
1788 * expands into a function with the name lpfc_hba_queue_depth_store
1790 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1791 * use the lpfc_##attr##_set function to set the value.
1792 * @cdev: class device that is converted into a Scsi_host.
1793 * @buf: contains the attribute value in decimal.
1797 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1798 * length of buffer upon success.
1800 #define lpfc_vport_param_store(attr) \
1802 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1803 const char *buf, size_t count) \
1805 struct Scsi_Host *shost = class_to_shost(dev);\
1806 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1808 if (!isdigit(buf[0]))\
1810 if (sscanf(buf, "%i", &val) != 1)\
1812 if (lpfc_##attr##_set(vport, val) == 0) \
1813 return strlen(buf);\
1819 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1820 static uint lpfc_##name = defval;\
1821 module_param(lpfc_##name, uint, S_IRUGO);\
1822 MODULE_PARM_DESC(lpfc_##name, desc);\
1823 lpfc_param_init(name, defval, minval, maxval)
1825 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1826 static uint lpfc_##name = defval;\
1827 module_param(lpfc_##name, uint, S_IRUGO);\
1828 MODULE_PARM_DESC(lpfc_##name, desc);\
1829 lpfc_param_show(name)\
1830 lpfc_param_init(name, defval, minval, maxval)\
1831 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1833 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1834 static uint lpfc_##name = defval;\
1835 module_param(lpfc_##name, uint, S_IRUGO);\
1836 MODULE_PARM_DESC(lpfc_##name, desc);\
1837 lpfc_param_show(name)\
1838 lpfc_param_init(name, defval, minval, maxval)\
1839 lpfc_param_set(name, defval, minval, maxval)\
1840 lpfc_param_store(name)\
1841 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1842 lpfc_##name##_show, lpfc_##name##_store)
1844 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1845 static uint lpfc_##name = defval;\
1846 module_param(lpfc_##name, uint, S_IRUGO);\
1847 MODULE_PARM_DESC(lpfc_##name, desc);\
1848 lpfc_param_hex_show(name)\
1849 lpfc_param_init(name, defval, minval, maxval)\
1850 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1852 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1853 static uint lpfc_##name = defval;\
1854 module_param(lpfc_##name, uint, S_IRUGO);\
1855 MODULE_PARM_DESC(lpfc_##name, desc);\
1856 lpfc_param_hex_show(name)\
1857 lpfc_param_init(name, defval, minval, maxval)\
1858 lpfc_param_set(name, defval, minval, maxval)\
1859 lpfc_param_store(name)\
1860 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1861 lpfc_##name##_show, lpfc_##name##_store)
1863 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1864 static uint lpfc_##name = defval;\
1865 module_param(lpfc_##name, uint, S_IRUGO);\
1866 MODULE_PARM_DESC(lpfc_##name, desc);\
1867 lpfc_vport_param_init(name, defval, minval, maxval)
1869 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1870 static uint lpfc_##name = defval;\
1871 module_param(lpfc_##name, uint, S_IRUGO);\
1872 MODULE_PARM_DESC(lpfc_##name, desc);\
1873 lpfc_vport_param_show(name)\
1874 lpfc_vport_param_init(name, defval, minval, maxval)\
1875 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1877 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1878 static uint lpfc_##name = defval;\
1879 module_param(lpfc_##name, uint, S_IRUGO);\
1880 MODULE_PARM_DESC(lpfc_##name, desc);\
1881 lpfc_vport_param_show(name)\
1882 lpfc_vport_param_init(name, defval, minval, maxval)\
1883 lpfc_vport_param_set(name, defval, minval, maxval)\
1884 lpfc_vport_param_store(name)\
1885 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1886 lpfc_##name##_show, lpfc_##name##_store)
1888 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1889 static uint lpfc_##name = defval;\
1890 module_param(lpfc_##name, uint, S_IRUGO);\
1891 MODULE_PARM_DESC(lpfc_##name, desc);\
1892 lpfc_vport_param_hex_show(name)\
1893 lpfc_vport_param_init(name, defval, minval, maxval)\
1894 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1896 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1897 static uint lpfc_##name = defval;\
1898 module_param(lpfc_##name, uint, S_IRUGO);\
1899 MODULE_PARM_DESC(lpfc_##name, desc);\
1900 lpfc_vport_param_hex_show(name)\
1901 lpfc_vport_param_init(name, defval, minval, maxval)\
1902 lpfc_vport_param_set(name, defval, minval, maxval)\
1903 lpfc_vport_param_store(name)\
1904 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1905 lpfc_##name##_show, lpfc_##name##_store)
1907 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1908 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1909 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1910 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1911 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1912 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1913 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1914 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1915 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1916 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1917 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1918 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1919 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1920 lpfc_link_state_store);
1921 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1922 lpfc_option_rom_version_show, NULL);
1923 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1924 lpfc_num_discovered_ports_show, NULL);
1925 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1926 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1927 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1928 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1929 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1930 lpfc_board_mode_show, lpfc_board_mode_store);
1931 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1932 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1933 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1934 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1935 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1936 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1937 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1938 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1939 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1940 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1941 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1942 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1943 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1944 lpfc_sriov_hw_max_virtfn_show, NULL);
1946 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1949 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1950 * @dev: class device that is converted into a Scsi_host.
1951 * @attr: device attribute, not used.
1952 * @buf: containing the string lpfc_soft_wwn_key.
1953 * @count: must be size of lpfc_soft_wwn_key.
1956 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1957 * length of buf indicates success
1960 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1961 const char *buf, size_t count)
1963 struct Scsi_Host *shost = class_to_shost(dev);
1964 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1965 struct lpfc_hba *phba = vport->phba;
1966 unsigned int cnt = count;
1969 * We're doing a simple sanity check for soft_wwpn setting.
1970 * We require that the user write a specific key to enable
1971 * the soft_wwpn attribute to be settable. Once the attribute
1972 * is written, the enable key resets. If further updates are
1973 * desired, the key must be written again to re-enable the
1976 * The "key" is not secret - it is a hardcoded string shown
1977 * here. The intent is to protect against the random user or
1978 * application that is just writing attributes.
1981 /* count may include a LF at end of string */
1982 if (buf[cnt-1] == '\n')
1985 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1986 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1989 phba->soft_wwn_enable = 1;
1992 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1993 lpfc_soft_wwn_enable_store);
1996 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1997 * @dev: class device that is converted into a Scsi_host.
1998 * @attr: device attribute, not used.
1999 * @buf: on return contains the wwpn in hexadecimal.
2001 * Returns: size of formatted string.
2004 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2007 struct Scsi_Host *shost = class_to_shost(dev);
2008 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2009 struct lpfc_hba *phba = vport->phba;
2011 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2012 (unsigned long long)phba->cfg_soft_wwpn);
2016 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2017 * @dev class device that is converted into a Scsi_host.
2018 * @attr: device attribute, not used.
2019 * @buf: contains the wwpn in hexadecimal.
2020 * @count: number of wwpn bytes in buf
2023 * -EACCES hba reset not enabled, adapter over temp
2024 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2025 * -EIO error taking adapter offline or online
2026 * value of count on success
2029 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2030 const char *buf, size_t count)
2032 struct Scsi_Host *shost = class_to_shost(dev);
2033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2034 struct lpfc_hba *phba = vport->phba;
2035 struct completion online_compl;
2036 int stat1=0, stat2=0;
2037 unsigned int i, j, cnt=count;
2041 if (!phba->cfg_enable_hba_reset)
2043 spin_lock_irq(&phba->hbalock);
2044 if (phba->over_temp_state == HBA_OVER_TEMP) {
2045 spin_unlock_irq(&phba->hbalock);
2048 spin_unlock_irq(&phba->hbalock);
2049 /* count may include a LF at end of string */
2050 if (buf[cnt-1] == '\n')
2053 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2054 ((cnt == 17) && (*buf++ != 'x')) ||
2055 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2058 phba->soft_wwn_enable = 0;
2060 memset(wwpn, 0, sizeof(wwpn));
2062 /* Validate and store the new name */
2063 for (i=0, j=0; i < 16; i++) {
2066 value = hex_to_bin(*buf++);
2068 j = (j << 4) | value;
2072 wwpn[i/2] = j & 0xff;
2076 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2077 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2078 if (phba->cfg_soft_wwnn)
2079 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2081 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2082 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2084 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2086 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2087 "0463 lpfc_soft_wwpn attribute set failed to "
2088 "reinit adapter - %d\n", stat1);
2089 init_completion(&online_compl);
2090 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2095 wait_for_completion(&online_compl);
2097 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2098 "0464 lpfc_soft_wwpn attribute set failed to "
2099 "reinit adapter - %d\n", stat2);
2100 return (stat1 || stat2) ? -EIO : count;
2102 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2103 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2106 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2107 * @dev: class device that is converted into a Scsi_host.
2108 * @attr: device attribute, not used.
2109 * @buf: on return contains the wwnn in hexadecimal.
2111 * Returns: size of formatted string.
2114 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2117 struct Scsi_Host *shost = class_to_shost(dev);
2118 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2119 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2120 (unsigned long long)phba->cfg_soft_wwnn);
2124 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2125 * @cdev: class device that is converted into a Scsi_host.
2126 * @buf: contains the ww node name in hexadecimal.
2127 * @count: number of wwnn bytes in buf.
2130 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2131 * value of count on success
2134 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2135 const char *buf, size_t count)
2137 struct Scsi_Host *shost = class_to_shost(dev);
2138 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2139 unsigned int i, j, cnt=count;
2142 /* count may include a LF at end of string */
2143 if (buf[cnt-1] == '\n')
2146 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2147 ((cnt == 17) && (*buf++ != 'x')) ||
2148 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2152 * Allow wwnn to be set many times, as long as the enable is set.
2153 * However, once the wwpn is set, everything locks.
2156 memset(wwnn, 0, sizeof(wwnn));
2158 /* Validate and store the new name */
2159 for (i=0, j=0; i < 16; i++) {
2162 value = hex_to_bin(*buf++);
2164 j = (j << 4) | value;
2168 wwnn[i/2] = j & 0xff;
2172 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2174 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2175 "lpfc%d: soft_wwnn set. Value will take effect upon "
2176 "setting of the soft_wwpn\n", phba->brd_no);
2180 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2181 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2184 static int lpfc_poll = 0;
2185 module_param(lpfc_poll, int, S_IRUGO);
2186 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2188 " 1 - poll with interrupts enabled"
2189 " 3 - poll and disable FCP ring interrupts");
2191 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2192 lpfc_poll_show, lpfc_poll_store);
2194 int lpfc_sli_mode = 0;
2195 module_param(lpfc_sli_mode, int, S_IRUGO);
2196 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2197 " 0 - auto (SLI-3 if supported),"
2198 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2199 " 3 - select SLI-3");
2201 int lpfc_enable_npiv = 1;
2202 module_param(lpfc_enable_npiv, int, S_IRUGO);
2203 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2204 lpfc_param_show(enable_npiv);
2205 lpfc_param_init(enable_npiv, 1, 0, 1);
2206 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2208 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2209 "FCF Fast failover=1 Priority failover=2");
2211 int lpfc_enable_rrq;
2212 module_param(lpfc_enable_rrq, int, S_IRUGO);
2213 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2214 lpfc_param_show(enable_rrq);
2215 lpfc_param_init(enable_rrq, 0, 0, 1);
2216 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2219 # lpfc_suppress_link_up: Bring link up at initialization
2220 # 0x0 = bring link up (issue MBX_INIT_LINK)
2221 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2222 # 0x2 = never bring up link
2223 # Default value is 0.
2225 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2226 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2227 "Suppress Link Up at initialization");
2229 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2237 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2239 struct Scsi_Host *shost = class_to_shost(dev);
2240 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2242 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2245 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2246 lpfc_iocb_hw_show, NULL);
2248 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2250 struct Scsi_Host *shost = class_to_shost(dev);
2251 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2253 return snprintf(buf, PAGE_SIZE, "%d\n",
2254 phba->sli.ring[LPFC_ELS_RING].txq_max);
2257 static DEVICE_ATTR(txq_hw, S_IRUGO,
2258 lpfc_txq_hw_show, NULL);
2260 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2263 struct Scsi_Host *shost = class_to_shost(dev);
2264 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2266 return snprintf(buf, PAGE_SIZE, "%d\n",
2267 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2270 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2271 lpfc_txcmplq_hw_show, NULL);
2273 int lpfc_iocb_cnt = 2;
2274 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2275 MODULE_PARM_DESC(lpfc_iocb_cnt,
2276 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2277 lpfc_param_show(iocb_cnt);
2278 lpfc_param_init(iocb_cnt, 2, 1, 5);
2279 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2280 lpfc_iocb_cnt_show, NULL);
2283 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2284 # until the timer expires. Value range is [0,255]. Default value is 30.
2286 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2287 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2288 module_param(lpfc_nodev_tmo, int, 0);
2289 MODULE_PARM_DESC(lpfc_nodev_tmo,
2290 "Seconds driver will hold I/O waiting "
2291 "for a device to come back");
2294 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2295 * @dev: class converted to a Scsi_host structure.
2296 * @attr: device attribute, not used.
2297 * @buf: on return contains the dev loss timeout in decimal.
2299 * Returns: size of formatted string.
2302 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2305 struct Scsi_Host *shost = class_to_shost(dev);
2306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2308 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2312 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2313 * @vport: lpfc vport structure pointer.
2314 * @val: contains the nodev timeout value.
2317 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2318 * a kernel error message is printed and zero is returned.
2319 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2320 * Otherwise nodev tmo is set to the default value.
2323 * zero if already set or if val is in range
2324 * -EINVAL val out of range
2327 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2329 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2330 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2331 if (val != LPFC_DEF_DEVLOSS_TMO)
2332 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2333 "0407 Ignoring nodev_tmo module "
2334 "parameter because devloss_tmo is "
2339 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2340 vport->cfg_nodev_tmo = val;
2341 vport->cfg_devloss_tmo = val;
2344 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2345 "0400 lpfc_nodev_tmo attribute cannot be set to"
2346 " %d, allowed range is [%d, %d]\n",
2347 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2348 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2353 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2354 * @vport: lpfc vport structure pointer.
2357 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2360 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2362 struct Scsi_Host *shost;
2363 struct lpfc_nodelist *ndlp;
2365 shost = lpfc_shost_from_vport(vport);
2366 spin_lock_irq(shost->host_lock);
2367 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2368 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2369 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2370 spin_unlock_irq(shost->host_lock);
2374 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2375 * @vport: lpfc vport structure pointer.
2376 * @val: contains the tmo value.
2379 * If the devloss tmo is already set or the vport dev loss tmo has changed
2380 * then a kernel error message is printed and zero is returned.
2381 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2382 * Otherwise nodev tmo is set to the default value.
2385 * zero if already set or if val is in range
2386 * -EINVAL val out of range
2389 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2391 if (vport->dev_loss_tmo_changed ||
2392 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2393 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2394 "0401 Ignoring change to nodev_tmo "
2395 "because devloss_tmo is set.\n");
2398 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2399 vport->cfg_nodev_tmo = val;
2400 vport->cfg_devloss_tmo = val;
2402 * For compat: set the fc_host dev loss so new rports
2403 * will get the value.
2405 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2406 lpfc_update_rport_devloss_tmo(vport);
2409 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2410 "0403 lpfc_nodev_tmo attribute cannot be set to"
2411 "%d, allowed range is [%d, %d]\n",
2412 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2416 lpfc_vport_param_store(nodev_tmo)
2418 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2419 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2422 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2423 # disappear until the timer expires. Value range is [0,255]. Default
2426 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2427 MODULE_PARM_DESC(lpfc_devloss_tmo,
2428 "Seconds driver will hold I/O waiting "
2429 "for a device to come back");
2430 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2431 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2432 lpfc_vport_param_show(devloss_tmo)
2435 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2436 * @vport: lpfc vport structure pointer.
2437 * @val: contains the tmo value.
2440 * If val is in a valid range then set the vport nodev tmo,
2441 * devloss tmo, also set the vport dev loss tmo changed flag.
2442 * Else a kernel error message is printed.
2445 * zero if val is in range
2446 * -EINVAL val out of range
2449 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2451 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2452 vport->cfg_nodev_tmo = val;
2453 vport->cfg_devloss_tmo = val;
2454 vport->dev_loss_tmo_changed = 1;
2455 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2456 lpfc_update_rport_devloss_tmo(vport);
2460 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2461 "0404 lpfc_devloss_tmo attribute cannot be set to"
2462 " %d, allowed range is [%d, %d]\n",
2463 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2467 lpfc_vport_param_store(devloss_tmo)
2468 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2469 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2472 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2473 # deluged with LOTS of information.
2474 # You can set a bit mask to record specific types of verbose messages:
2475 # See lpfc_logmsh.h for definitions.
2477 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2478 "Verbose logging bit-mask");
2481 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2482 # objects that have been registered with the nameserver after login.
2484 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2485 "Deregister nameserver objects before LOGO");
2488 # lun_queue_depth: This parameter is used to limit the number of outstanding
2489 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2491 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2492 "Max number of FCP commands we can queue to a specific LUN");
2495 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2496 # commands per target port. Value range is [10,65535]. Default value is 65535.
2498 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2499 "Max number of FCP commands we can queue to a specific target port");
2502 # hba_queue_depth: This parameter is used to limit the number of outstanding
2503 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2504 # value is greater than the maximum number of exchanges supported by the HBA,
2505 # then maximum number of exchanges supported by the HBA is used to determine
2506 # the hba_queue_depth.
2508 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2509 "Max number of FCP commands we can queue to a lpfc HBA");
2512 # peer_port_login: This parameter allows/prevents logins
2513 # between peer ports hosted on the same physical port.
2514 # When this parameter is set 0 peer ports of same physical port
2515 # are not allowed to login to each other.
2516 # When this parameter is set 1 peer ports of same physical port
2517 # are allowed to login to each other.
2518 # Default value of this parameter is 0.
2520 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2521 "Allow peer ports on the same physical port to login to each "
2525 # restrict_login: This parameter allows/prevents logins
2526 # between Virtual Ports and remote initiators.
2527 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2528 # other initiators and will attempt to PLOGI all remote ports.
2529 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2530 # remote ports and will not attempt to PLOGI to other initiators.
2531 # This parameter does not restrict to the physical port.
2532 # This parameter does not restrict logins to Fabric resident remote ports.
2533 # Default value of this parameter is 1.
2535 static int lpfc_restrict_login = 1;
2536 module_param(lpfc_restrict_login, int, S_IRUGO);
2537 MODULE_PARM_DESC(lpfc_restrict_login,
2538 "Restrict virtual ports login to remote initiators.");
2539 lpfc_vport_param_show(restrict_login);
2542 * lpfc_restrict_login_init - Set the vport restrict login flag
2543 * @vport: lpfc vport structure pointer.
2544 * @val: contains the restrict login value.
2547 * If val is not in a valid range then log a kernel error message and set
2548 * the vport restrict login to one.
2549 * If the port type is physical clear the restrict login flag and return.
2550 * Else set the restrict login flag to val.
2553 * zero if val is in range
2554 * -EINVAL val out of range
2557 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2559 if (val < 0 || val > 1) {
2560 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2561 "0422 lpfc_restrict_login attribute cannot "
2562 "be set to %d, allowed range is [0, 1]\n",
2564 vport->cfg_restrict_login = 1;
2567 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2568 vport->cfg_restrict_login = 0;
2571 vport->cfg_restrict_login = val;
2576 * lpfc_restrict_login_set - Set the vport restrict login flag
2577 * @vport: lpfc vport structure pointer.
2578 * @val: contains the restrict login value.
2581 * If val is not in a valid range then log a kernel error message and set
2582 * the vport restrict login to one.
2583 * If the port type is physical and the val is not zero log a kernel
2584 * error message, clear the restrict login flag and return zero.
2585 * Else set the restrict login flag to val.
2588 * zero if val is in range
2589 * -EINVAL val out of range
2592 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2594 if (val < 0 || val > 1) {
2595 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2596 "0425 lpfc_restrict_login attribute cannot "
2597 "be set to %d, allowed range is [0, 1]\n",
2599 vport->cfg_restrict_login = 1;
2602 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2603 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2604 "0468 lpfc_restrict_login must be 0 for "
2605 "Physical ports.\n");
2606 vport->cfg_restrict_login = 0;
2609 vport->cfg_restrict_login = val;
2612 lpfc_vport_param_store(restrict_login);
2613 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2614 lpfc_restrict_login_show, lpfc_restrict_login_store);
2617 # Some disk devices have a "select ID" or "select Target" capability.
2618 # From a protocol standpoint "select ID" usually means select the
2619 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2620 # annex" which contains a table that maps a "select ID" (a number
2621 # between 0 and 7F) to an ALPA. By default, for compatibility with
2622 # older drivers, the lpfc driver scans this table from low ALPA to high
2625 # Turning on the scan-down variable (on = 1, off = 0) will
2626 # cause the lpfc driver to use an inverted table, effectively
2627 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2629 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2630 # and will not work across a fabric. Also this parameter will take
2631 # effect only in the case when ALPA map is not available.)
2633 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2634 "Start scanning for devices from highest ALPA to lowest");
2637 # lpfc_topology: link topology for init link
2638 # 0x0 = attempt loop mode then point-to-point
2639 # 0x01 = internal loopback mode
2640 # 0x02 = attempt point-to-point mode only
2641 # 0x04 = attempt loop mode only
2642 # 0x06 = attempt point-to-point mode then loop
2643 # Set point-to-point mode if you want to run as an N_Port.
2644 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2645 # Default value is 0.
2649 * lpfc_topology_set - Set the adapters topology field
2650 * @phba: lpfc_hba pointer.
2651 * @val: topology value.
2654 * If val is in a valid range then set the adapter's topology field and
2655 * issue a lip; if the lip fails reset the topology to the old value.
2657 * If the value is not in range log a kernel error message and return an error.
2660 * zero if val is in range and lip okay
2661 * non-zero return value from lpfc_issue_lip()
2662 * -EINVAL val out of range
2665 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2666 const char *buf, size_t count)
2668 struct Scsi_Host *shost = class_to_shost(dev);
2669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2670 struct lpfc_hba *phba = vport->phba;
2673 const char *val_buf = buf;
2677 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2679 val_buf = &buf[strlen("nolip ")];
2682 if (!isdigit(val_buf[0]))
2684 if (sscanf(val_buf, "%i", &val) != 1)
2687 if (val >= 0 && val <= 6) {
2688 prev_val = phba->cfg_topology;
2689 phba->cfg_topology = val;
2693 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2694 "3054 lpfc_topology changed from %d to %d\n",
2696 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2698 phba->cfg_topology = prev_val;
2703 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2704 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2705 "allowed range is [0, 6]\n",
2709 static int lpfc_topology = 0;
2710 module_param(lpfc_topology, int, S_IRUGO);
2711 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2712 lpfc_param_show(topology)
2713 lpfc_param_init(topology, 0, 0, 6)
2714 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2715 lpfc_topology_show, lpfc_topology_store);
2718 * lpfc_static_vport_show: Read callback function for
2719 * lpfc_static_vport sysfs file.
2720 * @dev: Pointer to class device object.
2721 * @attr: device attribute structure.
2722 * @buf: Data buffer.
2724 * This function is the read call back function for
2725 * lpfc_static_vport sysfs file. The lpfc_static_vport
2726 * sysfs file report the mageability of the vport.
2729 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2732 struct Scsi_Host *shost = class_to_shost(dev);
2733 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2734 if (vport->vport_flag & STATIC_VPORT)
2735 sprintf(buf, "1\n");
2737 sprintf(buf, "0\n");
2743 * Sysfs attribute to control the statistical data collection.
2745 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2746 lpfc_static_vport_show, NULL);
2749 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2750 * @dev: Pointer to class device.
2751 * @buf: Data buffer.
2752 * @count: Size of the data buffer.
2754 * This function get called when an user write to the lpfc_stat_data_ctrl
2755 * sysfs file. This function parse the command written to the sysfs file
2756 * and take appropriate action. These commands are used for controlling
2757 * driver statistical data collection.
2758 * Following are the command this function handles.
2760 * setbucket <bucket_type> <base> <step>
2761 * = Set the latency buckets.
2762 * destroybucket = destroy all the buckets.
2763 * start = start data collection
2764 * stop = stop data collection
2765 * reset = reset the collected data
2768 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2769 const char *buf, size_t count)
2771 struct Scsi_Host *shost = class_to_shost(dev);
2772 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2773 struct lpfc_hba *phba = vport->phba;
2774 #define LPFC_MAX_DATA_CTRL_LEN 1024
2775 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2777 char *str_ptr, *token;
2778 struct lpfc_vport **vports;
2779 struct Scsi_Host *v_shost;
2780 char *bucket_type_str, *base_str, *step_str;
2781 unsigned long base, step, bucket_type;
2783 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2784 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2787 strcpy(bucket_data, buf);
2788 str_ptr = &bucket_data[0];
2789 /* Ignore this token - this is command token */
2790 token = strsep(&str_ptr, "\t ");
2794 bucket_type_str = strsep(&str_ptr, "\t ");
2795 if (!bucket_type_str)
2798 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2799 bucket_type = LPFC_LINEAR_BUCKET;
2800 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2801 bucket_type = LPFC_POWER2_BUCKET;
2805 base_str = strsep(&str_ptr, "\t ");
2808 base = simple_strtoul(base_str, NULL, 0);
2810 step_str = strsep(&str_ptr, "\t ");
2813 step = simple_strtoul(step_str, NULL, 0);
2817 /* Block the data collection for every vport */
2818 vports = lpfc_create_vport_work_array(phba);
2822 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2823 v_shost = lpfc_shost_from_vport(vports[i]);
2824 spin_lock_irq(v_shost->host_lock);
2825 /* Block and reset data collection */
2826 vports[i]->stat_data_blocked = 1;
2827 if (vports[i]->stat_data_enabled)
2828 lpfc_vport_reset_stat_data(vports[i]);
2829 spin_unlock_irq(v_shost->host_lock);
2832 /* Set the bucket attributes */
2833 phba->bucket_type = bucket_type;
2834 phba->bucket_base = base;
2835 phba->bucket_step = step;
2837 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2838 v_shost = lpfc_shost_from_vport(vports[i]);
2840 /* Unblock data collection */
2841 spin_lock_irq(v_shost->host_lock);
2842 vports[i]->stat_data_blocked = 0;
2843 spin_unlock_irq(v_shost->host_lock);
2845 lpfc_destroy_vport_work_array(phba, vports);
2849 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2850 vports = lpfc_create_vport_work_array(phba);
2854 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2855 v_shost = lpfc_shost_from_vport(vports[i]);
2856 spin_lock_irq(shost->host_lock);
2857 vports[i]->stat_data_blocked = 1;
2858 lpfc_free_bucket(vport);
2859 vport->stat_data_enabled = 0;
2860 vports[i]->stat_data_blocked = 0;
2861 spin_unlock_irq(shost->host_lock);
2863 lpfc_destroy_vport_work_array(phba, vports);
2864 phba->bucket_type = LPFC_NO_BUCKET;
2865 phba->bucket_base = 0;
2866 phba->bucket_step = 0;
2870 if (!strncmp(buf, "start", strlen("start"))) {
2871 /* If no buckets configured return error */
2872 if (phba->bucket_type == LPFC_NO_BUCKET)
2874 spin_lock_irq(shost->host_lock);
2875 if (vport->stat_data_enabled) {
2876 spin_unlock_irq(shost->host_lock);
2879 lpfc_alloc_bucket(vport);
2880 vport->stat_data_enabled = 1;
2881 spin_unlock_irq(shost->host_lock);
2885 if (!strncmp(buf, "stop", strlen("stop"))) {
2886 spin_lock_irq(shost->host_lock);
2887 if (vport->stat_data_enabled == 0) {
2888 spin_unlock_irq(shost->host_lock);
2891 lpfc_free_bucket(vport);
2892 vport->stat_data_enabled = 0;
2893 spin_unlock_irq(shost->host_lock);
2897 if (!strncmp(buf, "reset", strlen("reset"))) {
2898 if ((phba->bucket_type == LPFC_NO_BUCKET)
2899 || !vport->stat_data_enabled)
2901 spin_lock_irq(shost->host_lock);
2902 vport->stat_data_blocked = 1;
2903 lpfc_vport_reset_stat_data(vport);
2904 vport->stat_data_blocked = 0;
2905 spin_unlock_irq(shost->host_lock);
2913 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2914 * @dev: Pointer to class device object.
2915 * @buf: Data buffer.
2917 * This function is the read call back function for
2918 * lpfc_stat_data_ctrl sysfs file. This function report the
2919 * current statistical data collection state.
2922 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2925 struct Scsi_Host *shost = class_to_shost(dev);
2926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2927 struct lpfc_hba *phba = vport->phba;
2931 unsigned long bucket_value;
2933 switch (phba->bucket_type) {
2934 case LPFC_LINEAR_BUCKET:
2935 bucket_type = "linear";
2937 case LPFC_POWER2_BUCKET:
2938 bucket_type = "power2";
2941 bucket_type = "No Bucket";
2945 sprintf(&buf[index], "Statistical Data enabled :%d, "
2946 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2947 " Bucket step :%d\nLatency Ranges :",
2948 vport->stat_data_enabled, vport->stat_data_blocked,
2949 bucket_type, phba->bucket_base, phba->bucket_step);
2950 index = strlen(buf);
2951 if (phba->bucket_type != LPFC_NO_BUCKET) {
2952 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2953 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2954 bucket_value = phba->bucket_base +
2955 phba->bucket_step * i;
2957 bucket_value = phba->bucket_base +
2958 (1 << i) * phba->bucket_step;
2960 if (index + 10 > PAGE_SIZE)
2962 sprintf(&buf[index], "%08ld ", bucket_value);
2963 index = strlen(buf);
2966 sprintf(&buf[index], "\n");
2971 * Sysfs attribute to control the statistical data collection.
2973 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2974 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2977 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2981 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2984 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2985 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2986 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2990 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2992 * @kobj: Pointer to the kernel object
2993 * @bin_attr: Attribute object
2994 * @buff: Buffer pointer
2996 * @count: Buffer size
2998 * This function is the read call back function for lpfc_drvr_stat_data
2999 * sysfs file. This function export the statistical data to user
3003 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3004 struct bin_attribute *bin_attr,
3005 char *buf, loff_t off, size_t count)
3007 struct device *dev = container_of(kobj, struct device,
3009 struct Scsi_Host *shost = class_to_shost(dev);
3010 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3011 struct lpfc_hba *phba = vport->phba;
3012 int i = 0, index = 0;
3013 unsigned long nport_index;
3014 struct lpfc_nodelist *ndlp = NULL;
3015 nport_index = (unsigned long)off /
3016 MAX_STAT_DATA_SIZE_PER_TARGET;
3018 if (!vport->stat_data_enabled || vport->stat_data_blocked
3019 || (phba->bucket_type == LPFC_NO_BUCKET))
3022 spin_lock_irq(shost->host_lock);
3023 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3024 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3027 if (nport_index > 0) {
3032 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3036 if (!ndlp->lat_data)
3040 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3041 ndlp->nlp_portname.u.wwn[0],
3042 ndlp->nlp_portname.u.wwn[1],
3043 ndlp->nlp_portname.u.wwn[2],
3044 ndlp->nlp_portname.u.wwn[3],
3045 ndlp->nlp_portname.u.wwn[4],
3046 ndlp->nlp_portname.u.wwn[5],
3047 ndlp->nlp_portname.u.wwn[6],
3048 ndlp->nlp_portname.u.wwn[7]);
3050 index = strlen(buf);
3052 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3053 sprintf(&buf[index], "%010u,",
3054 ndlp->lat_data[i].cmd_count);
3055 index = strlen(buf);
3057 sprintf(&buf[index], "\n");
3058 index = strlen(buf);
3060 spin_unlock_irq(shost->host_lock);
3064 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3066 .name = "lpfc_drvr_stat_data",
3069 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3070 .read = sysfs_drvr_stat_data_read,
3075 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3077 # Value range is [0,16]. Default value is 0.
3080 * lpfc_link_speed_set - Set the adapters link speed
3081 * @phba: lpfc_hba pointer.
3082 * @val: link speed value.
3085 * If val is in a valid range then set the adapter's link speed field and
3086 * issue a lip; if the lip fails reset the link speed to the old value.
3089 * If the value is not in range log a kernel error message and return an error.
3092 * zero if val is in range and lip okay.
3093 * non-zero return value from lpfc_issue_lip()
3094 * -EINVAL val out of range
3097 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3098 const char *buf, size_t count)
3100 struct Scsi_Host *shost = class_to_shost(dev);
3101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3102 struct lpfc_hba *phba = vport->phba;
3103 int val = LPFC_USER_LINK_SPEED_AUTO;
3105 const char *val_buf = buf;
3109 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3111 val_buf = &buf[strlen("nolip ")];
3114 if (!isdigit(val_buf[0]))
3116 if (sscanf(val_buf, "%i", &val) != 1)
3119 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3120 "3055 lpfc_link_speed changed from %d to %d %s\n",
3121 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3123 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3124 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3125 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3126 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3127 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3128 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3130 "2879 lpfc_link_speed attribute cannot be set "
3131 "to %d. Speed is not supported by this port.\n",
3135 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3136 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3137 prev_val = phba->cfg_link_speed;
3138 phba->cfg_link_speed = val;
3142 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3144 phba->cfg_link_speed = prev_val;
3149 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3150 "0469 lpfc_link_speed attribute cannot be set to %d, "
3151 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3155 static int lpfc_link_speed = 0;
3156 module_param(lpfc_link_speed, int, S_IRUGO);
3157 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3158 lpfc_param_show(link_speed)
3161 * lpfc_link_speed_init - Set the adapters link speed
3162 * @phba: lpfc_hba pointer.
3163 * @val: link speed value.
3166 * If val is in a valid range then set the adapter's link speed field.
3169 * If the value is not in range log a kernel error message, clear the link
3170 * speed and return an error.
3173 * zero if val saved.
3174 * -EINVAL val out of range
3177 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3179 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3180 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3181 phba->cfg_link_speed = val;
3184 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3185 "0405 lpfc_link_speed attribute cannot "
3186 "be set to %d, allowed values are "
3187 "["LPFC_LINK_SPEED_STRING"]\n", val);
3188 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3192 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3193 lpfc_link_speed_show, lpfc_link_speed_store);
3196 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3197 # 0 = aer disabled or not supported
3198 # 1 = aer supported and enabled (default)
3199 # Value range is [0,1]. Default value is 1.
3203 * lpfc_aer_support_store - Set the adapter for aer support
3205 * @dev: class device that is converted into a Scsi_host.
3206 * @attr: device attribute, not used.
3207 * @buf: containing enable or disable aer flag.
3208 * @count: unused variable.
3211 * If the val is 1 and currently the device's AER capability was not
3212 * enabled, invoke the kernel's enable AER helper routine, trying to
3213 * enable the device's AER capability. If the helper routine enabling
3214 * AER returns success, update the device's cfg_aer_support flag to
3215 * indicate AER is supported by the device; otherwise, if the device
3216 * AER capability is already enabled to support AER, then do nothing.
3218 * If the val is 0 and currently the device's AER support was enabled,
3219 * invoke the kernel's disable AER helper routine. After that, update
3220 * the device's cfg_aer_support flag to indicate AER is not supported
3221 * by the device; otherwise, if the device AER capability is already
3222 * disabled from supporting AER, then do nothing.
3225 * length of the buf on success if val is in range the intended mode
3227 * -EINVAL if val out of range or intended mode is not supported.
3230 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3231 const char *buf, size_t count)
3233 struct Scsi_Host *shost = class_to_shost(dev);
3234 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3235 struct lpfc_hba *phba = vport->phba;
3236 int val = 0, rc = -EINVAL;
3238 if (!isdigit(buf[0]))
3240 if (sscanf(buf, "%i", &val) != 1)
3245 if (phba->hba_flag & HBA_AER_ENABLED) {
3246 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3248 spin_lock_irq(&phba->hbalock);
3249 phba->hba_flag &= ~HBA_AER_ENABLED;
3250 spin_unlock_irq(&phba->hbalock);
3251 phba->cfg_aer_support = 0;
3256 phba->cfg_aer_support = 0;
3261 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3262 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3264 spin_lock_irq(&phba->hbalock);
3265 phba->hba_flag |= HBA_AER_ENABLED;
3266 spin_unlock_irq(&phba->hbalock);
3267 phba->cfg_aer_support = 1;
3272 phba->cfg_aer_support = 1;
3283 static int lpfc_aer_support = 1;
3284 module_param(lpfc_aer_support, int, S_IRUGO);
3285 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3286 lpfc_param_show(aer_support)
3289 * lpfc_aer_support_init - Set the initial adapters aer support flag
3290 * @phba: lpfc_hba pointer.
3291 * @val: enable aer or disable aer flag.
3294 * If val is in a valid range [0,1], then set the adapter's initial
3295 * cfg_aer_support field. It will be up to the driver's probe_one
3296 * routine to determine whether the device's AER support can be set
3300 * If the value is not in range log a kernel error message, and
3301 * choose the default value of setting AER support and return.
3304 * zero if val saved.
3305 * -EINVAL val out of range
3308 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3310 if (val == 0 || val == 1) {
3311 phba->cfg_aer_support = val;
3314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3315 "2712 lpfc_aer_support attribute value %d out "
3316 "of range, allowed values are 0|1, setting it "
3317 "to default value of 1\n", val);
3318 /* By default, try to enable AER on a device */
3319 phba->cfg_aer_support = 1;
3323 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3324 lpfc_aer_support_show, lpfc_aer_support_store);
3327 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3328 * @dev: class device that is converted into a Scsi_host.
3329 * @attr: device attribute, not used.
3330 * @buf: containing flag 1 for aer cleanup state.
3331 * @count: unused variable.
3334 * If the @buf contains 1 and the device currently has the AER support
3335 * enabled, then invokes the kernel AER helper routine
3336 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3337 * error status register.
3342 * -EINVAL if the buf does not contain the 1 or the device is not currently
3343 * enabled with the AER support.
3346 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3347 const char *buf, size_t count)
3349 struct Scsi_Host *shost = class_to_shost(dev);
3350 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3351 struct lpfc_hba *phba = vport->phba;
3354 if (!isdigit(buf[0]))
3356 if (sscanf(buf, "%i", &val) != 1)
3361 if (phba->hba_flag & HBA_AER_ENABLED)
3362 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3370 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3371 lpfc_aer_cleanup_state);
3374 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3376 * @dev: class device that is converted into a Scsi_host.
3377 * @attr: device attribute, not used.
3378 * @buf: containing the string the number of vfs to be enabled.
3379 * @count: unused variable.
3382 * When this api is called either through user sysfs, the driver shall
3383 * try to enable or disable SR-IOV virtual functions according to the
3386 * If zero virtual function has been enabled to the physical function,
3387 * the driver shall invoke the pci enable virtual function api trying
3388 * to enable the virtual functions. If the nr_vfn provided is greater
3389 * than the maximum supported, the maximum virtual function number will
3390 * be used for invoking the api; otherwise, the nr_vfn provided shall
3391 * be used for invoking the api. If the api call returned success, the
3392 * actual number of virtual functions enabled will be set to the driver
3393 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3394 * cfg_sriov_nr_virtfn remains zero.
3396 * If none-zero virtual functions have already been enabled to the
3397 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3398 * -EINVAL will be returned and the driver does nothing;
3400 * If the nr_vfn provided is zero and none-zero virtual functions have
3401 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3402 * disabling virtual function api shall be invoded to disable all the
3403 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3404 * zero. Otherwise, if zero virtual function has been enabled, do
3408 * length of the buf on success if val is in range the intended mode
3410 * -EINVAL if val out of range or intended mode is not supported.
3413 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3414 const char *buf, size_t count)
3416 struct Scsi_Host *shost = class_to_shost(dev);
3417 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3418 struct lpfc_hba *phba = vport->phba;
3419 struct pci_dev *pdev = phba->pcidev;
3420 int val = 0, rc = -EINVAL;
3422 /* Sanity check on user data */
3423 if (!isdigit(buf[0]))
3425 if (sscanf(buf, "%i", &val) != 1)
3430 /* Request disabling virtual functions */
3432 if (phba->cfg_sriov_nr_virtfn > 0) {
3433 pci_disable_sriov(pdev);
3434 phba->cfg_sriov_nr_virtfn = 0;
3439 /* Request enabling virtual functions */
3440 if (phba->cfg_sriov_nr_virtfn > 0) {
3441 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3442 "3018 There are %d virtual functions "
3443 "enabled on physical function.\n",
3444 phba->cfg_sriov_nr_virtfn);
3448 if (val <= LPFC_MAX_VFN_PER_PFN)
3449 phba->cfg_sriov_nr_virtfn = val;
3451 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3452 "3019 Enabling %d virtual functions is not "
3457 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3459 phba->cfg_sriov_nr_virtfn = 0;
3467 static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3468 module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3469 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3470 lpfc_param_show(sriov_nr_virtfn)
3473 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3474 * @phba: lpfc_hba pointer.
3475 * @val: link speed value.
3478 * If val is in a valid range [0,255], then set the adapter's initial
3479 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3480 * number shall be used instead. It will be up to the driver's probe_one
3481 * routine to determine whether the device's SR-IOV is supported or not.
3484 * zero if val saved.
3485 * -EINVAL val out of range
3488 lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3490 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3491 phba->cfg_sriov_nr_virtfn = val;
3495 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3496 "3017 Enabling %d virtual functions is not "
3500 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3501 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3504 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3505 # Value range is [2,3]. Default value is 3.
3507 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3508 "Select Fibre Channel class of service for FCP sequences");
3511 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3512 # is [0,1]. Default value is 0.
3514 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3515 "Use ADISC on rediscovery to authenticate FCP devices");
3518 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3519 # depth. Default value is 0. When the value of this parameter is zero the
3520 # SCSI command completion time is not used for controlling I/O queue depth. When
3521 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3522 # to limit the I/O completion time to the parameter value.
3523 # The value is set in milliseconds.
3525 static int lpfc_max_scsicmpl_time;
3526 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3527 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3528 "Use command completion time to control queue depth");
3529 lpfc_vport_param_show(max_scsicmpl_time);
3530 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3532 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3534 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3535 struct lpfc_nodelist *ndlp, *next_ndlp;
3537 if (val == vport->cfg_max_scsicmpl_time)
3539 if ((val < 0) || (val > 60000))
3541 vport->cfg_max_scsicmpl_time = val;
3543 spin_lock_irq(shost->host_lock);
3544 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3545 if (!NLP_CHK_NODE_ACT(ndlp))
3547 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3549 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3551 spin_unlock_irq(shost->host_lock);
3554 lpfc_vport_param_store(max_scsicmpl_time);
3555 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3556 lpfc_max_scsicmpl_time_show,
3557 lpfc_max_scsicmpl_time_store);
3560 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3561 # range is [0,1]. Default value is 0.
3563 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3566 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3567 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3568 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3569 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3570 # cr_delay is set to 0.
3572 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3573 "interrupt response is generated");
3575 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3576 "interrupt response is generated");
3579 # lpfc_multi_ring_support: Determines how many rings to spread available
3580 # cmd/rsp IOCB entries across.
3581 # Value range is [1,2]. Default value is 1.
3583 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3584 "SLI rings to spread IOCB entries across");
3587 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3588 # identifies what rctl value to configure the additional ring for.
3589 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3591 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3592 255, "Identifies RCTL for additional ring configuration");
3595 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3596 # identifies what type value to configure the additional ring for.
3597 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3599 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3600 255, "Identifies TYPE for additional ring configuration");
3603 # lpfc_fdmi_on: controls FDMI support.
3604 # 0 = no FDMI support
3605 # 1 = support FDMI without attribute of hostname
3606 # 2 = support FDMI with attribute of hostname
3607 # Value range [0,2]. Default value is 0.
3609 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3612 # Specifies the maximum number of ELS cmds we can have outstanding (for
3613 # discovery). Value range is [1,64]. Default value = 32.
3615 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3616 "during discovery");
3619 # lpfc_max_luns: maximum allowed LUN.
3620 # Value range is [0,65535]. Default value is 255.
3621 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3623 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3626 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3627 # Value range is [1,255], default value is 10.
3629 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3630 "Milliseconds driver will wait between polling FCP ring");
3633 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3634 # support this feature
3637 # 2 = MSI-X enabled (default)
3638 # Value range is [0,2]. Default value is 2.
3640 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3641 "MSI-X (2), if possible");
3644 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3646 # Value range is [636,651042]. Default value is 10000.
3648 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3649 "Set the maximum number of fast-path FCP interrupts per second");
3652 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3654 # Value range is [1,31]. Default value is 4.
3656 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3657 "Set the number of fast-path FCP work queues, if possible");
3660 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3662 # Value range is [1,7]. Default value is 1.
3664 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3665 "Set the number of fast-path FCP event queues, if possible");
3668 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3669 # 0 = HBA resets disabled
3670 # 1 = HBA resets enabled (default)
3671 # Value range is [0,1]. Default value is 1.
3673 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3676 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3677 # 0 = HBA Heartbeat disabled
3678 # 1 = HBA Heartbeat enabled (default)
3679 # Value range is [0,1]. Default value is 1.
3681 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3684 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3685 # 0 = BlockGuard disabled (default)
3686 # 1 = BlockGuard enabled
3687 # Value range is [0,1]. Default value is 0.
3689 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3693 # - Bit mask of host protection capabilities used to register with the
3695 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3696 # - Allows you to ultimately specify which profiles to use
3697 # - Default will result in registering capabilities for all profiles.
3700 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3701 SHOST_DIX_TYPE0_PROTECTION |
3702 SHOST_DIX_TYPE1_PROTECTION;
3704 module_param(lpfc_prot_mask, uint, S_IRUGO);
3705 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3708 # lpfc_prot_guard: i
3709 # - Bit mask of protection guard types to register with the SCSI mid-layer
3710 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3711 # - Allows you to ultimately specify which profiles to use
3712 # - Default will result in registering capabilities for all guard types
3715 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3716 module_param(lpfc_prot_guard, byte, S_IRUGO);
3717 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3720 * Delay initial NPort discovery when Clean Address bit is cleared in
3721 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3722 * This parameter can have value 0 or 1.
3723 * When this parameter is set to 0, no delay is added to the initial
3725 * When this parameter is set to non-zero value, initial Nport discovery is
3726 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3727 * accept and FCID/Fabric name/Fabric portname is changed.
3728 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3729 * when Clean Address bit is cleared in FLOGI/FDISC
3730 * accept and FCID/Fabric name/Fabric portname is changed.
3731 * Default value is 0.
3733 int lpfc_delay_discovery;
3734 module_param(lpfc_delay_discovery, int, S_IRUGO);
3735 MODULE_PARM_DESC(lpfc_delay_discovery,
3736 "Delay NPort discovery when Clean Address bit is cleared. "
3737 "Allowed values: 0,1.");
3740 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3741 * This value can be set to values between 64 and 256. The default value is
3742 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3743 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3745 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3746 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3748 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3749 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3750 "Max Protection Scatter Gather Segment Count");
3752 struct device_attribute *lpfc_hba_attrs[] = {
3754 &dev_attr_bg_guard_err,
3755 &dev_attr_bg_apptag_err,
3756 &dev_attr_bg_reftag_err,
3758 &dev_attr_serialnum,
3759 &dev_attr_modeldesc,
3760 &dev_attr_modelname,
3761 &dev_attr_programtype,
3765 &dev_attr_option_rom_version,
3766 &dev_attr_link_state,
3767 &dev_attr_num_discovered_ports,
3768 &dev_attr_menlo_mgmt_mode,
3769 &dev_attr_lpfc_drvr_version,
3770 &dev_attr_lpfc_enable_fip,
3771 &dev_attr_lpfc_temp_sensor,
3772 &dev_attr_lpfc_log_verbose,
3773 &dev_attr_lpfc_lun_queue_depth,
3774 &dev_attr_lpfc_tgt_queue_depth,
3775 &dev_attr_lpfc_hba_queue_depth,
3776 &dev_attr_lpfc_peer_port_login,
3777 &dev_attr_lpfc_nodev_tmo,
3778 &dev_attr_lpfc_devloss_tmo,
3779 &dev_attr_lpfc_fcp_class,
3780 &dev_attr_lpfc_use_adisc,
3781 &dev_attr_lpfc_ack0,
3782 &dev_attr_lpfc_topology,
3783 &dev_attr_lpfc_scan_down,
3784 &dev_attr_lpfc_link_speed,
3785 &dev_attr_lpfc_cr_delay,
3786 &dev_attr_lpfc_cr_count,
3787 &dev_attr_lpfc_multi_ring_support,
3788 &dev_attr_lpfc_multi_ring_rctl,
3789 &dev_attr_lpfc_multi_ring_type,
3790 &dev_attr_lpfc_fdmi_on,
3791 &dev_attr_lpfc_max_luns,
3792 &dev_attr_lpfc_enable_npiv,
3793 &dev_attr_lpfc_fcf_failover_policy,
3794 &dev_attr_lpfc_enable_rrq,
3795 &dev_attr_nport_evt_cnt,
3796 &dev_attr_board_mode,
3803 &dev_attr_npiv_info,
3804 &dev_attr_issue_reset,
3805 &dev_attr_lpfc_poll,
3806 &dev_attr_lpfc_poll_tmo,
3807 &dev_attr_lpfc_use_msi,
3808 &dev_attr_lpfc_fcp_imax,
3809 &dev_attr_lpfc_fcp_wq_count,
3810 &dev_attr_lpfc_fcp_eq_count,
3811 &dev_attr_lpfc_enable_bg,
3812 &dev_attr_lpfc_soft_wwnn,
3813 &dev_attr_lpfc_soft_wwpn,
3814 &dev_attr_lpfc_soft_wwn_enable,
3815 &dev_attr_lpfc_enable_hba_reset,
3816 &dev_attr_lpfc_enable_hba_heartbeat,
3817 &dev_attr_lpfc_sg_seg_cnt,
3818 &dev_attr_lpfc_max_scsicmpl_time,
3819 &dev_attr_lpfc_stat_data_ctrl,
3820 &dev_attr_lpfc_prot_sg_seg_cnt,
3821 &dev_attr_lpfc_aer_support,
3822 &dev_attr_lpfc_aer_state_cleanup,
3823 &dev_attr_lpfc_sriov_nr_virtfn,
3824 &dev_attr_lpfc_suppress_link_up,
3825 &dev_attr_lpfc_iocb_cnt,
3828 &dev_attr_txcmplq_hw,
3829 &dev_attr_lpfc_fips_level,
3830 &dev_attr_lpfc_fips_rev,
3832 &dev_attr_lpfc_sriov_hw_max_virtfn,
3836 struct device_attribute *lpfc_vport_attrs[] = {
3838 &dev_attr_link_state,
3839 &dev_attr_num_discovered_ports,
3840 &dev_attr_lpfc_drvr_version,
3841 &dev_attr_lpfc_log_verbose,
3842 &dev_attr_lpfc_lun_queue_depth,
3843 &dev_attr_lpfc_tgt_queue_depth,
3844 &dev_attr_lpfc_nodev_tmo,
3845 &dev_attr_lpfc_devloss_tmo,
3846 &dev_attr_lpfc_hba_queue_depth,
3847 &dev_attr_lpfc_peer_port_login,
3848 &dev_attr_lpfc_restrict_login,
3849 &dev_attr_lpfc_fcp_class,
3850 &dev_attr_lpfc_use_adisc,
3851 &dev_attr_lpfc_fdmi_on,
3852 &dev_attr_lpfc_max_luns,
3853 &dev_attr_nport_evt_cnt,
3854 &dev_attr_npiv_info,
3855 &dev_attr_lpfc_enable_da_id,
3856 &dev_attr_lpfc_max_scsicmpl_time,
3857 &dev_attr_lpfc_stat_data_ctrl,
3858 &dev_attr_lpfc_static_vport,
3859 &dev_attr_lpfc_fips_level,
3860 &dev_attr_lpfc_fips_rev,
3865 * sysfs_ctlreg_write - Write method for writing to ctlreg
3866 * @filp: open sysfs file
3867 * @kobj: kernel kobject that contains the kernel class device.
3868 * @bin_attr: kernel attributes passed to us.
3869 * @buf: contains the data to be written to the adapter IOREG space.
3870 * @off: offset into buffer to beginning of data.
3871 * @count: bytes to transfer.
3874 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3875 * Uses the adapter io control registers to send buf contents to the adapter.
3878 * -ERANGE off and count combo out of range
3879 * -EINVAL off, count or buff address invalid
3880 * -EPERM adapter is offline
3881 * value of count, buf contents written
3884 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3885 struct bin_attribute *bin_attr,
3886 char *buf, loff_t off, size_t count)
3889 struct device *dev = container_of(kobj, struct device, kobj);
3890 struct Scsi_Host *shost = class_to_shost(dev);
3891 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3892 struct lpfc_hba *phba = vport->phba;
3894 if (phba->sli_rev >= LPFC_SLI_REV4)
3897 if ((off + count) > FF_REG_AREA_SIZE)
3900 if (count <= LPFC_REG_WRITE_KEY_SIZE)
3903 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3906 /* This is to protect HBA registers from accidental writes. */
3907 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3910 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3913 spin_lock_irq(&phba->hbalock);
3914 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
3915 buf_off += sizeof(uint32_t))
3916 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
3917 phba->ctrl_regs_memmap_p + off + buf_off);
3919 spin_unlock_irq(&phba->hbalock);
3925 * sysfs_ctlreg_read - Read method for reading from ctlreg
3926 * @filp: open sysfs file
3927 * @kobj: kernel kobject that contains the kernel class device.
3928 * @bin_attr: kernel attributes passed to us.
3929 * @buf: if successful contains the data from the adapter IOREG space.
3930 * @off: offset into buffer to beginning of data.
3931 * @count: bytes to transfer.
3934 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3935 * Uses the adapter io control registers to read data into buf.
3938 * -ERANGE off and count combo out of range
3939 * -EINVAL off, count or buff address invalid
3940 * value of count, buf contents read
3943 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3944 struct bin_attribute *bin_attr,
3945 char *buf, loff_t off, size_t count)
3949 struct device *dev = container_of(kobj, struct device, kobj);
3950 struct Scsi_Host *shost = class_to_shost(dev);
3951 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3952 struct lpfc_hba *phba = vport->phba;
3954 if (phba->sli_rev >= LPFC_SLI_REV4)
3957 if (off > FF_REG_AREA_SIZE)
3960 if ((off + count) > FF_REG_AREA_SIZE)
3961 count = FF_REG_AREA_SIZE - off;
3963 if (count == 0) return 0;
3965 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3968 spin_lock_irq(&phba->hbalock);
3970 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3971 tmp_ptr = (uint32_t *)(buf + buf_off);
3972 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3975 spin_unlock_irq(&phba->hbalock);
3980 static struct bin_attribute sysfs_ctlreg_attr = {
3983 .mode = S_IRUSR | S_IWUSR,
3986 .read = sysfs_ctlreg_read,
3987 .write = sysfs_ctlreg_write,
3991 * sysfs_mbox_idle - frees the sysfs mailbox
3992 * @phba: lpfc_hba pointer
3995 sysfs_mbox_idle(struct lpfc_hba *phba)
3997 phba->sysfs_mbox.state = SMBOX_IDLE;
3998 phba->sysfs_mbox.offset = 0;
4000 if (phba->sysfs_mbox.mbox) {
4001 mempool_free(phba->sysfs_mbox.mbox,
4002 phba->mbox_mem_pool);
4003 phba->sysfs_mbox.mbox = NULL;
4008 * sysfs_mbox_write - Write method for writing information via mbox
4009 * @filp: open sysfs file
4010 * @kobj: kernel kobject that contains the kernel class device.
4011 * @bin_attr: kernel attributes passed to us.
4012 * @buf: contains the data to be written to sysfs mbox.
4013 * @off: offset into buffer to beginning of data.
4014 * @count: bytes to transfer.
4017 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4018 * Uses the sysfs mbox to send buf contents to the adapter.
4021 * -ERANGE off and count combo out of range
4022 * -EINVAL off, count or buff address invalid
4023 * zero if count is zero
4024 * -EPERM adapter is offline
4025 * -ENOMEM failed to allocate memory for the mail box
4026 * -EAGAIN offset, state or mbox is NULL
4027 * count number of bytes transferred
4030 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4031 struct bin_attribute *bin_attr,
4032 char *buf, loff_t off, size_t count)
4034 struct device *dev = container_of(kobj, struct device, kobj);
4035 struct Scsi_Host *shost = class_to_shost(dev);
4036 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4037 struct lpfc_hba *phba = vport->phba;
4038 struct lpfcMboxq *mbox = NULL;
4040 if ((count + off) > MAILBOX_CMD_SIZE)
4043 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4050 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4053 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
4056 spin_lock_irq(&phba->hbalock);
4059 if (phba->sysfs_mbox.mbox)
4060 mempool_free(mbox, phba->mbox_mem_pool);
4062 phba->sysfs_mbox.mbox = mbox;
4063 phba->sysfs_mbox.state = SMBOX_WRITING;
4065 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4066 phba->sysfs_mbox.offset != off ||
4067 phba->sysfs_mbox.mbox == NULL) {
4068 sysfs_mbox_idle(phba);
4069 spin_unlock_irq(&phba->hbalock);
4074 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
4077 phba->sysfs_mbox.offset = off + count;
4079 spin_unlock_irq(&phba->hbalock);
4085 * sysfs_mbox_read - Read method for reading information via mbox
4086 * @filp: open sysfs file
4087 * @kobj: kernel kobject that contains the kernel class device.
4088 * @bin_attr: kernel attributes passed to us.
4089 * @buf: contains the data to be read from sysfs mbox.
4090 * @off: offset into buffer to beginning of data.
4091 * @count: bytes to transfer.
4094 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4095 * Uses the sysfs mbox to receive data from to the adapter.
4098 * -ERANGE off greater than mailbox command size
4099 * -EINVAL off, count or buff address invalid
4100 * zero if off and count are zero
4101 * -EACCES adapter over temp
4102 * -EPERM garbage can value to catch a multitude of errors
4103 * -EAGAIN management IO not permitted, state or off error
4104 * -ETIME mailbox timeout
4105 * -ENODEV mailbox error
4106 * count number of bytes transferred
4109 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4110 struct bin_attribute *bin_attr,
4111 char *buf, loff_t off, size_t count)
4113 struct device *dev = container_of(kobj, struct device, kobj);
4114 struct Scsi_Host *shost = class_to_shost(dev);
4115 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4116 struct lpfc_hba *phba = vport->phba;
4117 LPFC_MBOXQ_t *mboxq;
4122 if (off > MAILBOX_CMD_SIZE)
4125 if ((count + off) > MAILBOX_CMD_SIZE)
4126 count = MAILBOX_CMD_SIZE - off;
4128 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4131 if (off && count == 0)
4134 spin_lock_irq(&phba->hbalock);
4136 if (phba->over_temp_state == HBA_OVER_TEMP) {
4137 sysfs_mbox_idle(phba);
4138 spin_unlock_irq(&phba->hbalock);
4143 phba->sysfs_mbox.state == SMBOX_WRITING &&
4144 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
4145 mboxq = (LPFC_MBOXQ_t *)&phba->sysfs_mbox.mbox;
4147 switch (pmb->mbxCommand) {
4151 case MBX_CONFIG_LINK:
4152 case MBX_CONFIG_RING:
4153 case MBX_RESET_RING:
4154 case MBX_UNREG_LOGIN:
4156 case MBX_DUMP_CONTEXT:
4161 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
4162 printk(KERN_WARNING "mbox_read:Command 0x%x "
4163 "is illegal in on-line state\n",
4165 sysfs_mbox_idle(phba);
4166 spin_unlock_irq(&phba->hbalock);
4170 case MBX_WRITE_VPARMS:
4173 case MBX_READ_CONFIG:
4174 case MBX_READ_RCONFIG:
4175 case MBX_READ_STATUS:
4178 case MBX_READ_LNK_STAT:
4179 case MBX_DUMP_MEMORY:
4181 case MBX_UPDATE_CFG:
4182 case MBX_KILL_BOARD:
4184 case MBX_LOAD_EXP_ROM:
4186 case MBX_DEL_LD_ENTRY:
4187 case MBX_SET_VARIABLE:
4189 case MBX_PORT_CAPABILITIES:
4190 case MBX_PORT_IOV_CONTROL:
4192 case MBX_SECURITY_MGMT:
4194 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4195 printk(KERN_WARNING "mbox_read:Command 0x%x "
4196 "is not permitted\n", pmb->mbxCommand);
4197 sysfs_mbox_idle(phba);
4198 spin_unlock_irq(&phba->hbalock);
4202 case MBX_READ_SPARM64:
4203 case MBX_READ_TOPOLOGY:
4205 case MBX_REG_LOGIN64:
4206 case MBX_CONFIG_PORT:
4207 case MBX_RUN_BIU_DIAG:
4208 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
4210 sysfs_mbox_idle(phba);
4211 spin_unlock_irq(&phba->hbalock);
4214 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
4216 sysfs_mbox_idle(phba);
4217 spin_unlock_irq(&phba->hbalock);
4221 /* If HBA encountered an error attention, allow only DUMP
4222 * or RESTART mailbox commands until the HBA is restarted.
4224 if (phba->pport->stopped &&
4225 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4226 pmb->mbxCommand != MBX_RESTART &&
4227 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4228 pmb->mbxCommand != MBX_WRITE_WWN)
4229 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4230 "1259 mbox: Issued mailbox cmd "
4231 "0x%x while in stopped state.\n",
4234 phba->sysfs_mbox.mbox->vport = vport;
4236 /* Don't allow mailbox commands to be sent when blocked
4237 * or when in the middle of discovery
4239 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
4240 sysfs_mbox_idle(phba);
4241 spin_unlock_irq(&phba->hbalock);
4245 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4246 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
4248 spin_unlock_irq(&phba->hbalock);
4249 rc = lpfc_sli_issue_mbox (phba,
4250 phba->sysfs_mbox.mbox,
4252 spin_lock_irq(&phba->hbalock);
4255 spin_unlock_irq(&phba->hbalock);
4256 mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
4257 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
4258 spin_lock_irq(&phba->hbalock);
4261 if (rc != MBX_SUCCESS) {
4262 if (rc == MBX_TIMEOUT) {
4263 phba->sysfs_mbox.mbox = NULL;
4265 sysfs_mbox_idle(phba);
4266 spin_unlock_irq(&phba->hbalock);
4267 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
4269 phba->sysfs_mbox.state = SMBOX_READING;
4271 else if (phba->sysfs_mbox.offset != off ||
4272 phba->sysfs_mbox.state != SMBOX_READING) {
4273 printk(KERN_WARNING "mbox_read: Bad State\n");
4274 sysfs_mbox_idle(phba);
4275 spin_unlock_irq(&phba->hbalock);
4279 memcpy(buf, (uint8_t *) &pmb + off, count);
4281 phba->sysfs_mbox.offset = off + count;
4283 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
4284 sysfs_mbox_idle(phba);
4286 spin_unlock_irq(&phba->hbalock);
4291 static struct bin_attribute sysfs_mbox_attr = {
4294 .mode = S_IRUSR | S_IWUSR,
4296 .size = MAILBOX_SYSFS_MAX,
4297 .read = sysfs_mbox_read,
4298 .write = sysfs_mbox_write,
4302 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
4303 * @vport: address of lpfc vport structure.
4307 * error return code from sysfs_create_bin_file()
4310 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
4312 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4315 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4316 &sysfs_drvr_stat_data_attr);
4318 /* Virtual ports do not need ctrl_reg and mbox */
4319 if (error || vport->port_type == LPFC_NPIV_PORT)
4322 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4323 &sysfs_ctlreg_attr);
4325 goto out_remove_stat_attr;
4327 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4330 goto out_remove_ctlreg_attr;
4333 out_remove_ctlreg_attr:
4334 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4335 out_remove_stat_attr:
4336 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4337 &sysfs_drvr_stat_data_attr);
4343 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4344 * @vport: address of lpfc vport structure.
4347 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4349 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4350 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4351 &sysfs_drvr_stat_data_attr);
4352 /* Virtual ports do not need ctrl_reg and mbox */
4353 if (vport->port_type == LPFC_NPIV_PORT)
4355 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4356 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4361 * Dynamic FC Host Attributes Support
4365 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4366 * @shost: kernel scsi host pointer.
4369 lpfc_get_host_port_id(struct Scsi_Host *shost)
4371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4373 /* note: fc_myDID already in cpu endianness */
4374 fc_host_port_id(shost) = vport->fc_myDID;
4378 * lpfc_get_host_port_type - Set the value of the scsi host port type
4379 * @shost: kernel scsi host pointer.
4382 lpfc_get_host_port_type(struct Scsi_Host *shost)
4384 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4385 struct lpfc_hba *phba = vport->phba;
4387 spin_lock_irq(shost->host_lock);
4389 if (vport->port_type == LPFC_NPIV_PORT) {
4390 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4391 } else if (lpfc_is_link_up(phba)) {
4392 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4393 if (vport->fc_flag & FC_PUBLIC_LOOP)
4394 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4396 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4398 if (vport->fc_flag & FC_FABRIC)
4399 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4401 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4404 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4406 spin_unlock_irq(shost->host_lock);
4410 * lpfc_get_host_port_state - Set the value of the scsi host port state
4411 * @shost: kernel scsi host pointer.
4414 lpfc_get_host_port_state(struct Scsi_Host *shost)
4416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4417 struct lpfc_hba *phba = vport->phba;
4419 spin_lock_irq(shost->host_lock);
4421 if (vport->fc_flag & FC_OFFLINE_MODE)
4422 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4424 switch (phba->link_state) {
4425 case LPFC_LINK_UNKNOWN:
4426 case LPFC_LINK_DOWN:
4427 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4431 case LPFC_HBA_READY:
4432 /* Links up, beyond this port_type reports state */
4433 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4435 case LPFC_HBA_ERROR:
4436 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4439 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4444 spin_unlock_irq(shost->host_lock);
4448 * lpfc_get_host_speed - Set the value of the scsi host speed
4449 * @shost: kernel scsi host pointer.
4452 lpfc_get_host_speed(struct Scsi_Host *shost)
4454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4455 struct lpfc_hba *phba = vport->phba;
4457 spin_lock_irq(shost->host_lock);
4459 if (lpfc_is_link_up(phba)) {
4460 switch(phba->fc_linkspeed) {
4461 case LPFC_LINK_SPEED_1GHZ:
4462 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4464 case LPFC_LINK_SPEED_2GHZ:
4465 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4467 case LPFC_LINK_SPEED_4GHZ:
4468 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4470 case LPFC_LINK_SPEED_8GHZ:
4471 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4473 case LPFC_LINK_SPEED_10GHZ:
4474 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4476 case LPFC_LINK_SPEED_16GHZ:
4477 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4480 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4484 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4486 spin_unlock_irq(shost->host_lock);
4490 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4491 * @shost: kernel scsi host pointer.
4494 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4496 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4497 struct lpfc_hba *phba = vport->phba;
4500 spin_lock_irq(shost->host_lock);
4502 if ((vport->port_state > LPFC_FLOGI) &&
4503 ((vport->fc_flag & FC_FABRIC) ||
4504 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4505 (vport->fc_flag & FC_PUBLIC_LOOP))))
4506 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4508 /* fabric is local port if there is no F/FL_Port */
4511 spin_unlock_irq(shost->host_lock);
4513 fc_host_fabric_name(shost) = node_name;
4517 * lpfc_get_stats - Return statistical information about the adapter
4518 * @shost: kernel scsi host pointer.
4521 * NULL on error for link down, no mbox pool, sli2 active,
4522 * management not allowed, memory allocation error, or mbox error.
4526 * address of the adapter host statistics
4528 static struct fc_host_statistics *
4529 lpfc_get_stats(struct Scsi_Host *shost)
4531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4532 struct lpfc_hba *phba = vport->phba;
4533 struct lpfc_sli *psli = &phba->sli;
4534 struct fc_host_statistics *hs = &phba->link_stats;
4535 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4536 LPFC_MBOXQ_t *pmboxq;
4538 unsigned long seconds;
4542 * prevent udev from issuing mailbox commands until the port is
4545 if (phba->link_state < LPFC_LINK_DOWN ||
4546 !phba->mbox_mem_pool ||
4547 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4550 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4553 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4556 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4558 pmb = &pmboxq->u.mb;
4559 pmb->mbxCommand = MBX_READ_STATUS;
4560 pmb->mbxOwner = OWN_HOST;
4561 pmboxq->context1 = NULL;
4562 pmboxq->vport = vport;
4564 if (vport->fc_flag & FC_OFFLINE_MODE)
4565 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4567 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4569 if (rc != MBX_SUCCESS) {
4570 if (rc != MBX_TIMEOUT)
4571 mempool_free(pmboxq, phba->mbox_mem_pool);
4575 memset(hs, 0, sizeof (struct fc_host_statistics));
4577 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4579 * The MBX_READ_STATUS returns tx_k_bytes which has to
4580 * converted to words
4582 hs->tx_words = (uint64_t)
4583 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4585 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4586 hs->rx_words = (uint64_t)
4587 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4590 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4591 pmb->mbxCommand = MBX_READ_LNK_STAT;
4592 pmb->mbxOwner = OWN_HOST;
4593 pmboxq->context1 = NULL;
4594 pmboxq->vport = vport;
4596 if (vport->fc_flag & FC_OFFLINE_MODE)
4597 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4599 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4601 if (rc != MBX_SUCCESS) {
4602 if (rc != MBX_TIMEOUT)
4603 mempool_free(pmboxq, phba->mbox_mem_pool);
4607 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4608 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4609 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4610 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4611 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4612 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4613 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4615 hs->link_failure_count -= lso->link_failure_count;
4616 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4617 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4618 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4619 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4620 hs->invalid_crc_count -= lso->invalid_crc_count;
4621 hs->error_frames -= lso->error_frames;
4623 if (phba->hba_flag & HBA_FCOE_MODE) {
4625 hs->nos_count = (phba->link_events >> 1);
4626 hs->nos_count -= lso->link_events;
4627 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4628 hs->lip_count = (phba->fc_eventTag >> 1);
4629 hs->lip_count -= lso->link_events;
4633 hs->nos_count = (phba->fc_eventTag >> 1);
4634 hs->nos_count -= lso->link_events;
4637 hs->dumped_frames = -1;
4639 seconds = get_seconds();
4640 if (seconds < psli->stats_start)
4641 hs->seconds_since_last_reset = seconds +
4642 ((unsigned long)-1 - psli->stats_start);
4644 hs->seconds_since_last_reset = seconds - psli->stats_start;
4646 mempool_free(pmboxq, phba->mbox_mem_pool);
4652 * lpfc_reset_stats - Copy the adapter link stats information
4653 * @shost: kernel scsi host pointer.
4656 lpfc_reset_stats(struct Scsi_Host *shost)
4658 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4659 struct lpfc_hba *phba = vport->phba;
4660 struct lpfc_sli *psli = &phba->sli;
4661 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4662 LPFC_MBOXQ_t *pmboxq;
4666 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4669 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4672 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4674 pmb = &pmboxq->u.mb;
4675 pmb->mbxCommand = MBX_READ_STATUS;
4676 pmb->mbxOwner = OWN_HOST;
4677 pmb->un.varWords[0] = 0x1; /* reset request */
4678 pmboxq->context1 = NULL;
4679 pmboxq->vport = vport;
4681 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4682 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4683 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4685 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4687 if (rc != MBX_SUCCESS) {
4688 if (rc != MBX_TIMEOUT)
4689 mempool_free(pmboxq, phba->mbox_mem_pool);
4693 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4694 pmb->mbxCommand = MBX_READ_LNK_STAT;
4695 pmb->mbxOwner = OWN_HOST;
4696 pmboxq->context1 = NULL;
4697 pmboxq->vport = vport;
4699 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4700 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4701 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4703 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4705 if (rc != MBX_SUCCESS) {
4706 if (rc != MBX_TIMEOUT)
4707 mempool_free( pmboxq, phba->mbox_mem_pool);
4711 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4712 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4713 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4714 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4715 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4716 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4717 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4718 if (phba->hba_flag & HBA_FCOE_MODE)
4719 lso->link_events = (phba->link_events >> 1);
4721 lso->link_events = (phba->fc_eventTag >> 1);
4723 psli->stats_start = get_seconds();
4725 mempool_free(pmboxq, phba->mbox_mem_pool);
4731 * The LPFC driver treats linkdown handling as target loss events so there
4732 * are no sysfs handlers for link_down_tmo.
4736 * lpfc_get_node_by_target - Return the nodelist for a target
4737 * @starget: kernel scsi target pointer.
4740 * address of the node list if found
4741 * NULL target not found
4743 static struct lpfc_nodelist *
4744 lpfc_get_node_by_target(struct scsi_target *starget)
4746 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4747 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4748 struct lpfc_nodelist *ndlp;
4750 spin_lock_irq(shost->host_lock);
4751 /* Search for this, mapped, target ID */
4752 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4753 if (NLP_CHK_NODE_ACT(ndlp) &&
4754 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4755 starget->id == ndlp->nlp_sid) {
4756 spin_unlock_irq(shost->host_lock);
4760 spin_unlock_irq(shost->host_lock);
4765 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4766 * @starget: kernel scsi target pointer.
4769 lpfc_get_starget_port_id(struct scsi_target *starget)
4771 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4773 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4777 * lpfc_get_starget_node_name - Set the target node name
4778 * @starget: kernel scsi target pointer.
4780 * Description: Set the target node name to the ndlp node name wwn or zero.
4783 lpfc_get_starget_node_name(struct scsi_target *starget)
4785 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4787 fc_starget_node_name(starget) =
4788 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4792 * lpfc_get_starget_port_name - Set the target port name
4793 * @starget: kernel scsi target pointer.
4795 * Description: set the target port name to the ndlp port name wwn or zero.
4798 lpfc_get_starget_port_name(struct scsi_target *starget)
4800 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4802 fc_starget_port_name(starget) =
4803 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4807 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4808 * @rport: fc rport address.
4809 * @timeout: new value for dev loss tmo.
4812 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4813 * dev_loss_tmo to one.
4816 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4819 rport->dev_loss_tmo = timeout;
4821 rport->dev_loss_tmo = 1;
4825 * lpfc_rport_show_function - Return rport target information
4828 * Macro that uses field to generate a function with the name lpfc_show_rport_
4830 * lpfc_show_rport_##field: returns the bytes formatted in buf
4831 * @cdev: class converted to an fc_rport.
4832 * @buf: on return contains the target_field or zero.
4834 * Returns: size of formatted string.
4836 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4838 lpfc_show_rport_##field (struct device *dev, \
4839 struct device_attribute *attr, \
4842 struct fc_rport *rport = transport_class_to_rport(dev); \
4843 struct lpfc_rport_data *rdata = rport->hostdata; \
4844 return snprintf(buf, sz, format_string, \
4845 (rdata->target) ? cast rdata->target->field : 0); \
4848 #define lpfc_rport_rd_attr(field, format_string, sz) \
4849 lpfc_rport_show_function(field, format_string, sz, ) \
4850 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4853 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4854 * @fc_vport: The fc_vport who's symbolic name has been changed.
4857 * This function is called by the transport after the @fc_vport's symbolic name
4858 * has been changed. This function re-registers the symbolic name with the
4859 * switch to propagate the change into the fabric if the vport is active.
4862 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4864 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4866 if (vport->port_state == LPFC_VPORT_READY)
4867 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4871 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4872 * @phba: Pointer to lpfc_hba struct.
4874 * This function is called by the lpfc_get_cfgparam() routine to set the
4875 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4876 * log message according to the module's lpfc_log_verbose parameter setting
4877 * before hba port or vport created.
4880 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4882 phba->cfg_log_verbose = verbose;
4885 struct fc_function_template lpfc_transport_functions = {
4886 /* fixed attributes the driver supports */
4887 .show_host_node_name = 1,
4888 .show_host_port_name = 1,
4889 .show_host_supported_classes = 1,
4890 .show_host_supported_fc4s = 1,
4891 .show_host_supported_speeds = 1,
4892 .show_host_maxframe_size = 1,
4893 .show_host_symbolic_name = 1,
4895 /* dynamic attributes the driver supports */
4896 .get_host_port_id = lpfc_get_host_port_id,
4897 .show_host_port_id = 1,
4899 .get_host_port_type = lpfc_get_host_port_type,
4900 .show_host_port_type = 1,
4902 .get_host_port_state = lpfc_get_host_port_state,
4903 .show_host_port_state = 1,
4905 /* active_fc4s is shown but doesn't change (thus no get function) */
4906 .show_host_active_fc4s = 1,
4908 .get_host_speed = lpfc_get_host_speed,
4909 .show_host_speed = 1,
4911 .get_host_fabric_name = lpfc_get_host_fabric_name,
4912 .show_host_fabric_name = 1,
4915 * The LPFC driver treats linkdown handling as target loss events
4916 * so there are no sysfs handlers for link_down_tmo.
4919 .get_fc_host_stats = lpfc_get_stats,
4920 .reset_fc_host_stats = lpfc_reset_stats,
4922 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4923 .show_rport_maxframe_size = 1,
4924 .show_rport_supported_classes = 1,
4926 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4927 .show_rport_dev_loss_tmo = 1,
4929 .get_starget_port_id = lpfc_get_starget_port_id,
4930 .show_starget_port_id = 1,
4932 .get_starget_node_name = lpfc_get_starget_node_name,
4933 .show_starget_node_name = 1,
4935 .get_starget_port_name = lpfc_get_starget_port_name,
4936 .show_starget_port_name = 1,
4938 .issue_fc_host_lip = lpfc_issue_lip,
4939 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4940 .terminate_rport_io = lpfc_terminate_rport_io,
4942 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4944 .vport_disable = lpfc_vport_disable,
4946 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4948 .bsg_request = lpfc_bsg_request,
4949 .bsg_timeout = lpfc_bsg_timeout,
4952 struct fc_function_template lpfc_vport_transport_functions = {
4953 /* fixed attributes the driver supports */
4954 .show_host_node_name = 1,
4955 .show_host_port_name = 1,
4956 .show_host_supported_classes = 1,
4957 .show_host_supported_fc4s = 1,
4958 .show_host_supported_speeds = 1,
4959 .show_host_maxframe_size = 1,
4960 .show_host_symbolic_name = 1,
4962 /* dynamic attributes the driver supports */
4963 .get_host_port_id = lpfc_get_host_port_id,
4964 .show_host_port_id = 1,
4966 .get_host_port_type = lpfc_get_host_port_type,
4967 .show_host_port_type = 1,
4969 .get_host_port_state = lpfc_get_host_port_state,
4970 .show_host_port_state = 1,
4972 /* active_fc4s is shown but doesn't change (thus no get function) */
4973 .show_host_active_fc4s = 1,
4975 .get_host_speed = lpfc_get_host_speed,
4976 .show_host_speed = 1,
4978 .get_host_fabric_name = lpfc_get_host_fabric_name,
4979 .show_host_fabric_name = 1,
4982 * The LPFC driver treats linkdown handling as target loss events
4983 * so there are no sysfs handlers for link_down_tmo.
4986 .get_fc_host_stats = lpfc_get_stats,
4987 .reset_fc_host_stats = lpfc_reset_stats,
4989 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4990 .show_rport_maxframe_size = 1,
4991 .show_rport_supported_classes = 1,
4993 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4994 .show_rport_dev_loss_tmo = 1,
4996 .get_starget_port_id = lpfc_get_starget_port_id,
4997 .show_starget_port_id = 1,
4999 .get_starget_node_name = lpfc_get_starget_node_name,
5000 .show_starget_node_name = 1,
5002 .get_starget_port_name = lpfc_get_starget_port_name,
5003 .show_starget_port_name = 1,
5005 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5006 .terminate_rport_io = lpfc_terminate_rport_io,
5008 .vport_disable = lpfc_vport_disable,
5010 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5014 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
5015 * @phba: lpfc_hba pointer.
5018 lpfc_get_cfgparam(struct lpfc_hba *phba)
5020 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5021 lpfc_cr_count_init(phba, lpfc_cr_count);
5022 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5023 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5024 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5025 lpfc_ack0_init(phba, lpfc_ack0);
5026 lpfc_topology_init(phba, lpfc_topology);
5027 lpfc_link_speed_init(phba, lpfc_link_speed);
5028 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5029 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5030 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
5031 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5032 lpfc_use_msi_init(phba, lpfc_use_msi);
5033 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5034 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5035 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
5036 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5037 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5038 lpfc_enable_bg_init(phba, lpfc_enable_bg);
5039 if (phba->sli_rev == LPFC_SLI_REV4)
5042 phba->cfg_poll = lpfc_poll;
5043 phba->cfg_soft_wwnn = 0L;
5044 phba->cfg_soft_wwpn = 0L;
5045 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5046 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5047 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5048 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5049 lpfc_aer_support_init(phba, lpfc_aer_support);
5050 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5051 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5052 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5053 phba->cfg_enable_dss = 1;
5058 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5059 * @vport: lpfc_vport pointer.
5062 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5064 lpfc_log_verbose_init(vport, lpfc_log_verbose);
5065 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5066 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5067 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5068 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5069 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5070 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5071 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5072 lpfc_use_adisc_init(vport, lpfc_use_adisc);
5073 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5074 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5075 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5076 lpfc_max_luns_init(vport, lpfc_max_luns);
5077 lpfc_scan_down_init(vport, lpfc_scan_down);
5078 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);