1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 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 char fwrev[FW_REV_STR_SIZE];
359 lpfc_decode_firmware_rev(phba, fwrev, 1);
360 if_type = phba->sli4_hba.pc_sli4_params.if_type;
361 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
363 if (phba->sli_rev < LPFC_SLI_REV4)
364 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
365 fwrev, phba->sli_rev);
367 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
368 fwrev, phba->sli_rev, if_type, sli_family);
374 * lpfc_hdw_show - Return the jedec information about the hba
375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the scsi vpd program type.
379 * Returns: size of formatted string.
382 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
385 struct Scsi_Host *shost = class_to_shost(dev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388 lpfc_vpd_t *vp = &phba->vpd;
390 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
391 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
395 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains the ROM and FCode ascii strings.
400 * Returns: size of formatted string.
403 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
406 struct Scsi_Host *shost = class_to_shost(dev);
407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
409 char fwrev[FW_REV_STR_SIZE];
411 if (phba->sli_rev < LPFC_SLI_REV4)
412 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
414 lpfc_decode_firmware_rev(phba, fwrev, 1);
415 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
419 * lpfc_state_show - Return the link state of the port
420 * @dev: class converted to a Scsi_host structure.
421 * @attr: device attribute, not used.
422 * @buf: on return contains text describing the state of the link.
425 * The switch statement has no default so zero will be returned.
427 * Returns: size of formatted string.
430 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
433 struct Scsi_Host *shost = class_to_shost(dev);
434 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
435 struct lpfc_hba *phba = vport->phba;
438 switch (phba->link_state) {
439 case LPFC_LINK_UNKNOWN:
440 case LPFC_WARM_START:
441 case LPFC_INIT_START:
442 case LPFC_INIT_MBX_CMDS:
445 if (phba->hba_flag & LINK_DISABLED)
446 len += snprintf(buf + len, PAGE_SIZE-len,
447 "Link Down - User disabled\n");
449 len += snprintf(buf + len, PAGE_SIZE-len,
455 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
457 switch (vport->port_state) {
458 case LPFC_LOCAL_CFG_LINK:
459 len += snprintf(buf + len, PAGE_SIZE-len,
460 "Configuring Link\n");
464 case LPFC_FABRIC_CFG_LINK:
467 case LPFC_BUILD_DISC_LIST:
469 len += snprintf(buf + len, PAGE_SIZE - len,
472 case LPFC_VPORT_READY:
473 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
476 case LPFC_VPORT_FAILED:
477 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
480 case LPFC_VPORT_UNKNOWN:
481 len += snprintf(buf + len, PAGE_SIZE - len,
485 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
486 len += snprintf(buf + len, PAGE_SIZE-len,
487 " Menlo Maint Mode\n");
488 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
489 if (vport->fc_flag & FC_PUBLIC_LOOP)
490 len += snprintf(buf + len, PAGE_SIZE-len,
493 len += snprintf(buf + len, PAGE_SIZE-len,
496 if (vport->fc_flag & FC_FABRIC)
497 len += snprintf(buf + len, PAGE_SIZE-len,
500 len += snprintf(buf + len, PAGE_SIZE-len,
509 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
510 * @dev: class unused variable.
511 * @attr: device attribute, not used.
512 * @buf: on return contains the module description text.
514 * Returns: size of formatted string.
517 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
520 struct Scsi_Host *shost = class_to_shost(dev);
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
522 struct lpfc_hba *phba = vport->phba;
524 if (phba->sli_rev < LPFC_SLI_REV4)
525 return snprintf(buf, PAGE_SIZE, "fc\n");
527 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
528 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
529 return snprintf(buf, PAGE_SIZE, "fcoe\n");
530 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
531 return snprintf(buf, PAGE_SIZE, "fc\n");
533 return snprintf(buf, PAGE_SIZE, "unknown\n");
537 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
538 * (OAS) is supported.
539 * @dev: class unused variable.
540 * @attr: device attribute, not used.
541 * @buf: on return contains the module description text.
543 * Returns: size of formatted string.
546 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
549 struct Scsi_Host *shost = class_to_shost(dev);
550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
551 struct lpfc_hba *phba = vport->phba;
553 return snprintf(buf, PAGE_SIZE, "%d\n",
554 phba->sli4_hba.pc_sli4_params.oas_supported);
558 * lpfc_link_state_store - Transition the link_state on an HBA port
559 * @dev: class device that is converted into a Scsi_host.
560 * @attr: device attribute, not used.
561 * @buf: one or more lpfc_polling_flags values.
565 * -EINVAL if the buffer is not "up" or "down"
566 * return from link state change function if non-zero
567 * length of the buf on success
570 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
571 const char *buf, size_t count)
573 struct Scsi_Host *shost = class_to_shost(dev);
574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
575 struct lpfc_hba *phba = vport->phba;
577 int status = -EINVAL;
579 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
580 (phba->link_state == LPFC_LINK_DOWN))
581 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
582 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
583 (phba->link_state >= LPFC_LINK_UP))
584 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
593 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
594 * @dev: class device that is converted into a Scsi_host.
595 * @attr: device attribute, not used.
596 * @buf: on return contains the sum of fc mapped and unmapped.
599 * Returns the ascii text number of the sum of the fc mapped and unmapped
602 * Returns: size of formatted string.
605 lpfc_num_discovered_ports_show(struct device *dev,
606 struct device_attribute *attr, char *buf)
608 struct Scsi_Host *shost = class_to_shost(dev);
609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
611 return snprintf(buf, PAGE_SIZE, "%d\n",
612 vport->fc_map_cnt + vport->fc_unmap_cnt);
616 * lpfc_issue_lip - Misnomer, name carried over from long ago
617 * @shost: Scsi_Host pointer.
620 * Bring the link down gracefully then re-init the link. The firmware will
621 * re-init the fiber channel interface as required. Does not issue a LIP.
624 * -EPERM port offline or management commands are being blocked
625 * -ENOMEM cannot allocate memory for the mailbox command
626 * -EIO error sending the mailbox command
630 lpfc_issue_lip(struct Scsi_Host *shost)
632 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
633 struct lpfc_hba *phba = vport->phba;
634 LPFC_MBOXQ_t *pmboxq;
635 int mbxstatus = MBXERR_ERROR;
638 * If the link is offline, disabled or BLOCK_MGMT_IO
639 * it doesn't make any sense to allow issue_lip
641 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
642 (phba->hba_flag & LINK_DISABLED) ||
643 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
646 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
651 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
652 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
653 pmboxq->u.mb.mbxOwner = OWN_HOST;
655 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
657 if ((mbxstatus == MBX_SUCCESS) &&
658 (pmboxq->u.mb.mbxStatus == 0 ||
659 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
660 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
661 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
662 phba->cfg_link_speed);
663 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
665 if ((mbxstatus == MBX_SUCCESS) &&
666 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
667 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
668 "2859 SLI authentication is required "
669 "for INIT_LINK but has not done yet\n");
672 lpfc_set_loopback_flag(phba);
673 if (mbxstatus != MBX_TIMEOUT)
674 mempool_free(pmboxq, phba->mbox_mem_pool);
676 if (mbxstatus == MBXERR_ERROR)
683 * lpfc_do_offline - Issues a mailbox command to bring the link down
684 * @phba: lpfc_hba pointer.
685 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
688 * Assumes any error from lpfc_do_offline() will be negative.
689 * Can wait up to 5 seconds for the port ring buffers count
690 * to reach zero, prints a warning if it is not zero and continues.
691 * lpfc_workq_post_event() returns a non-zero return code if call fails.
694 * -EIO error posting the event
698 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
700 struct completion online_compl;
701 struct lpfc_sli_ring *pring;
702 struct lpfc_sli *psli;
708 init_completion(&online_compl);
709 rc = lpfc_workq_post_event(phba, &status, &online_compl,
710 LPFC_EVT_OFFLINE_PREP);
714 wait_for_completion(&online_compl);
721 /* Wait a little for things to settle down, but not
722 * long enough for dev loss timeout to expire.
724 for (i = 0; i < psli->num_rings; i++) {
725 pring = &psli->ring[i];
726 while (!list_empty(&pring->txcmplq)) {
728 if (cnt++ > 500) { /* 5 secs */
729 lpfc_printf_log(phba,
730 KERN_WARNING, LOG_INIT,
731 "0466 Outstanding IO when "
732 "bringing Adapter offline\n");
738 init_completion(&online_compl);
739 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
743 wait_for_completion(&online_compl);
752 * lpfc_selective_reset - Offline then onlines the port
753 * @phba: lpfc_hba pointer.
756 * If the port is configured to allow a reset then the hba is brought
757 * offline then online.
760 * Assumes any error from lpfc_do_offline() will be negative.
761 * Do not make this function static.
764 * lpfc_do_offline() return code if not zero
765 * -EIO reset not configured or error posting the event
769 lpfc_selective_reset(struct lpfc_hba *phba)
771 struct completion online_compl;
775 if (!phba->cfg_enable_hba_reset)
778 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
779 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
785 init_completion(&online_compl);
786 rc = lpfc_workq_post_event(phba, &status, &online_compl,
791 wait_for_completion(&online_compl);
800 * lpfc_issue_reset - Selectively resets an adapter
801 * @dev: class device that is converted into a Scsi_host.
802 * @attr: device attribute, not used.
803 * @buf: containing the string "selective".
804 * @count: unused variable.
807 * If the buf contains the string "selective" then lpfc_selective_reset()
808 * is called to perform the reset.
811 * Assumes any error from lpfc_selective_reset() will be negative.
812 * If lpfc_selective_reset() returns zero then the length of the buffer
813 * is returned which indicates success
816 * -EINVAL if the buffer does not contain the string "selective"
817 * length of buf if lpfc-selective_reset() if the call succeeds
818 * return value of lpfc_selective_reset() if the call fails
821 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
822 const char *buf, size_t count)
824 struct Scsi_Host *shost = class_to_shost(dev);
825 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
826 struct lpfc_hba *phba = vport->phba;
827 int status = -EINVAL;
829 if (!phba->cfg_enable_hba_reset)
832 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
833 status = phba->lpfc_selective_reset(phba);
842 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
843 * @phba: lpfc_hba pointer.
846 * SLI4 interface type-2 device to wait on the sliport status register for
847 * the readyness after performing a firmware reset.
850 * zero for success, -EPERM when port does not have privilege to perform the
851 * reset, -EIO when port timeout from recovering from the reset.
854 * As the caller will interpret the return code by value, be careful in making
855 * change or addition to return codes.
858 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
860 struct lpfc_register portstat_reg = {0};
864 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
865 &portstat_reg.word0);
867 /* verify if privileged for the request operation */
868 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
869 !bf_get(lpfc_sliport_status_err, &portstat_reg))
872 /* wait for the SLI port firmware ready after firmware reset */
873 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
875 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
876 &portstat_reg.word0);
877 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
879 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
881 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
886 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
893 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
894 * @phba: lpfc_hba pointer.
897 * Request SLI4 interface type-2 device to perform a physical register set
904 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
906 struct completion online_compl;
907 struct pci_dev *pdev = phba->pcidev;
908 uint32_t before_fc_flag;
909 uint32_t sriov_nr_virtfn;
911 int status = 0, rc = 0;
912 int job_posted = 1, sriov_err;
914 if (!phba->cfg_enable_hba_reset)
917 if ((phba->sli_rev < LPFC_SLI_REV4) ||
918 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
919 LPFC_SLI_INTF_IF_TYPE_2))
922 /* Keep state if we need to restore back */
923 before_fc_flag = phba->pport->fc_flag;
924 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
926 /* Disable SR-IOV virtual functions if enabled */
927 if (phba->cfg_sriov_nr_virtfn) {
928 pci_disable_sriov(pdev);
929 phba->cfg_sriov_nr_virtfn = 0;
932 if (opcode == LPFC_FW_DUMP)
933 phba->hba_flag |= HBA_FW_DUMP_OP;
935 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
938 phba->hba_flag &= ~HBA_FW_DUMP_OP;
942 /* wait for the device to be quiesced before firmware reset */
945 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
946 LPFC_CTL_PDEV_CTL_OFFSET);
948 if (opcode == LPFC_FW_DUMP)
949 reg_val |= LPFC_FW_DUMP_REQUEST;
950 else if (opcode == LPFC_FW_RESET)
951 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
952 else if (opcode == LPFC_DV_RESET)
953 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
955 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
956 LPFC_CTL_PDEV_CTL_OFFSET);
958 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
960 /* delay driver action following IF_TYPE_2 reset */
961 rc = lpfc_sli4_pdev_status_reg_wait(phba);
964 /* no privilege for reset */
965 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
966 "3150 No privilege to perform the requested "
967 "access: x%x\n", reg_val);
968 } else if (rc == -EIO) {
969 /* reset failed, there is nothing more we can do */
970 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
971 "3153 Fail to perform the requested "
972 "access: x%x\n", reg_val);
976 /* keep the original port state */
977 if (before_fc_flag & FC_OFFLINE_MODE)
980 init_completion(&online_compl);
981 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
986 wait_for_completion(&online_compl);
989 /* in any case, restore the virtual functions enabled as before */
990 if (sriov_nr_virtfn) {
992 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
994 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
997 /* return proper error code */
1008 * lpfc_nport_evt_cnt_show - Return the number of nport events
1009 * @dev: class device that is converted into a Scsi_host.
1010 * @attr: device attribute, not used.
1011 * @buf: on return contains the ascii number of nport events.
1013 * Returns: size of formatted string.
1016 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1019 struct Scsi_Host *shost = class_to_shost(dev);
1020 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1021 struct lpfc_hba *phba = vport->phba;
1023 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1027 * lpfc_board_mode_show - Return the state of the board
1028 * @dev: class device that is converted into a Scsi_host.
1029 * @attr: device attribute, not used.
1030 * @buf: on return contains the state of the adapter.
1032 * Returns: size of formatted string.
1035 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1038 struct Scsi_Host *shost = class_to_shost(dev);
1039 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1040 struct lpfc_hba *phba = vport->phba;
1043 if (phba->link_state == LPFC_HBA_ERROR)
1045 else if (phba->link_state == LPFC_WARM_START)
1046 state = "warm start";
1047 else if (phba->link_state == LPFC_INIT_START)
1052 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1056 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1057 * @dev: class device that is converted into a Scsi_host.
1058 * @attr: device attribute, not used.
1059 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1060 * @count: unused variable.
1063 * -EACCES if enable hba reset not enabled
1064 * -EINVAL if the buffer does not contain a valid string (see above)
1065 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1066 * buf length greater than zero indicates success
1069 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1070 const char *buf, size_t count)
1072 struct Scsi_Host *shost = class_to_shost(dev);
1073 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1074 struct lpfc_hba *phba = vport->phba;
1075 struct completion online_compl;
1076 char *board_mode_str = NULL;
1080 if (!phba->cfg_enable_hba_reset) {
1082 goto board_mode_out;
1085 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1086 "3050 lpfc_board_mode set to %s\n", buf);
1088 init_completion(&online_compl);
1090 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1091 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1095 goto board_mode_out;
1097 wait_for_completion(&online_compl);
1098 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1099 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1100 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1101 if (phba->sli_rev == LPFC_SLI_REV4)
1104 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1105 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1106 if (phba->sli_rev == LPFC_SLI_REV4)
1109 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1110 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1111 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1112 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1113 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1114 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1115 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1123 board_mode_str = strchr(buf, '\n');
1125 *board_mode_str = '\0';
1126 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1127 "3097 Failed \"%s\", status(%d), "
1129 buf, status, phba->pport->fc_flag);
1135 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1136 * @phba: pointer to the adapter structure.
1137 * @mxri: max xri count.
1138 * @axri: available xri count.
1139 * @mrpi: max rpi count.
1140 * @arpi: available rpi count.
1141 * @mvpi: max vpi count.
1142 * @avpi: available vpi count.
1145 * If an integer pointer for an count is not null then the value for the
1146 * count is returned.
1153 lpfc_get_hba_info(struct lpfc_hba *phba,
1154 uint32_t *mxri, uint32_t *axri,
1155 uint32_t *mrpi, uint32_t *arpi,
1156 uint32_t *mvpi, uint32_t *avpi)
1158 struct lpfc_mbx_read_config *rd_config;
1159 LPFC_MBOXQ_t *pmboxq;
1165 * prevent udev from issuing mailbox commands until the port is
1168 if (phba->link_state < LPFC_LINK_DOWN ||
1169 !phba->mbox_mem_pool ||
1170 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1173 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1176 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1179 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1181 pmb = &pmboxq->u.mb;
1182 pmb->mbxCommand = MBX_READ_CONFIG;
1183 pmb->mbxOwner = OWN_HOST;
1184 pmboxq->context1 = NULL;
1186 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1187 rc = MBX_NOT_FINISHED;
1189 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1191 if (rc != MBX_SUCCESS) {
1192 if (rc != MBX_TIMEOUT)
1193 mempool_free(pmboxq, phba->mbox_mem_pool);
1197 if (phba->sli_rev == LPFC_SLI_REV4) {
1198 rd_config = &pmboxq->u.mqe.un.rd_config;
1200 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1202 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1203 phba->sli4_hba.max_cfg_param.rpi_used;
1205 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1207 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1208 phba->sli4_hba.max_cfg_param.xri_used;
1210 /* Account for differences with SLI-3. Get vpi count from
1211 * mailbox data and subtract one for max vpi value.
1213 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1214 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1216 /* Limit the max we support */
1217 if (max_vpi > LPFC_MAX_VPI)
1218 max_vpi = LPFC_MAX_VPI;
1222 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1225 *mrpi = pmb->un.varRdConfig.max_rpi;
1227 *arpi = pmb->un.varRdConfig.avail_rpi;
1229 *mxri = pmb->un.varRdConfig.max_xri;
1231 *axri = pmb->un.varRdConfig.avail_xri;
1233 *mvpi = pmb->un.varRdConfig.max_vpi;
1235 /* avail_vpi is only valid if link is up and ready */
1236 if (phba->link_state == LPFC_HBA_READY)
1237 *avpi = pmb->un.varRdConfig.avail_vpi;
1239 *avpi = pmb->un.varRdConfig.max_vpi;
1243 mempool_free(pmboxq, phba->mbox_mem_pool);
1248 * lpfc_max_rpi_show - Return maximum rpi
1249 * @dev: class device that is converted into a Scsi_host.
1250 * @attr: device attribute, not used.
1251 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1254 * Calls lpfc_get_hba_info() asking for just the mrpi count.
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_max_rpi_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, &cnt, NULL, NULL, NULL))
1271 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1272 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1276 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1277 * @dev: class device that is converted into a Scsi_host.
1278 * @attr: device attribute, not used.
1279 * @buf: containing the used rpi count in decimal or "Unknown".
1282 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1283 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1284 * to "Unknown" and the buffer length is returned, therefore the caller
1285 * must check for "Unknown" in the buffer to detect a failure.
1287 * Returns: size of formatted string.
1290 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1293 struct Scsi_Host *shost = class_to_shost(dev);
1294 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1295 struct lpfc_hba *phba = vport->phba;
1298 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1299 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1300 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1304 * lpfc_max_xri_show - Return maximum xri
1305 * @dev: class device that is converted into a Scsi_host.
1306 * @attr: device attribute, not used.
1307 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1310 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1311 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1312 * to "Unknown" and the buffer length is returned, therefore the caller
1313 * must check for "Unknown" in the buffer to detect a failure.
1315 * Returns: size of formatted string.
1318 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1321 struct Scsi_Host *shost = class_to_shost(dev);
1322 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1323 struct lpfc_hba *phba = vport->phba;
1326 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1327 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1328 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1332 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1333 * @dev: class device that is converted into a Scsi_host.
1334 * @attr: device attribute, not used.
1335 * @buf: on return contains the used xri count in decimal or "Unknown".
1338 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1339 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1340 * to "Unknown" and the buffer length is returned, therefore the caller
1341 * must check for "Unknown" in the buffer to detect a failure.
1343 * Returns: size of formatted string.
1346 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1349 struct Scsi_Host *shost = class_to_shost(dev);
1350 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1351 struct lpfc_hba *phba = vport->phba;
1354 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1355 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1356 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1360 * lpfc_max_vpi_show - Return maximum vpi
1361 * @dev: class device that is converted into a Scsi_host.
1362 * @attr: device attribute, not used.
1363 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1366 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1367 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1368 * to "Unknown" and the buffer length is returned, therefore the caller
1369 * must check for "Unknown" in the buffer to detect a failure.
1371 * Returns: size of formatted string.
1374 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1377 struct Scsi_Host *shost = class_to_shost(dev);
1378 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1379 struct lpfc_hba *phba = vport->phba;
1382 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1383 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1384 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1388 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1389 * @dev: class device that is converted into a Scsi_host.
1390 * @attr: device attribute, not used.
1391 * @buf: on return contains the used vpi count in decimal or "Unknown".
1394 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1395 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1396 * to "Unknown" and the buffer length is returned, therefore the caller
1397 * must check for "Unknown" in the buffer to detect a failure.
1399 * Returns: size of formatted string.
1402 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1405 struct Scsi_Host *shost = class_to_shost(dev);
1406 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1407 struct lpfc_hba *phba = vport->phba;
1410 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1411 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1412 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1416 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1417 * @dev: class device that is converted into a Scsi_host.
1418 * @attr: device attribute, not used.
1419 * @buf: text that must be interpreted to determine if npiv is supported.
1422 * Buffer will contain text indicating npiv is not suppoerted on the port,
1423 * the port is an NPIV physical port, or it is an npiv virtual port with
1424 * the id of the vport.
1426 * Returns: size of formatted string.
1429 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1432 struct Scsi_Host *shost = class_to_shost(dev);
1433 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1434 struct lpfc_hba *phba = vport->phba;
1436 if (!(phba->max_vpi))
1437 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1438 if (vport->port_type == LPFC_PHYSICAL_PORT)
1439 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1440 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1444 * lpfc_poll_show - Return text about poll support for the adapter
1445 * @dev: class device that is converted into a Scsi_host.
1446 * @attr: device attribute, not used.
1447 * @buf: on return contains the cfg_poll in hex.
1450 * cfg_poll should be a lpfc_polling_flags type.
1452 * Returns: size of formatted string.
1455 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1458 struct Scsi_Host *shost = class_to_shost(dev);
1459 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1460 struct lpfc_hba *phba = vport->phba;
1462 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1466 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1467 * @dev: class device that is converted into a Scsi_host.
1468 * @attr: device attribute, not used.
1469 * @buf: one or more lpfc_polling_flags values.
1473 * buf contents converted to integer and checked for a valid value.
1476 * -EINVAL if the buffer connot be converted or is out of range
1477 * length of the buf on success
1480 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1481 const char *buf, size_t count)
1483 struct Scsi_Host *shost = class_to_shost(dev);
1484 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1485 struct lpfc_hba *phba = vport->phba;
1490 if (!isdigit(buf[0]))
1493 if (sscanf(buf, "%i", &val) != 1)
1496 if ((val & 0x3) != val)
1499 if (phba->sli_rev == LPFC_SLI_REV4)
1502 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1503 "3051 lpfc_poll changed from %d to %d\n",
1504 phba->cfg_poll, val);
1506 spin_lock_irq(&phba->hbalock);
1508 old_val = phba->cfg_poll;
1510 if (val & ENABLE_FCP_RING_POLLING) {
1511 if ((val & DISABLE_FCP_RING_INT) &&
1512 !(old_val & DISABLE_FCP_RING_INT)) {
1513 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1514 spin_unlock_irq(&phba->hbalock);
1517 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1518 writel(creg_val, phba->HCregaddr);
1519 readl(phba->HCregaddr); /* flush */
1521 lpfc_poll_start_timer(phba);
1523 } else if (val != 0x0) {
1524 spin_unlock_irq(&phba->hbalock);
1528 if (!(val & DISABLE_FCP_RING_INT) &&
1529 (old_val & DISABLE_FCP_RING_INT))
1531 spin_unlock_irq(&phba->hbalock);
1532 del_timer(&phba->fcp_poll_timer);
1533 spin_lock_irq(&phba->hbalock);
1534 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1535 spin_unlock_irq(&phba->hbalock);
1538 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1539 writel(creg_val, phba->HCregaddr);
1540 readl(phba->HCregaddr); /* flush */
1543 phba->cfg_poll = val;
1545 spin_unlock_irq(&phba->hbalock);
1551 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1552 * @dev: class unused variable.
1553 * @attr: device attribute, not used.
1554 * @buf: on return contains the module description text.
1556 * Returns: size of formatted string.
1559 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1562 struct Scsi_Host *shost = class_to_shost(dev);
1563 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1564 struct lpfc_hba *phba = vport->phba;
1566 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1570 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1571 * @dev: class unused variable.
1572 * @attr: device attribute, not used.
1573 * @buf: on return contains the module description text.
1575 * Returns: size of formatted string.
1578 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1581 struct Scsi_Host *shost = class_to_shost(dev);
1582 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1583 struct lpfc_hba *phba = vport->phba;
1585 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1589 * lpfc_dss_show - Return the current state of dss and the configured state
1590 * @dev: class converted to a Scsi_host structure.
1591 * @attr: device attribute, not used.
1592 * @buf: on return contains the formatted text.
1594 * Returns: size of formatted string.
1597 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1600 struct Scsi_Host *shost = class_to_shost(dev);
1601 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1602 struct lpfc_hba *phba = vport->phba;
1604 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1605 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1606 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1611 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1612 * @dev: class converted to a Scsi_host structure.
1613 * @attr: device attribute, not used.
1614 * @buf: on return contains the formatted support level.
1617 * Returns the maximum number of virtual functions a physical function can
1618 * support, 0 will be returned if called on virtual function.
1620 * Returns: size of formatted string.
1623 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1624 struct device_attribute *attr,
1627 struct Scsi_Host *shost = class_to_shost(dev);
1628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1629 struct lpfc_hba *phba = vport->phba;
1630 uint16_t max_nr_virtfn;
1632 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1633 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1637 * lpfc_param_show - Return a cfg attribute value in decimal
1640 * Macro that given an attr e.g. hba_queue_depth expands
1641 * into a function with the name lpfc_hba_queue_depth_show.
1643 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1644 * @dev: class device that is converted into a Scsi_host.
1645 * @attr: device attribute, not used.
1646 * @buf: on return contains the attribute value in decimal.
1648 * Returns: size of formatted string.
1650 #define lpfc_param_show(attr) \
1652 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1655 struct Scsi_Host *shost = class_to_shost(dev);\
1656 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1657 struct lpfc_hba *phba = vport->phba;\
1658 return snprintf(buf, PAGE_SIZE, "%d\n",\
1663 * lpfc_param_hex_show - Return a cfg attribute value in hex
1666 * Macro that given an attr e.g. hba_queue_depth expands
1667 * into a function with the name lpfc_hba_queue_depth_show
1669 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1670 * @dev: class device that is converted into a Scsi_host.
1671 * @attr: device attribute, not used.
1672 * @buf: on return contains the attribute value in hexadecimal.
1674 * Returns: size of formatted string.
1676 #define lpfc_param_hex_show(attr) \
1678 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1681 struct Scsi_Host *shost = class_to_shost(dev);\
1682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1683 struct lpfc_hba *phba = vport->phba;\
1685 val = phba->cfg_##attr;\
1686 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1691 * lpfc_param_init - Initializes a cfg attribute
1694 * Macro that given an attr e.g. hba_queue_depth expands
1695 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1696 * takes a default argument, a minimum and maximum argument.
1698 * lpfc_##attr##_init: Initializes an attribute.
1699 * @phba: pointer the the adapter structure.
1700 * @val: integer attribute value.
1702 * Validates the min and max values then sets the adapter config field
1703 * accordingly, or uses the default if out of range and prints an error message.
1707 * -EINVAL if default used
1709 #define lpfc_param_init(attr, default, minval, maxval) \
1711 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1713 if (val >= minval && val <= maxval) {\
1714 phba->cfg_##attr = val;\
1717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1718 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1719 "allowed range is ["#minval", "#maxval"]\n", val); \
1720 phba->cfg_##attr = default;\
1725 * lpfc_param_set - Set a cfg attribute value
1728 * Macro that given an attr e.g. hba_queue_depth expands
1729 * into a function with the name lpfc_hba_queue_depth_set
1731 * lpfc_##attr##_set: Sets an attribute value.
1732 * @phba: pointer the the adapter structure.
1733 * @val: integer attribute value.
1736 * Validates the min and max values then sets the
1737 * adapter config field if in the valid range. prints error message
1738 * and does not set the parameter if invalid.
1742 * -EINVAL if val is invalid
1744 #define lpfc_param_set(attr, default, minval, maxval) \
1746 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1748 if (val >= minval && val <= maxval) {\
1749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1750 "3052 lpfc_" #attr " changed from %d to %d\n", \
1751 phba->cfg_##attr, val); \
1752 phba->cfg_##attr = val;\
1755 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1756 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1757 "allowed range is ["#minval", "#maxval"]\n", val); \
1762 * lpfc_param_store - Set a vport attribute value
1765 * Macro that given an attr e.g. hba_queue_depth expands
1766 * into a function with the name lpfc_hba_queue_depth_store.
1768 * lpfc_##attr##_store: Set an sttribute value.
1769 * @dev: class device that is converted into a Scsi_host.
1770 * @attr: device attribute, not used.
1771 * @buf: contains the attribute value in ascii.
1775 * Convert the ascii text number to an integer, then
1776 * use the lpfc_##attr##_set function to set the value.
1779 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1780 * length of buffer upon success.
1782 #define lpfc_param_store(attr) \
1784 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1785 const char *buf, size_t count) \
1787 struct Scsi_Host *shost = class_to_shost(dev);\
1788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1789 struct lpfc_hba *phba = vport->phba;\
1791 if (!isdigit(buf[0]))\
1793 if (sscanf(buf, "%i", &val) != 1)\
1795 if (lpfc_##attr##_set(phba, val) == 0) \
1796 return strlen(buf);\
1802 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1805 * Macro that given an attr e.g. hba_queue_depth expands
1806 * into a function with the name lpfc_hba_queue_depth_show
1808 * lpfc_##attr##_show: prints the attribute value in decimal.
1809 * @dev: class device that is converted into a Scsi_host.
1810 * @attr: device attribute, not used.
1811 * @buf: on return contains the attribute value in decimal.
1813 * Returns: length of formatted string.
1815 #define lpfc_vport_param_show(attr) \
1817 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1820 struct Scsi_Host *shost = class_to_shost(dev);\
1821 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1822 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1826 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1829 * Macro that given an attr e.g.
1830 * hba_queue_depth expands into a function with the name
1831 * lpfc_hba_queue_depth_show
1833 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1834 * @dev: class device that is converted into a Scsi_host.
1835 * @attr: device attribute, not used.
1836 * @buf: on return contains the attribute value in hexadecimal.
1838 * Returns: length of formatted string.
1840 #define lpfc_vport_param_hex_show(attr) \
1842 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1845 struct Scsi_Host *shost = class_to_shost(dev);\
1846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1847 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1851 * lpfc_vport_param_init - Initialize a vport cfg attribute
1854 * Macro that given an attr e.g. hba_queue_depth expands
1855 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1856 * takes a default argument, a minimum and maximum argument.
1858 * lpfc_##attr##_init: validates the min and max values then sets the
1859 * adapter config field accordingly, or uses the default if out of range
1860 * and prints an error message.
1861 * @phba: pointer the the adapter structure.
1862 * @val: integer attribute value.
1866 * -EINVAL if default used
1868 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1870 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1872 if (val >= minval && val <= maxval) {\
1873 vport->cfg_##attr = val;\
1876 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1877 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1878 "allowed range is ["#minval", "#maxval"]\n", val); \
1879 vport->cfg_##attr = default;\
1884 * lpfc_vport_param_set - Set a vport cfg attribute
1887 * Macro that given an attr e.g. hba_queue_depth expands
1888 * into a function with the name lpfc_hba_queue_depth_set
1890 * lpfc_##attr##_set: validates the min and max values then sets the
1891 * adapter config field if in the valid range. prints error message
1892 * and does not set the parameter if invalid.
1893 * @phba: pointer the the adapter structure.
1894 * @val: integer attribute value.
1898 * -EINVAL if val is invalid
1900 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1902 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1904 if (val >= minval && val <= maxval) {\
1905 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1906 "3053 lpfc_" #attr \
1907 " changed from %d (x%x) to %d (x%x)\n", \
1908 vport->cfg_##attr, vport->cfg_##attr, \
1910 vport->cfg_##attr = val;\
1913 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1914 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1915 "allowed range is ["#minval", "#maxval"]\n", val); \
1920 * lpfc_vport_param_store - Set a vport attribute
1923 * Macro that given an attr e.g. hba_queue_depth
1924 * expands into a function with the name lpfc_hba_queue_depth_store
1926 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1927 * use the lpfc_##attr##_set function to set the value.
1928 * @cdev: class device that is converted into a Scsi_host.
1929 * @buf: contains the attribute value in decimal.
1933 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1934 * length of buffer upon success.
1936 #define lpfc_vport_param_store(attr) \
1938 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1939 const char *buf, size_t count) \
1941 struct Scsi_Host *shost = class_to_shost(dev);\
1942 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1944 if (!isdigit(buf[0]))\
1946 if (sscanf(buf, "%i", &val) != 1)\
1948 if (lpfc_##attr##_set(vport, val) == 0) \
1949 return strlen(buf);\
1955 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1956 static uint lpfc_##name = defval;\
1957 module_param(lpfc_##name, uint, S_IRUGO);\
1958 MODULE_PARM_DESC(lpfc_##name, desc);\
1959 lpfc_param_init(name, defval, minval, maxval)
1961 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1962 static uint lpfc_##name = defval;\
1963 module_param(lpfc_##name, uint, S_IRUGO);\
1964 MODULE_PARM_DESC(lpfc_##name, desc);\
1965 lpfc_param_show(name)\
1966 lpfc_param_init(name, defval, minval, maxval)\
1967 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1969 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1970 static uint lpfc_##name = defval;\
1971 module_param(lpfc_##name, uint, S_IRUGO);\
1972 MODULE_PARM_DESC(lpfc_##name, desc);\
1973 lpfc_param_show(name)\
1974 lpfc_param_init(name, defval, minval, maxval)\
1975 lpfc_param_set(name, defval, minval, maxval)\
1976 lpfc_param_store(name)\
1977 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1978 lpfc_##name##_show, lpfc_##name##_store)
1980 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1981 static uint lpfc_##name = defval;\
1982 module_param(lpfc_##name, uint, S_IRUGO);\
1983 MODULE_PARM_DESC(lpfc_##name, desc);\
1984 lpfc_param_hex_show(name)\
1985 lpfc_param_init(name, defval, minval, maxval)\
1986 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1988 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1989 static uint lpfc_##name = defval;\
1990 module_param(lpfc_##name, uint, S_IRUGO);\
1991 MODULE_PARM_DESC(lpfc_##name, desc);\
1992 lpfc_param_hex_show(name)\
1993 lpfc_param_init(name, defval, minval, maxval)\
1994 lpfc_param_set(name, defval, minval, maxval)\
1995 lpfc_param_store(name)\
1996 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1997 lpfc_##name##_show, lpfc_##name##_store)
1999 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
2000 static uint lpfc_##name = defval;\
2001 module_param(lpfc_##name, uint, S_IRUGO);\
2002 MODULE_PARM_DESC(lpfc_##name, desc);\
2003 lpfc_vport_param_init(name, defval, minval, maxval)
2005 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
2006 static uint lpfc_##name = defval;\
2007 module_param(lpfc_##name, uint, S_IRUGO);\
2008 MODULE_PARM_DESC(lpfc_##name, desc);\
2009 lpfc_vport_param_show(name)\
2010 lpfc_vport_param_init(name, defval, minval, maxval)\
2011 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
2013 #define LPFC_VPORT_ULL_ATTR_R(name, defval, minval, maxval, desc) \
2014 static uint64_t lpfc_##name = defval;\
2015 module_param(lpfc_##name, ullong, S_IRUGO);\
2016 MODULE_PARM_DESC(lpfc_##name, desc);\
2017 lpfc_vport_param_show(name)\
2018 lpfc_vport_param_init(name, defval, minval, maxval)\
2019 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
2021 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
2022 static uint lpfc_##name = defval;\
2023 module_param(lpfc_##name, uint, S_IRUGO);\
2024 MODULE_PARM_DESC(lpfc_##name, desc);\
2025 lpfc_vport_param_show(name)\
2026 lpfc_vport_param_init(name, defval, minval, maxval)\
2027 lpfc_vport_param_set(name, defval, minval, maxval)\
2028 lpfc_vport_param_store(name)\
2029 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2030 lpfc_##name##_show, lpfc_##name##_store)
2032 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
2033 static uint lpfc_##name = defval;\
2034 module_param(lpfc_##name, uint, S_IRUGO);\
2035 MODULE_PARM_DESC(lpfc_##name, desc);\
2036 lpfc_vport_param_hex_show(name)\
2037 lpfc_vport_param_init(name, defval, minval, maxval)\
2038 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
2040 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
2041 static uint lpfc_##name = defval;\
2042 module_param(lpfc_##name, uint, S_IRUGO);\
2043 MODULE_PARM_DESC(lpfc_##name, desc);\
2044 lpfc_vport_param_hex_show(name)\
2045 lpfc_vport_param_init(name, defval, minval, maxval)\
2046 lpfc_vport_param_set(name, defval, minval, maxval)\
2047 lpfc_vport_param_store(name)\
2048 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2049 lpfc_##name##_show, lpfc_##name##_store)
2051 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2052 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2053 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2054 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2055 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2056 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2057 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2058 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2059 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2060 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2061 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2062 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2063 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2064 lpfc_link_state_store);
2065 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2066 lpfc_option_rom_version_show, NULL);
2067 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2068 lpfc_num_discovered_ports_show, NULL);
2069 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2070 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2071 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2072 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2073 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2074 lpfc_board_mode_show, lpfc_board_mode_store);
2075 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2076 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2077 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2078 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2079 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2080 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2081 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2082 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2083 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2084 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2085 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2086 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2087 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2088 lpfc_sriov_hw_max_virtfn_show, NULL);
2089 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2090 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2093 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2096 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2098 * @cnt: Length of string.
2099 * @wwn: Array to receive converted wwn value.
2102 * -EINVAL if the buffer does not contain a valid wwn
2106 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2110 /* Count may include a LF at end of string */
2111 if (buf[cnt-1] == '\n')
2114 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2115 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2118 memset(wwn, 0, WWN_SZ);
2120 /* Validate and store the new name */
2121 for (i = 0, j = 0; i < 16; i++) {
2122 if ((*buf >= 'a') && (*buf <= 'f'))
2123 j = ((j << 4) | ((*buf++ - 'a') + 10));
2124 else if ((*buf >= 'A') && (*buf <= 'F'))
2125 j = ((j << 4) | ((*buf++ - 'A') + 10));
2126 else if ((*buf >= '0') && (*buf <= '9'))
2127 j = ((j << 4) | (*buf++ - '0'));
2131 wwn[i/2] = j & 0xff;
2138 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2139 * @dev: class device that is converted into a Scsi_host.
2140 * @attr: device attribute, not used.
2141 * @buf: containing the string lpfc_soft_wwn_key.
2142 * @count: must be size of lpfc_soft_wwn_key.
2145 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2146 * length of buf indicates success
2149 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2150 const char *buf, size_t count)
2152 struct Scsi_Host *shost = class_to_shost(dev);
2153 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2154 struct lpfc_hba *phba = vport->phba;
2155 unsigned int cnt = count;
2158 * We're doing a simple sanity check for soft_wwpn setting.
2159 * We require that the user write a specific key to enable
2160 * the soft_wwpn attribute to be settable. Once the attribute
2161 * is written, the enable key resets. If further updates are
2162 * desired, the key must be written again to re-enable the
2165 * The "key" is not secret - it is a hardcoded string shown
2166 * here. The intent is to protect against the random user or
2167 * application that is just writing attributes.
2170 /* count may include a LF at end of string */
2171 if (buf[cnt-1] == '\n')
2174 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2175 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2178 phba->soft_wwn_enable = 1;
2181 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2182 lpfc_soft_wwn_enable_store);
2185 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2186 * @dev: class device that is converted into a Scsi_host.
2187 * @attr: device attribute, not used.
2188 * @buf: on return contains the wwpn in hexadecimal.
2190 * Returns: size of formatted string.
2193 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2196 struct Scsi_Host *shost = class_to_shost(dev);
2197 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2198 struct lpfc_hba *phba = vport->phba;
2200 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2201 (unsigned long long)phba->cfg_soft_wwpn);
2205 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2206 * @dev class device that is converted into a Scsi_host.
2207 * @attr: device attribute, not used.
2208 * @buf: contains the wwpn in hexadecimal.
2209 * @count: number of wwpn bytes in buf
2212 * -EACCES hba reset not enabled, adapter over temp
2213 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2214 * -EIO error taking adapter offline or online
2215 * value of count on success
2218 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2219 const char *buf, size_t count)
2221 struct Scsi_Host *shost = class_to_shost(dev);
2222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2223 struct lpfc_hba *phba = vport->phba;
2224 struct completion online_compl;
2225 int stat1 = 0, stat2 = 0;
2226 unsigned int cnt = count;
2230 if (!phba->cfg_enable_hba_reset)
2232 spin_lock_irq(&phba->hbalock);
2233 if (phba->over_temp_state == HBA_OVER_TEMP) {
2234 spin_unlock_irq(&phba->hbalock);
2237 spin_unlock_irq(&phba->hbalock);
2238 /* count may include a LF at end of string */
2239 if (buf[cnt-1] == '\n')
2242 if (!phba->soft_wwn_enable)
2245 /* lock setting wwpn, wwnn down */
2246 phba->soft_wwn_enable = 0;
2248 rc = lpfc_wwn_set(buf, cnt, wwpn);
2250 /* not able to set wwpn, unlock it */
2251 phba->soft_wwn_enable = 1;
2255 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2256 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2257 if (phba->cfg_soft_wwnn)
2258 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2260 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2261 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2263 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2265 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2266 "0463 lpfc_soft_wwpn attribute set failed to "
2267 "reinit adapter - %d\n", stat1);
2268 init_completion(&online_compl);
2269 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2274 wait_for_completion(&online_compl);
2276 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2277 "0464 lpfc_soft_wwpn attribute set failed to "
2278 "reinit adapter - %d\n", stat2);
2279 return (stat1 || stat2) ? -EIO : count;
2281 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2282 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2285 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2286 * @dev: class device that is converted into a Scsi_host.
2287 * @attr: device attribute, not used.
2288 * @buf: on return contains the wwnn in hexadecimal.
2290 * Returns: size of formatted string.
2293 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2296 struct Scsi_Host *shost = class_to_shost(dev);
2297 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2298 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2299 (unsigned long long)phba->cfg_soft_wwnn);
2303 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2304 * @cdev: class device that is converted into a Scsi_host.
2305 * @buf: contains the ww node name in hexadecimal.
2306 * @count: number of wwnn bytes in buf.
2309 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2310 * value of count on success
2313 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2314 const char *buf, size_t count)
2316 struct Scsi_Host *shost = class_to_shost(dev);
2317 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2318 unsigned int cnt = count;
2322 /* count may include a LF at end of string */
2323 if (buf[cnt-1] == '\n')
2326 if (!phba->soft_wwn_enable)
2329 rc = lpfc_wwn_set(buf, cnt, wwnn);
2331 /* Allow wwnn to be set many times, as long as the enable
2332 * is set. However, once the wwpn is set, everything locks.
2337 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2339 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2340 "lpfc%d: soft_wwnn set. Value will take effect upon "
2341 "setting of the soft_wwpn\n", phba->brd_no);
2345 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2346 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2349 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2350 * Optimized Access Storage (OAS) operations.
2351 * @dev: class device that is converted into a Scsi_host.
2352 * @attr: device attribute, not used.
2353 * @buf: buffer for passing information.
2359 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2362 struct Scsi_Host *shost = class_to_shost(dev);
2363 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2365 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2366 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2370 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2371 * Optimized Access Storage (OAS) operations.
2372 * @dev: class device that is converted into a Scsi_host.
2373 * @attr: device attribute, not used.
2374 * @buf: buffer for passing information.
2375 * @count: Size of the data buffer.
2378 * -EINVAL count is invalid, invalid wwpn byte invalid
2379 * -EPERM oas is not supported by hba
2380 * value of count on success
2383 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2384 const char *buf, size_t count)
2386 struct Scsi_Host *shost = class_to_shost(dev);
2387 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2388 unsigned int cnt = count;
2389 uint8_t wwpn[WWN_SZ];
2395 /* count may include a LF at end of string */
2396 if (buf[cnt-1] == '\n')
2399 rc = lpfc_wwn_set(buf, cnt, wwpn);
2403 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2404 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2405 if (wwn_to_u64(wwpn) == 0)
2406 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2408 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2409 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2410 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2413 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2414 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2417 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2418 * for Optimized Access Storage (OAS) operations.
2419 * @dev: class device that is converted into a Scsi_host.
2420 * @attr: device attribute, not used.
2421 * @buf: buffer for passing information.
2424 * value of count on success
2427 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2430 struct Scsi_Host *shost = class_to_shost(dev);
2431 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2433 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2434 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2438 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2439 * for Optimized Access Storage (OAS) operations.
2440 * @dev: class device that is converted into a Scsi_host.
2441 * @attr: device attribute, not used.
2442 * @buf: buffer for passing information.
2443 * @count: Size of the data buffer.
2446 * -EINVAL count is invalid, invalid wwpn byte invalid
2447 * -EPERM oas is not supported by hba
2448 * value of count on success
2451 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2452 const char *buf, size_t count)
2454 struct Scsi_Host *shost = class_to_shost(dev);
2455 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2456 unsigned int cnt = count;
2457 uint8_t wwpn[WWN_SZ];
2463 /* count may include a LF at end of string */
2464 if (buf[cnt-1] == '\n')
2467 rc = lpfc_wwn_set(buf, cnt, wwpn);
2471 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2472 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2473 if (wwn_to_u64(wwpn) == 0)
2474 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2476 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2477 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2478 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2481 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2482 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2485 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2486 * of whether luns will be enabled or disabled
2487 * for Optimized Access Storage (OAS) operations.
2488 * @dev: class device that is converted into a Scsi_host.
2489 * @attr: device attribute, not used.
2490 * @buf: buffer for passing information.
2493 * size of formatted string.
2496 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2499 struct Scsi_Host *shost = class_to_shost(dev);
2500 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2502 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2506 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2507 * of whether luns will be enabled or disabled
2508 * for Optimized Access Storage (OAS) operations.
2509 * @dev: class device that is converted into a Scsi_host.
2510 * @attr: device attribute, not used.
2511 * @buf: buffer for passing information.
2512 * @count: Size of the data buffer.
2515 * -EINVAL count is invalid, invalid wwpn byte invalid
2516 * -EPERM oas is not supported by hba
2517 * value of count on success
2520 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2521 const char *buf, size_t count)
2523 struct Scsi_Host *shost = class_to_shost(dev);
2524 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2530 if (!isdigit(buf[0]))
2533 if (sscanf(buf, "%i", &val) != 1)
2536 if ((val != 0) && (val != 1))
2539 phba->cfg_oas_lun_state = val;
2543 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2544 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2547 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2548 * Storage (OAS) lun returned by the
2549 * lpfc_oas_lun_show function.
2550 * @dev: class device that is converted into a Scsi_host.
2551 * @attr: device attribute, not used.
2552 * @buf: buffer for passing information.
2555 * size of formatted string.
2558 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2561 struct Scsi_Host *shost = class_to_shost(dev);
2562 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2564 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2567 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2569 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2570 lpfc_oas_lun_status_show, NULL);
2574 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2576 * @phba: lpfc_hba pointer.
2577 * @ndlp: pointer to fcp target node.
2578 * @lun: the fc lun for setting oas state.
2579 * @oas_state: the oas state to be set to the lun.
2583 * -EPERM OAS is not enabled or not supported by this port.
2587 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2588 uint8_t tgt_wwpn[], uint64_t lun, uint32_t oas_state)
2597 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2598 (struct lpfc_name *)tgt_wwpn, lun))
2601 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2602 (struct lpfc_name *)tgt_wwpn, lun);
2609 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2610 * Access Storage (OAS) operations.
2611 * @phba: lpfc_hba pointer.
2612 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2613 * @tgt_wwpn: wwpn of the target associated with the returned lun
2614 * @lun_status: status of the lun returned lun
2616 * Returns the first or next lun enabled for OAS operations for the vport/target
2617 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2618 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2621 * lun that is OAS enabled for the vport/target
2622 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2625 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2626 uint8_t tgt_wwpn[], uint32_t *lun_status)
2630 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2631 return NOT_OAS_ENABLED_LUN;
2632 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2633 phba->sli4_hba.oas_next_vpt_wwpn,
2634 (struct lpfc_name *)
2635 phba->sli4_hba.oas_next_tgt_wwpn,
2636 &phba->sli4_hba.oas_next_lun,
2637 (struct lpfc_name *)vpt_wwpn,
2638 (struct lpfc_name *)tgt_wwpn,
2639 &found_lun, lun_status))
2642 return NOT_OAS_ENABLED_LUN;
2646 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2647 * @phba: lpfc_hba pointer.
2648 * @vpt_wwpn: vport wwpn by reference.
2649 * @tgt_wwpn: target wwpn by reference.
2650 * @lun: the fc lun for setting oas state.
2651 * @oas_state: the oas state to be set to the oas_lun.
2653 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2654 * a lun for OAS operations.
2658 * -ENOMEM: failed to enable an lun for OAS operations
2659 * -EPERM: OAS is not enabled
2662 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2663 uint8_t tgt_wwpn[], uint64_t lun,
2669 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2675 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2676 * @dev: class device that is converted into a Scsi_host.
2677 * @attr: device attribute, not used.
2678 * @buf: buffer for passing information.
2680 * This routine returns a lun enabled for OAS each time the function
2684 * SUCCESS: size of formatted string.
2685 * -EFAULT: target or vport wwpn was not set properly.
2686 * -EPERM: oas is not enabled.
2689 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2692 struct Scsi_Host *shost = class_to_shost(dev);
2693 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2701 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2702 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2705 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2706 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2709 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2710 phba->cfg_oas_tgt_wwpn,
2711 &phba->cfg_oas_lun_status);
2712 if (oas_lun != NOT_OAS_ENABLED_LUN)
2713 phba->cfg_oas_flags |= OAS_LUN_VALID;
2715 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2721 * lpfc_oas_lun_store - Sets the OAS state for lun
2722 * @dev: class device that is converted into a Scsi_host.
2723 * @attr: device attribute, not used.
2724 * @buf: buffer for passing information.
2726 * This function sets the OAS state for lun. Before this function is called,
2727 * the vport wwpn, target wwpn, and oas state need to be set.
2730 * SUCCESS: size of formatted string.
2731 * -EFAULT: target or vport wwpn was not set properly.
2732 * -EPERM: oas is not enabled.
2733 * size of formatted string.
2736 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2737 const char *buf, size_t count)
2739 struct Scsi_Host *shost = class_to_shost(dev);
2740 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2747 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2750 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2753 if (!isdigit(buf[0]))
2756 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2759 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2760 "3372 Try to set vport 0x%llx target 0x%llx lun:%lld "
2761 "with oas set to %d\n",
2762 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2763 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
2764 phba->cfg_oas_lun_state);
2766 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
2767 phba->cfg_oas_tgt_wwpn, scsi_lun,
2768 phba->cfg_oas_lun_state);
2775 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2776 lpfc_oas_lun_show, lpfc_oas_lun_store);
2778 static int lpfc_poll = 0;
2779 module_param(lpfc_poll, int, S_IRUGO);
2780 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2782 " 1 - poll with interrupts enabled"
2783 " 3 - poll and disable FCP ring interrupts");
2785 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2786 lpfc_poll_show, lpfc_poll_store);
2788 int lpfc_sli_mode = 0;
2789 module_param(lpfc_sli_mode, int, S_IRUGO);
2790 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2791 " 0 - auto (SLI-3 if supported),"
2792 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2793 " 3 - select SLI-3");
2795 int lpfc_enable_npiv = 1;
2796 module_param(lpfc_enable_npiv, int, S_IRUGO);
2797 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2798 lpfc_param_show(enable_npiv);
2799 lpfc_param_init(enable_npiv, 1, 0, 1);
2800 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2802 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2803 "FCF Fast failover=1 Priority failover=2");
2805 int lpfc_enable_rrq = 2;
2806 module_param(lpfc_enable_rrq, int, S_IRUGO);
2807 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2808 lpfc_param_show(enable_rrq);
2810 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2811 # 0x0 = disabled, XRI/OXID use not tracked.
2812 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2813 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2815 lpfc_param_init(enable_rrq, 2, 0, 2);
2816 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2819 # lpfc_suppress_link_up: Bring link up at initialization
2820 # 0x0 = bring link up (issue MBX_INIT_LINK)
2821 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2822 # 0x2 = never bring up link
2823 # Default value is 0.
2825 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2826 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2827 "Suppress Link Up at initialization");
2829 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2837 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2839 struct Scsi_Host *shost = class_to_shost(dev);
2840 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2842 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2845 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2846 lpfc_iocb_hw_show, NULL);
2848 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2850 struct Scsi_Host *shost = class_to_shost(dev);
2851 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2853 return snprintf(buf, PAGE_SIZE, "%d\n",
2854 phba->sli.ring[LPFC_ELS_RING].txq_max);
2857 static DEVICE_ATTR(txq_hw, S_IRUGO,
2858 lpfc_txq_hw_show, NULL);
2860 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2863 struct Scsi_Host *shost = class_to_shost(dev);
2864 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2866 return snprintf(buf, PAGE_SIZE, "%d\n",
2867 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2870 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2871 lpfc_txcmplq_hw_show, NULL);
2873 int lpfc_iocb_cnt = 2;
2874 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2875 MODULE_PARM_DESC(lpfc_iocb_cnt,
2876 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2877 lpfc_param_show(iocb_cnt);
2878 lpfc_param_init(iocb_cnt, 2, 1, 5);
2879 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2880 lpfc_iocb_cnt_show, NULL);
2883 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2884 # until the timer expires. Value range is [0,255]. Default value is 30.
2886 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2887 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2888 module_param(lpfc_nodev_tmo, int, 0);
2889 MODULE_PARM_DESC(lpfc_nodev_tmo,
2890 "Seconds driver will hold I/O waiting "
2891 "for a device to come back");
2894 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2895 * @dev: class converted to a Scsi_host structure.
2896 * @attr: device attribute, not used.
2897 * @buf: on return contains the dev loss timeout in decimal.
2899 * Returns: size of formatted string.
2902 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2905 struct Scsi_Host *shost = class_to_shost(dev);
2906 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2908 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2912 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2913 * @vport: lpfc vport structure pointer.
2914 * @val: contains the nodev timeout value.
2917 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2918 * a kernel error message is printed and zero is returned.
2919 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2920 * Otherwise nodev tmo is set to the default value.
2923 * zero if already set or if val is in range
2924 * -EINVAL val out of range
2927 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2929 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2930 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2931 if (val != LPFC_DEF_DEVLOSS_TMO)
2932 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2933 "0407 Ignoring nodev_tmo module "
2934 "parameter because devloss_tmo is "
2939 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2940 vport->cfg_nodev_tmo = val;
2941 vport->cfg_devloss_tmo = val;
2944 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2945 "0400 lpfc_nodev_tmo attribute cannot be set to"
2946 " %d, allowed range is [%d, %d]\n",
2947 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2948 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2953 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2954 * @vport: lpfc vport structure pointer.
2957 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2960 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2962 struct Scsi_Host *shost;
2963 struct lpfc_nodelist *ndlp;
2965 shost = lpfc_shost_from_vport(vport);
2966 spin_lock_irq(shost->host_lock);
2967 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2968 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2969 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2970 spin_unlock_irq(shost->host_lock);
2974 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2975 * @vport: lpfc vport structure pointer.
2976 * @val: contains the tmo value.
2979 * If the devloss tmo is already set or the vport dev loss tmo has changed
2980 * then a kernel error message is printed and zero is returned.
2981 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2982 * Otherwise nodev tmo is set to the default value.
2985 * zero if already set or if val is in range
2986 * -EINVAL val out of range
2989 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2991 if (vport->dev_loss_tmo_changed ||
2992 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2993 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2994 "0401 Ignoring change to nodev_tmo "
2995 "because devloss_tmo is set.\n");
2998 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2999 vport->cfg_nodev_tmo = val;
3000 vport->cfg_devloss_tmo = val;
3002 * For compat: set the fc_host dev loss so new rports
3003 * will get the value.
3005 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3006 lpfc_update_rport_devloss_tmo(vport);
3009 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3010 "0403 lpfc_nodev_tmo attribute cannot be set to"
3011 "%d, allowed range is [%d, %d]\n",
3012 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3016 lpfc_vport_param_store(nodev_tmo)
3018 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3019 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3022 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3023 # disappear until the timer expires. Value range is [0,255]. Default
3026 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3027 MODULE_PARM_DESC(lpfc_devloss_tmo,
3028 "Seconds driver will hold I/O waiting "
3029 "for a device to come back");
3030 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3031 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3032 lpfc_vport_param_show(devloss_tmo)
3035 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3036 * @vport: lpfc vport structure pointer.
3037 * @val: contains the tmo value.
3040 * If val is in a valid range then set the vport nodev tmo,
3041 * devloss tmo, also set the vport dev loss tmo changed flag.
3042 * Else a kernel error message is printed.
3045 * zero if val is in range
3046 * -EINVAL val out of range
3049 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3051 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3052 vport->cfg_nodev_tmo = val;
3053 vport->cfg_devloss_tmo = val;
3054 vport->dev_loss_tmo_changed = 1;
3055 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3056 lpfc_update_rport_devloss_tmo(vport);
3060 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3061 "0404 lpfc_devloss_tmo attribute cannot be set to"
3062 " %d, allowed range is [%d, %d]\n",
3063 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3067 lpfc_vport_param_store(devloss_tmo)
3068 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3069 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3072 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3073 # deluged with LOTS of information.
3074 # You can set a bit mask to record specific types of verbose messages:
3075 # See lpfc_logmsh.h for definitions.
3077 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3078 "Verbose logging bit-mask");
3081 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3082 # objects that have been registered with the nameserver after login.
3084 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3085 "Deregister nameserver objects before LOGO");
3088 # lun_queue_depth: This parameter is used to limit the number of outstanding
3089 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3090 # If this parameter value is greater than 1/8th the maximum number of exchanges
3091 # supported by the HBA port, then the lun queue depth will be reduced to
3092 # 1/8th the maximum number of exchanges.
3094 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3095 "Max number of FCP commands we can queue to a specific LUN");
3098 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3099 # commands per target port. Value range is [10,65535]. Default value is 65535.
3101 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3102 "Max number of FCP commands we can queue to a specific target port");
3105 # hba_queue_depth: This parameter is used to limit the number of outstanding
3106 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3107 # value is greater than the maximum number of exchanges supported by the HBA,
3108 # then maximum number of exchanges supported by the HBA is used to determine
3109 # the hba_queue_depth.
3111 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3112 "Max number of FCP commands we can queue to a lpfc HBA");
3115 # peer_port_login: This parameter allows/prevents logins
3116 # between peer ports hosted on the same physical port.
3117 # When this parameter is set 0 peer ports of same physical port
3118 # are not allowed to login to each other.
3119 # When this parameter is set 1 peer ports of same physical port
3120 # are allowed to login to each other.
3121 # Default value of this parameter is 0.
3123 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3124 "Allow peer ports on the same physical port to login to each "
3128 # restrict_login: This parameter allows/prevents logins
3129 # between Virtual Ports and remote initiators.
3130 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3131 # other initiators and will attempt to PLOGI all remote ports.
3132 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3133 # remote ports and will not attempt to PLOGI to other initiators.
3134 # This parameter does not restrict to the physical port.
3135 # This parameter does not restrict logins to Fabric resident remote ports.
3136 # Default value of this parameter is 1.
3138 static int lpfc_restrict_login = 1;
3139 module_param(lpfc_restrict_login, int, S_IRUGO);
3140 MODULE_PARM_DESC(lpfc_restrict_login,
3141 "Restrict virtual ports login to remote initiators.");
3142 lpfc_vport_param_show(restrict_login);
3145 * lpfc_restrict_login_init - Set the vport restrict login flag
3146 * @vport: lpfc vport structure pointer.
3147 * @val: contains the restrict login value.
3150 * If val is not in a valid range then log a kernel error message and set
3151 * the vport restrict login to one.
3152 * If the port type is physical clear the restrict login flag and return.
3153 * Else set the restrict login flag to val.
3156 * zero if val is in range
3157 * -EINVAL val out of range
3160 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3162 if (val < 0 || val > 1) {
3163 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3164 "0422 lpfc_restrict_login attribute cannot "
3165 "be set to %d, allowed range is [0, 1]\n",
3167 vport->cfg_restrict_login = 1;
3170 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3171 vport->cfg_restrict_login = 0;
3174 vport->cfg_restrict_login = val;
3179 * lpfc_restrict_login_set - Set the vport restrict login flag
3180 * @vport: lpfc vport structure pointer.
3181 * @val: contains the restrict login value.
3184 * If val is not in a valid range then log a kernel error message and set
3185 * the vport restrict login to one.
3186 * If the port type is physical and the val is not zero log a kernel
3187 * error message, clear the restrict login flag and return zero.
3188 * Else set the restrict login flag to val.
3191 * zero if val is in range
3192 * -EINVAL val out of range
3195 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3197 if (val < 0 || val > 1) {
3198 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3199 "0425 lpfc_restrict_login attribute cannot "
3200 "be set to %d, allowed range is [0, 1]\n",
3202 vport->cfg_restrict_login = 1;
3205 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3206 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3207 "0468 lpfc_restrict_login must be 0 for "
3208 "Physical ports.\n");
3209 vport->cfg_restrict_login = 0;
3212 vport->cfg_restrict_login = val;
3215 lpfc_vport_param_store(restrict_login);
3216 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3217 lpfc_restrict_login_show, lpfc_restrict_login_store);
3220 # Some disk devices have a "select ID" or "select Target" capability.
3221 # From a protocol standpoint "select ID" usually means select the
3222 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3223 # annex" which contains a table that maps a "select ID" (a number
3224 # between 0 and 7F) to an ALPA. By default, for compatibility with
3225 # older drivers, the lpfc driver scans this table from low ALPA to high
3228 # Turning on the scan-down variable (on = 1, off = 0) will
3229 # cause the lpfc driver to use an inverted table, effectively
3230 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3232 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3233 # and will not work across a fabric. Also this parameter will take
3234 # effect only in the case when ALPA map is not available.)
3236 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3237 "Start scanning for devices from highest ALPA to lowest");
3240 # lpfc_topology: link topology for init link
3241 # 0x0 = attempt loop mode then point-to-point
3242 # 0x01 = internal loopback mode
3243 # 0x02 = attempt point-to-point mode only
3244 # 0x04 = attempt loop mode only
3245 # 0x06 = attempt point-to-point mode then loop
3246 # Set point-to-point mode if you want to run as an N_Port.
3247 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3248 # Default value is 0.
3252 * lpfc_topology_set - Set the adapters topology field
3253 * @phba: lpfc_hba pointer.
3254 * @val: topology value.
3257 * If val is in a valid range then set the adapter's topology field and
3258 * issue a lip; if the lip fails reset the topology to the old value.
3260 * If the value is not in range log a kernel error message and return an error.
3263 * zero if val is in range and lip okay
3264 * non-zero return value from lpfc_issue_lip()
3265 * -EINVAL val out of range
3268 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3269 const char *buf, size_t count)
3271 struct Scsi_Host *shost = class_to_shost(dev);
3272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3273 struct lpfc_hba *phba = vport->phba;
3276 const char *val_buf = buf;
3280 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3282 val_buf = &buf[strlen("nolip ")];
3285 if (!isdigit(val_buf[0]))
3287 if (sscanf(val_buf, "%i", &val) != 1)
3290 if (val >= 0 && val <= 6) {
3291 prev_val = phba->cfg_topology;
3292 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3294 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3295 "3113 Loop mode not supported at speed %d\n",
3299 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3301 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3302 "3114 Loop mode not supported\n");
3305 phba->cfg_topology = val;
3309 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3310 "3054 lpfc_topology changed from %d to %d\n",
3312 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3313 phba->fc_topology_changed = 1;
3314 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3316 phba->cfg_topology = prev_val;
3321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3322 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3323 "allowed range is [0, 6]\n",
3327 static int lpfc_topology = 0;
3328 module_param(lpfc_topology, int, S_IRUGO);
3329 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
3330 lpfc_param_show(topology)
3331 lpfc_param_init(topology, 0, 0, 6)
3332 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3333 lpfc_topology_show, lpfc_topology_store);
3336 * lpfc_static_vport_show: Read callback function for
3337 * lpfc_static_vport sysfs file.
3338 * @dev: Pointer to class device object.
3339 * @attr: device attribute structure.
3340 * @buf: Data buffer.
3342 * This function is the read call back function for
3343 * lpfc_static_vport sysfs file. The lpfc_static_vport
3344 * sysfs file report the mageability of the vport.
3347 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3350 struct Scsi_Host *shost = class_to_shost(dev);
3351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3352 if (vport->vport_flag & STATIC_VPORT)
3353 sprintf(buf, "1\n");
3355 sprintf(buf, "0\n");
3361 * Sysfs attribute to control the statistical data collection.
3363 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3364 lpfc_static_vport_show, NULL);
3367 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3368 * @dev: Pointer to class device.
3369 * @buf: Data buffer.
3370 * @count: Size of the data buffer.
3372 * This function get called when an user write to the lpfc_stat_data_ctrl
3373 * sysfs file. This function parse the command written to the sysfs file
3374 * and take appropriate action. These commands are used for controlling
3375 * driver statistical data collection.
3376 * Following are the command this function handles.
3378 * setbucket <bucket_type> <base> <step>
3379 * = Set the latency buckets.
3380 * destroybucket = destroy all the buckets.
3381 * start = start data collection
3382 * stop = stop data collection
3383 * reset = reset the collected data
3386 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3387 const char *buf, size_t count)
3389 struct Scsi_Host *shost = class_to_shost(dev);
3390 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3391 struct lpfc_hba *phba = vport->phba;
3392 #define LPFC_MAX_DATA_CTRL_LEN 1024
3393 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3395 char *str_ptr, *token;
3396 struct lpfc_vport **vports;
3397 struct Scsi_Host *v_shost;
3398 char *bucket_type_str, *base_str, *step_str;
3399 unsigned long base, step, bucket_type;
3401 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3402 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3405 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3406 str_ptr = &bucket_data[0];
3407 /* Ignore this token - this is command token */
3408 token = strsep(&str_ptr, "\t ");
3412 bucket_type_str = strsep(&str_ptr, "\t ");
3413 if (!bucket_type_str)
3416 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3417 bucket_type = LPFC_LINEAR_BUCKET;
3418 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3419 bucket_type = LPFC_POWER2_BUCKET;
3423 base_str = strsep(&str_ptr, "\t ");
3426 base = simple_strtoul(base_str, NULL, 0);
3428 step_str = strsep(&str_ptr, "\t ");
3431 step = simple_strtoul(step_str, NULL, 0);
3435 /* Block the data collection for every vport */
3436 vports = lpfc_create_vport_work_array(phba);
3440 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3441 v_shost = lpfc_shost_from_vport(vports[i]);
3442 spin_lock_irq(v_shost->host_lock);
3443 /* Block and reset data collection */
3444 vports[i]->stat_data_blocked = 1;
3445 if (vports[i]->stat_data_enabled)
3446 lpfc_vport_reset_stat_data(vports[i]);
3447 spin_unlock_irq(v_shost->host_lock);
3450 /* Set the bucket attributes */
3451 phba->bucket_type = bucket_type;
3452 phba->bucket_base = base;
3453 phba->bucket_step = step;
3455 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3456 v_shost = lpfc_shost_from_vport(vports[i]);
3458 /* Unblock data collection */
3459 spin_lock_irq(v_shost->host_lock);
3460 vports[i]->stat_data_blocked = 0;
3461 spin_unlock_irq(v_shost->host_lock);
3463 lpfc_destroy_vport_work_array(phba, vports);
3467 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3468 vports = lpfc_create_vport_work_array(phba);
3472 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3473 v_shost = lpfc_shost_from_vport(vports[i]);
3474 spin_lock_irq(shost->host_lock);
3475 vports[i]->stat_data_blocked = 1;
3476 lpfc_free_bucket(vport);
3477 vport->stat_data_enabled = 0;
3478 vports[i]->stat_data_blocked = 0;
3479 spin_unlock_irq(shost->host_lock);
3481 lpfc_destroy_vport_work_array(phba, vports);
3482 phba->bucket_type = LPFC_NO_BUCKET;
3483 phba->bucket_base = 0;
3484 phba->bucket_step = 0;
3488 if (!strncmp(buf, "start", strlen("start"))) {
3489 /* If no buckets configured return error */
3490 if (phba->bucket_type == LPFC_NO_BUCKET)
3492 spin_lock_irq(shost->host_lock);
3493 if (vport->stat_data_enabled) {
3494 spin_unlock_irq(shost->host_lock);
3497 lpfc_alloc_bucket(vport);
3498 vport->stat_data_enabled = 1;
3499 spin_unlock_irq(shost->host_lock);
3503 if (!strncmp(buf, "stop", strlen("stop"))) {
3504 spin_lock_irq(shost->host_lock);
3505 if (vport->stat_data_enabled == 0) {
3506 spin_unlock_irq(shost->host_lock);
3509 lpfc_free_bucket(vport);
3510 vport->stat_data_enabled = 0;
3511 spin_unlock_irq(shost->host_lock);
3515 if (!strncmp(buf, "reset", strlen("reset"))) {
3516 if ((phba->bucket_type == LPFC_NO_BUCKET)
3517 || !vport->stat_data_enabled)
3519 spin_lock_irq(shost->host_lock);
3520 vport->stat_data_blocked = 1;
3521 lpfc_vport_reset_stat_data(vport);
3522 vport->stat_data_blocked = 0;
3523 spin_unlock_irq(shost->host_lock);
3531 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3532 * @dev: Pointer to class device object.
3533 * @buf: Data buffer.
3535 * This function is the read call back function for
3536 * lpfc_stat_data_ctrl sysfs file. This function report the
3537 * current statistical data collection state.
3540 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3543 struct Scsi_Host *shost = class_to_shost(dev);
3544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3545 struct lpfc_hba *phba = vport->phba;
3549 unsigned long bucket_value;
3551 switch (phba->bucket_type) {
3552 case LPFC_LINEAR_BUCKET:
3553 bucket_type = "linear";
3555 case LPFC_POWER2_BUCKET:
3556 bucket_type = "power2";
3559 bucket_type = "No Bucket";
3563 sprintf(&buf[index], "Statistical Data enabled :%d, "
3564 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3565 " Bucket step :%d\nLatency Ranges :",
3566 vport->stat_data_enabled, vport->stat_data_blocked,
3567 bucket_type, phba->bucket_base, phba->bucket_step);
3568 index = strlen(buf);
3569 if (phba->bucket_type != LPFC_NO_BUCKET) {
3570 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3571 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3572 bucket_value = phba->bucket_base +
3573 phba->bucket_step * i;
3575 bucket_value = phba->bucket_base +
3576 (1 << i) * phba->bucket_step;
3578 if (index + 10 > PAGE_SIZE)
3580 sprintf(&buf[index], "%08ld ", bucket_value);
3581 index = strlen(buf);
3584 sprintf(&buf[index], "\n");
3589 * Sysfs attribute to control the statistical data collection.
3591 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3592 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3595 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3599 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3602 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3603 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3604 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3608 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3610 * @kobj: Pointer to the kernel object
3611 * @bin_attr: Attribute object
3612 * @buff: Buffer pointer
3614 * @count: Buffer size
3616 * This function is the read call back function for lpfc_drvr_stat_data
3617 * sysfs file. This function export the statistical data to user
3621 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3622 struct bin_attribute *bin_attr,
3623 char *buf, loff_t off, size_t count)
3625 struct device *dev = container_of(kobj, struct device,
3627 struct Scsi_Host *shost = class_to_shost(dev);
3628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3629 struct lpfc_hba *phba = vport->phba;
3630 int i = 0, index = 0;
3631 unsigned long nport_index;
3632 struct lpfc_nodelist *ndlp = NULL;
3633 nport_index = (unsigned long)off /
3634 MAX_STAT_DATA_SIZE_PER_TARGET;
3636 if (!vport->stat_data_enabled || vport->stat_data_blocked
3637 || (phba->bucket_type == LPFC_NO_BUCKET))
3640 spin_lock_irq(shost->host_lock);
3641 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3642 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3645 if (nport_index > 0) {
3650 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3654 if (!ndlp->lat_data)
3658 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3659 ndlp->nlp_portname.u.wwn[0],
3660 ndlp->nlp_portname.u.wwn[1],
3661 ndlp->nlp_portname.u.wwn[2],
3662 ndlp->nlp_portname.u.wwn[3],
3663 ndlp->nlp_portname.u.wwn[4],
3664 ndlp->nlp_portname.u.wwn[5],
3665 ndlp->nlp_portname.u.wwn[6],
3666 ndlp->nlp_portname.u.wwn[7]);
3668 index = strlen(buf);
3670 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3671 sprintf(&buf[index], "%010u,",
3672 ndlp->lat_data[i].cmd_count);
3673 index = strlen(buf);
3675 sprintf(&buf[index], "\n");
3676 index = strlen(buf);
3678 spin_unlock_irq(shost->host_lock);
3682 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3684 .name = "lpfc_drvr_stat_data",
3687 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3688 .read = sysfs_drvr_stat_data_read,
3693 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3695 # Value range is [0,16]. Default value is 0.
3698 * lpfc_link_speed_set - Set the adapters link speed
3699 * @phba: lpfc_hba pointer.
3700 * @val: link speed value.
3703 * If val is in a valid range then set the adapter's link speed field and
3704 * issue a lip; if the lip fails reset the link speed to the old value.
3707 * If the value is not in range log a kernel error message and return an error.
3710 * zero if val is in range and lip okay.
3711 * non-zero return value from lpfc_issue_lip()
3712 * -EINVAL val out of range
3715 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3716 const char *buf, size_t count)
3718 struct Scsi_Host *shost = class_to_shost(dev);
3719 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3720 struct lpfc_hba *phba = vport->phba;
3721 int val = LPFC_USER_LINK_SPEED_AUTO;
3723 const char *val_buf = buf;
3727 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3729 val_buf = &buf[strlen("nolip ")];
3732 if (!isdigit(val_buf[0]))
3734 if (sscanf(val_buf, "%i", &val) != 1)
3737 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3738 "3055 lpfc_link_speed changed from %d to %d %s\n",
3739 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3741 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3742 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3743 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3744 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3745 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3746 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3747 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
3748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3749 "2879 lpfc_link_speed attribute cannot be set "
3750 "to %d. Speed is not supported by this port.\n",
3754 if (val == LPFC_USER_LINK_SPEED_16G &&
3755 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3756 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3757 "3112 lpfc_link_speed attribute cannot be set "
3758 "to %d. Speed is not supported in loop mode.\n",
3762 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3763 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3764 prev_val = phba->cfg_link_speed;
3765 phba->cfg_link_speed = val;
3769 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3771 phba->cfg_link_speed = prev_val;
3776 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3777 "0469 lpfc_link_speed attribute cannot be set to %d, "
3778 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3782 static int lpfc_link_speed = 0;
3783 module_param(lpfc_link_speed, int, S_IRUGO);
3784 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3785 lpfc_param_show(link_speed)
3788 * lpfc_link_speed_init - Set the adapters link speed
3789 * @phba: lpfc_hba pointer.
3790 * @val: link speed value.
3793 * If val is in a valid range then set the adapter's link speed field.
3796 * If the value is not in range log a kernel error message, clear the link
3797 * speed and return an error.
3800 * zero if val saved.
3801 * -EINVAL val out of range
3804 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3806 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3807 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3808 "3111 lpfc_link_speed of %d cannot "
3809 "support loop mode, setting topology to default.\n",
3811 phba->cfg_topology = 0;
3813 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3814 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3815 phba->cfg_link_speed = val;
3818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3819 "0405 lpfc_link_speed attribute cannot "
3820 "be set to %d, allowed values are "
3821 "["LPFC_LINK_SPEED_STRING"]\n", val);
3822 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3826 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3827 lpfc_link_speed_show, lpfc_link_speed_store);
3830 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3831 # 0 = aer disabled or not supported
3832 # 1 = aer supported and enabled (default)
3833 # Value range is [0,1]. Default value is 1.
3837 * lpfc_aer_support_store - Set the adapter for aer support
3839 * @dev: class device that is converted into a Scsi_host.
3840 * @attr: device attribute, not used.
3841 * @buf: containing enable or disable aer flag.
3842 * @count: unused variable.
3845 * If the val is 1 and currently the device's AER capability was not
3846 * enabled, invoke the kernel's enable AER helper routine, trying to
3847 * enable the device's AER capability. If the helper routine enabling
3848 * AER returns success, update the device's cfg_aer_support flag to
3849 * indicate AER is supported by the device; otherwise, if the device
3850 * AER capability is already enabled to support AER, then do nothing.
3852 * If the val is 0 and currently the device's AER support was enabled,
3853 * invoke the kernel's disable AER helper routine. After that, update
3854 * the device's cfg_aer_support flag to indicate AER is not supported
3855 * by the device; otherwise, if the device AER capability is already
3856 * disabled from supporting AER, then do nothing.
3859 * length of the buf on success if val is in range the intended mode
3861 * -EINVAL if val out of range or intended mode is not supported.
3864 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3865 const char *buf, size_t count)
3867 struct Scsi_Host *shost = class_to_shost(dev);
3868 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3869 struct lpfc_hba *phba = vport->phba;
3870 int val = 0, rc = -EINVAL;
3872 if (!isdigit(buf[0]))
3874 if (sscanf(buf, "%i", &val) != 1)
3879 if (phba->hba_flag & HBA_AER_ENABLED) {
3880 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3882 spin_lock_irq(&phba->hbalock);
3883 phba->hba_flag &= ~HBA_AER_ENABLED;
3884 spin_unlock_irq(&phba->hbalock);
3885 phba->cfg_aer_support = 0;
3890 phba->cfg_aer_support = 0;
3895 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3896 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3898 spin_lock_irq(&phba->hbalock);
3899 phba->hba_flag |= HBA_AER_ENABLED;
3900 spin_unlock_irq(&phba->hbalock);
3901 phba->cfg_aer_support = 1;
3906 phba->cfg_aer_support = 1;
3917 static int lpfc_aer_support = 1;
3918 module_param(lpfc_aer_support, int, S_IRUGO);
3919 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3920 lpfc_param_show(aer_support)
3923 * lpfc_aer_support_init - Set the initial adapters aer support flag
3924 * @phba: lpfc_hba pointer.
3925 * @val: enable aer or disable aer flag.
3928 * If val is in a valid range [0,1], then set the adapter's initial
3929 * cfg_aer_support field. It will be up to the driver's probe_one
3930 * routine to determine whether the device's AER support can be set
3934 * If the value is not in range log a kernel error message, and
3935 * choose the default value of setting AER support and return.
3938 * zero if val saved.
3939 * -EINVAL val out of range
3942 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3944 if (val == 0 || val == 1) {
3945 phba->cfg_aer_support = val;
3948 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3949 "2712 lpfc_aer_support attribute value %d out "
3950 "of range, allowed values are 0|1, setting it "
3951 "to default value of 1\n", val);
3952 /* By default, try to enable AER on a device */
3953 phba->cfg_aer_support = 1;
3957 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3958 lpfc_aer_support_show, lpfc_aer_support_store);
3961 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3962 * @dev: class device that is converted into a Scsi_host.
3963 * @attr: device attribute, not used.
3964 * @buf: containing flag 1 for aer cleanup state.
3965 * @count: unused variable.
3968 * If the @buf contains 1 and the device currently has the AER support
3969 * enabled, then invokes the kernel AER helper routine
3970 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3971 * error status register.
3976 * -EINVAL if the buf does not contain the 1 or the device is not currently
3977 * enabled with the AER support.
3980 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3981 const char *buf, size_t count)
3983 struct Scsi_Host *shost = class_to_shost(dev);
3984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3985 struct lpfc_hba *phba = vport->phba;
3988 if (!isdigit(buf[0]))
3990 if (sscanf(buf, "%i", &val) != 1)
3995 if (phba->hba_flag & HBA_AER_ENABLED)
3996 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4004 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4005 lpfc_aer_cleanup_state);
4008 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4010 * @dev: class device that is converted into a Scsi_host.
4011 * @attr: device attribute, not used.
4012 * @buf: containing the string the number of vfs to be enabled.
4013 * @count: unused variable.
4016 * When this api is called either through user sysfs, the driver shall
4017 * try to enable or disable SR-IOV virtual functions according to the
4020 * If zero virtual function has been enabled to the physical function,
4021 * the driver shall invoke the pci enable virtual function api trying
4022 * to enable the virtual functions. If the nr_vfn provided is greater
4023 * than the maximum supported, the maximum virtual function number will
4024 * be used for invoking the api; otherwise, the nr_vfn provided shall
4025 * be used for invoking the api. If the api call returned success, the
4026 * actual number of virtual functions enabled will be set to the driver
4027 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4028 * cfg_sriov_nr_virtfn remains zero.
4030 * If none-zero virtual functions have already been enabled to the
4031 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4032 * -EINVAL will be returned and the driver does nothing;
4034 * If the nr_vfn provided is zero and none-zero virtual functions have
4035 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4036 * disabling virtual function api shall be invoded to disable all the
4037 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4038 * zero. Otherwise, if zero virtual function has been enabled, do
4042 * length of the buf on success if val is in range the intended mode
4044 * -EINVAL if val out of range or intended mode is not supported.
4047 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4048 const char *buf, size_t count)
4050 struct Scsi_Host *shost = class_to_shost(dev);
4051 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4052 struct lpfc_hba *phba = vport->phba;
4053 struct pci_dev *pdev = phba->pcidev;
4054 int val = 0, rc = -EINVAL;
4056 /* Sanity check on user data */
4057 if (!isdigit(buf[0]))
4059 if (sscanf(buf, "%i", &val) != 1)
4064 /* Request disabling virtual functions */
4066 if (phba->cfg_sriov_nr_virtfn > 0) {
4067 pci_disable_sriov(pdev);
4068 phba->cfg_sriov_nr_virtfn = 0;
4073 /* Request enabling virtual functions */
4074 if (phba->cfg_sriov_nr_virtfn > 0) {
4075 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4076 "3018 There are %d virtual functions "
4077 "enabled on physical function.\n",
4078 phba->cfg_sriov_nr_virtfn);
4082 if (val <= LPFC_MAX_VFN_PER_PFN)
4083 phba->cfg_sriov_nr_virtfn = val;
4085 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4086 "3019 Enabling %d virtual functions is not "
4091 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4093 phba->cfg_sriov_nr_virtfn = 0;
4101 static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
4102 module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
4103 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
4104 lpfc_param_show(sriov_nr_virtfn)
4107 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
4108 * @phba: lpfc_hba pointer.
4109 * @val: link speed value.
4112 * If val is in a valid range [0,255], then set the adapter's initial
4113 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
4114 * number shall be used instead. It will be up to the driver's probe_one
4115 * routine to determine whether the device's SR-IOV is supported or not.
4118 * zero if val saved.
4119 * -EINVAL val out of range
4122 lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
4124 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
4125 phba->cfg_sriov_nr_virtfn = val;
4129 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4130 "3017 Enabling %d virtual functions is not "
4134 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4135 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4138 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4140 * @dev: class device that is converted into a Scsi_host.
4141 * @attr: device attribute, not used.
4142 * @buf: containing the string the number of vfs to be enabled.
4143 * @count: unused variable.
4148 * length of the buf on success if val is in range the intended mode
4150 * -EINVAL if val out of range or intended mode is not supported.
4153 lpfc_request_firmware_upgrade_store(struct device *dev,
4154 struct device_attribute *attr,
4155 const char *buf, size_t count)
4157 struct Scsi_Host *shost = class_to_shost(dev);
4158 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4159 struct lpfc_hba *phba = vport->phba;
4160 int val = 0, rc = -EINVAL;
4162 /* Sanity check on user data */
4163 if (!isdigit(buf[0]))
4165 if (sscanf(buf, "%i", &val) != 1)
4170 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4178 static int lpfc_req_fw_upgrade;
4179 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4180 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4181 lpfc_param_show(request_firmware_upgrade)
4184 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4185 * @phba: lpfc_hba pointer.
4189 * Set the initial Linux generic firmware upgrade enable or disable flag.
4192 * zero if val saved.
4193 * -EINVAL val out of range
4196 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4198 if (val >= 0 && val <= 1) {
4199 phba->cfg_request_firmware_upgrade = val;
4204 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4205 lpfc_request_firmware_upgrade_show,
4206 lpfc_request_firmware_upgrade_store);
4209 * lpfc_fcp_imax_store
4211 * @dev: class device that is converted into a Scsi_host.
4212 * @attr: device attribute, not used.
4213 * @buf: string with the number of fast-path FCP interrupts per second.
4214 * @count: unused variable.
4217 * If val is in a valid range [636,651042], then set the adapter's
4218 * maximum number of fast-path FCP interrupts per second.
4221 * length of the buf on success if val is in range the intended mode
4223 * -EINVAL if val out of range or intended mode is not supported.
4226 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4227 const char *buf, size_t count)
4229 struct Scsi_Host *shost = class_to_shost(dev);
4230 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4231 struct lpfc_hba *phba = vport->phba;
4234 /* fcp_imax is only valid for SLI4 */
4235 if (phba->sli_rev != LPFC_SLI_REV4)
4238 /* Sanity check on user data */
4239 if (!isdigit(buf[0]))
4241 if (sscanf(buf, "%i", &val) != 1)
4245 * Value range for the HBA is [5000,5000000]
4246 * The value for each EQ depends on how many EQs are configured.
4248 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
4251 phba->cfg_fcp_imax = (uint32_t)val;
4252 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
4253 lpfc_modify_fcp_eq_delay(phba, i);
4259 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4262 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4264 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4265 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4266 MODULE_PARM_DESC(lpfc_fcp_imax,
4267 "Set the maximum number of FCP interrupts per second per HBA");
4268 lpfc_param_show(fcp_imax)
4271 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4272 * @phba: lpfc_hba pointer.
4273 * @val: link speed value.
4276 * If val is in a valid range [636,651042], then initialize the adapter's
4277 * maximum number of fast-path FCP interrupts per second.
4280 * zero if val saved.
4281 * -EINVAL val out of range
4284 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4286 if (phba->sli_rev != LPFC_SLI_REV4) {
4287 phba->cfg_fcp_imax = 0;
4291 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
4292 phba->cfg_fcp_imax = val;
4296 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4297 "3016 fcp_imax: %d out of range, using default\n", val);
4298 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4303 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4304 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4307 * lpfc_state_show - Display current driver CPU affinity
4308 * @dev: class converted to a Scsi_host structure.
4309 * @attr: device attribute, not used.
4310 * @buf: on return contains text describing the state of the link.
4312 * Returns: size of formatted string.
4315 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4318 struct Scsi_Host *shost = class_to_shost(dev);
4319 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4320 struct lpfc_hba *phba = vport->phba;
4321 struct lpfc_vector_map_info *cpup;
4324 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4325 (phba->intr_type != MSIX))
4328 switch (phba->cfg_fcp_cpu_map) {
4330 len += snprintf(buf + len, PAGE_SIZE-len,
4331 "fcp_cpu_map: No mapping (%d)\n",
4332 phba->cfg_fcp_cpu_map);
4335 len += snprintf(buf + len, PAGE_SIZE-len,
4336 "fcp_cpu_map: HBA centric mapping (%d): "
4338 phba->cfg_fcp_cpu_map,
4339 phba->sli4_hba.num_online_cpu);
4342 len += snprintf(buf + len, PAGE_SIZE-len,
4343 "fcp_cpu_map: Driver centric mapping (%d): "
4345 phba->cfg_fcp_cpu_map,
4346 phba->sli4_hba.num_online_cpu);
4350 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4351 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4353 /* margin should fit in this and the truncated message */
4354 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4355 len += snprintf(buf + len, PAGE_SIZE-len,
4356 "CPU %02d io_chan %02d "
4357 "physid %d coreid %d\n",
4358 phba->sli4_hba.curr_disp_cpu,
4359 cpup->channel_id, cpup->phys_id,
4362 len += snprintf(buf + len, PAGE_SIZE-len,
4363 "CPU %02d io_chan %02d "
4364 "physid %d coreid %d IRQ %d\n",
4365 phba->sli4_hba.curr_disp_cpu,
4366 cpup->channel_id, cpup->phys_id,
4367 cpup->core_id, cpup->irq);
4369 phba->sli4_hba.curr_disp_cpu++;
4371 /* display max number of CPUs keeping some margin */
4372 if (phba->sli4_hba.curr_disp_cpu <
4373 phba->sli4_hba.num_present_cpu &&
4374 (len >= (PAGE_SIZE - 64))) {
4375 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4380 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4381 phba->sli4_hba.curr_disp_cpu = 0;
4387 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4388 * @dev: class device that is converted into a Scsi_host.
4389 * @attr: device attribute, not used.
4390 * @buf: one or more lpfc_polling_flags values.
4394 * -EINVAL - Not implemented yet.
4397 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4398 const char *buf, size_t count)
4400 int status = -EINVAL;
4405 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4408 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4409 # 0 - Do not affinitze IRQ vectors
4410 # 1 - Affintize HBA vectors with respect to each HBA
4411 # (start with CPU0 for each HBA)
4412 # 2 - Affintize HBA vectors with respect to the entire driver
4413 # (round robin thru all CPUs across all HBAs)
4415 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4416 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4417 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4418 "Defines how to map CPUs to IRQ vectors per HBA");
4421 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4422 * @phba: lpfc_hba pointer.
4423 * @val: link speed value.
4426 * If val is in a valid range [0-2], then affinitze the adapter's
4430 * zero if val saved.
4431 * -EINVAL val out of range
4434 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4436 if (phba->sli_rev != LPFC_SLI_REV4) {
4437 phba->cfg_fcp_cpu_map = 0;
4441 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4442 phba->cfg_fcp_cpu_map = val;
4446 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4447 "3326 fcp_cpu_map: %d out of range, using default\n",
4449 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4454 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4455 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4458 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4459 # Value range is [2,3]. Default value is 3.
4461 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4462 "Select Fibre Channel class of service for FCP sequences");
4465 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4466 # is [0,1]. Default value is 0.
4468 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4469 "Use ADISC on rediscovery to authenticate FCP devices");
4472 # lpfc_first_burst_size: First burst size to use on the NPorts
4473 # that support first burst.
4474 # Value range is [0,65536]. Default value is 0.
4476 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4477 "First burst size for Targets that support first burst");
4480 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4481 # depth. Default value is 0. When the value of this parameter is zero the
4482 # SCSI command completion time is not used for controlling I/O queue depth. When
4483 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4484 # to limit the I/O completion time to the parameter value.
4485 # The value is set in milliseconds.
4487 static int lpfc_max_scsicmpl_time;
4488 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
4489 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
4490 "Use command completion time to control queue depth");
4491 lpfc_vport_param_show(max_scsicmpl_time);
4492 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
4494 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4496 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4497 struct lpfc_nodelist *ndlp, *next_ndlp;
4499 if (val == vport->cfg_max_scsicmpl_time)
4501 if ((val < 0) || (val > 60000))
4503 vport->cfg_max_scsicmpl_time = val;
4505 spin_lock_irq(shost->host_lock);
4506 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4507 if (!NLP_CHK_NODE_ACT(ndlp))
4509 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4511 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4513 spin_unlock_irq(shost->host_lock);
4516 lpfc_vport_param_store(max_scsicmpl_time);
4517 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4518 lpfc_max_scsicmpl_time_show,
4519 lpfc_max_scsicmpl_time_store);
4522 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4523 # range is [0,1]. Default value is 0.
4525 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4528 # lpfc_fcp_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4529 # range is [0,1]. Default value is 0.
4530 # For [0], FCP commands are issued to Work Queues ina round robin fashion.
4531 # For [1], FCP commands are issued to a Work Queue associated with the
4533 # It would be set to 1 by the driver if it's able to set up cpu affinity
4534 # for FCP I/Os through Work Queue associated with the current CPU. Otherwise,
4535 # roundrobin scheduling of FCP I/Os through WQs will be used.
4537 LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
4538 "issuing commands [0] - Round Robin, [1] - Current CPU");
4541 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4542 # range is [0,1]. Default value is 0.
4543 # For [0], bus reset issues target reset to ALL devices
4544 # For [1], bus reset issues target reset to non-FCP2 devices
4546 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4547 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4551 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4552 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4553 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4554 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4555 # cr_delay is set to 0.
4557 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4558 "interrupt response is generated");
4560 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4561 "interrupt response is generated");
4564 # lpfc_multi_ring_support: Determines how many rings to spread available
4565 # cmd/rsp IOCB entries across.
4566 # Value range is [1,2]. Default value is 1.
4568 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4569 "SLI rings to spread IOCB entries across");
4572 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4573 # identifies what rctl value to configure the additional ring for.
4574 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4576 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4577 255, "Identifies RCTL for additional ring configuration");
4580 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4581 # identifies what type value to configure the additional ring for.
4582 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4584 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4585 255, "Identifies TYPE for additional ring configuration");
4588 # lpfc_fdmi_on: controls FDMI support.
4590 # bit 0 = FDMI support no FDMI support
4591 # LPFC_FDMI_SUPPORT just turns basic support on/off
4592 # bit 1 = Register delay no register delay (60 seconds)
4593 # LPFC_FDMI_REG_DELAY 60 sec registration delay after FDMI login
4594 # bit 2 = All attributes Use a attribute subset
4595 # LPFC_FDMI_ALL_ATTRIB applies to both port and HBA attributes
4596 # Port attrutes subset: 1 thru 6 OR all: 1 thru 0xd 0x101 0x102 0x103
4597 # HBA attributes subset: 1 thru 0xb OR all: 1 thru 0xc
4598 # Value range [0,7]. Default value is 0.
4600 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 7, "Enable FDMI support");
4603 # Specifies the maximum number of ELS cmds we can have outstanding (for
4604 # discovery). Value range is [1,64]. Default value = 32.
4606 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4607 "during discovery");
4610 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4611 # will be scanned by the SCSI midlayer when sequential scanning is
4612 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4613 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4614 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4615 # above. The lpfc driver limits the default value to 255 for two reasons.
4616 # As it bounds the sequential scan loop, scanning for thousands of luns
4617 # on a target can take minutes of wall clock time. Additionally,
4618 # there are FC targets, such as JBODs, that only recognize 8-bits of
4619 # LUN ID. When they receive a value greater than 8 bits, they chop off
4620 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4621 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4622 # valid responses at each of the LUN IDs, to believe there are multiple
4623 # devices present, when in fact, there is only 1.
4624 # A customer that is aware of their target behaviors, and the results as
4625 # indicated above, is welcome to increase the lpfc_max_luns value.
4626 # As mentioned, this value is not used by the lpfc driver, only the
4628 # Value range is [0,65535]. Default value is 255.
4629 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4631 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4634 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4635 # Value range is [1,255], default value is 10.
4637 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4638 "Milliseconds driver will wait between polling FCP ring");
4641 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4642 # to complete in seconds. Value range is [5,180], default value is 60.
4644 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4645 "Maximum time to wait for task management commands to complete");
4647 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4648 # support this feature
4651 # 2 = MSI-X enabled (default)
4652 # Value range is [0,2]. Default value is 2.
4654 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4655 "MSI-X (2), if possible");
4658 # lpfc_fcp_io_channel: Set the number of FCP EQ/CQ/WQ IO channels
4660 # Value range is [1,7]. Default value is 4.
4662 LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4663 LPFC_FCP_IO_CHAN_MAX,
4664 "Set the number of FCP I/O channels");
4667 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4668 # 0 = HBA resets disabled
4669 # 1 = HBA resets enabled (default)
4670 # Value range is [0,1]. Default value is 1.
4672 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4675 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
4676 # 0 = HBA Heartbeat disabled
4677 # 1 = HBA Heartbeat enabled (default)
4678 # Value range is [0,1]. Default value is 1.
4680 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4683 # lpfc_EnableXLane: Enable Express Lane Feature
4684 # 0x0 Express Lane Feature disabled
4685 # 0x1 Express Lane Feature enabled
4686 # Value range is [0,1]. Default value is 0.
4688 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4691 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4692 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4693 # Value range is [0x0,0x7f]. Default value is 0
4695 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
4698 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4699 # 0 = BlockGuard disabled (default)
4700 # 1 = BlockGuard enabled
4701 # Value range is [0,1]. Default value is 0.
4703 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4706 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4707 # 0 = disabled (default)
4709 # Value range is [0,1]. Default value is 0.
4711 # This feature in under investigation and may be supported in the future.
4713 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4717 # - Bit mask of host protection capabilities used to register with the
4719 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4720 # - Allows you to ultimately specify which profiles to use
4721 # - Default will result in registering capabilities for all profiles.
4722 # - SHOST_DIF_TYPE1_PROTECTION 1
4723 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4724 # - SHOST_DIX_TYPE0_PROTECTION 8
4725 # HBA supports DIX Type 0: Host to HBA protection only
4726 # - SHOST_DIX_TYPE1_PROTECTION 16
4727 # HBA supports DIX Type 1: Host to HBA Type 1 protection
4730 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4731 SHOST_DIX_TYPE0_PROTECTION |
4732 SHOST_DIX_TYPE1_PROTECTION;
4734 module_param(lpfc_prot_mask, uint, S_IRUGO);
4735 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4738 # lpfc_prot_guard: i
4739 # - Bit mask of protection guard types to register with the SCSI mid-layer
4740 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
4741 # - Allows you to ultimately specify which profiles to use
4742 # - Default will result in registering capabilities for all guard types
4745 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
4746 module_param(lpfc_prot_guard, byte, S_IRUGO);
4747 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4750 * Delay initial NPort discovery when Clean Address bit is cleared in
4751 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4752 * This parameter can have value 0 or 1.
4753 * When this parameter is set to 0, no delay is added to the initial
4755 * When this parameter is set to non-zero value, initial Nport discovery is
4756 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4757 * accept and FCID/Fabric name/Fabric portname is changed.
4758 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4759 * when Clean Address bit is cleared in FLOGI/FDISC
4760 * accept and FCID/Fabric name/Fabric portname is changed.
4761 * Default value is 0.
4763 int lpfc_delay_discovery;
4764 module_param(lpfc_delay_discovery, int, S_IRUGO);
4765 MODULE_PARM_DESC(lpfc_delay_discovery,
4766 "Delay NPort discovery when Clean Address bit is cleared. "
4767 "Allowed values: 0,1.");
4770 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
4771 * This value can be set to values between 64 and 4096. The default value is
4772 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4773 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
4774 * Because of the additional overhead involved in setting up T10-DIF,
4775 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4776 * and will be limited to 512 if BlockGuard is enabled under SLI3.
4778 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4779 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4782 * This parameter will be depricated, the driver cannot limit the
4783 * protection data s/g list.
4785 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4786 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4787 "Max Protection Scatter Gather Segment Count");
4789 struct device_attribute *lpfc_hba_attrs[] = {
4791 &dev_attr_bg_guard_err,
4792 &dev_attr_bg_apptag_err,
4793 &dev_attr_bg_reftag_err,
4795 &dev_attr_serialnum,
4796 &dev_attr_modeldesc,
4797 &dev_attr_modelname,
4798 &dev_attr_programtype,
4802 &dev_attr_option_rom_version,
4803 &dev_attr_link_state,
4804 &dev_attr_num_discovered_ports,
4805 &dev_attr_menlo_mgmt_mode,
4806 &dev_attr_lpfc_drvr_version,
4807 &dev_attr_lpfc_enable_fip,
4808 &dev_attr_lpfc_temp_sensor,
4809 &dev_attr_lpfc_log_verbose,
4810 &dev_attr_lpfc_lun_queue_depth,
4811 &dev_attr_lpfc_tgt_queue_depth,
4812 &dev_attr_lpfc_hba_queue_depth,
4813 &dev_attr_lpfc_peer_port_login,
4814 &dev_attr_lpfc_nodev_tmo,
4815 &dev_attr_lpfc_devloss_tmo,
4816 &dev_attr_lpfc_fcp_class,
4817 &dev_attr_lpfc_use_adisc,
4818 &dev_attr_lpfc_first_burst_size,
4819 &dev_attr_lpfc_ack0,
4820 &dev_attr_lpfc_topology,
4821 &dev_attr_lpfc_scan_down,
4822 &dev_attr_lpfc_link_speed,
4823 &dev_attr_lpfc_fcp_io_sched,
4824 &dev_attr_lpfc_fcp2_no_tgt_reset,
4825 &dev_attr_lpfc_cr_delay,
4826 &dev_attr_lpfc_cr_count,
4827 &dev_attr_lpfc_multi_ring_support,
4828 &dev_attr_lpfc_multi_ring_rctl,
4829 &dev_attr_lpfc_multi_ring_type,
4830 &dev_attr_lpfc_fdmi_on,
4831 &dev_attr_lpfc_max_luns,
4832 &dev_attr_lpfc_enable_npiv,
4833 &dev_attr_lpfc_fcf_failover_policy,
4834 &dev_attr_lpfc_enable_rrq,
4835 &dev_attr_nport_evt_cnt,
4836 &dev_attr_board_mode,
4843 &dev_attr_npiv_info,
4844 &dev_attr_issue_reset,
4845 &dev_attr_lpfc_poll,
4846 &dev_attr_lpfc_poll_tmo,
4847 &dev_attr_lpfc_task_mgmt_tmo,
4848 &dev_attr_lpfc_use_msi,
4849 &dev_attr_lpfc_fcp_imax,
4850 &dev_attr_lpfc_fcp_cpu_map,
4851 &dev_attr_lpfc_fcp_io_channel,
4852 &dev_attr_lpfc_enable_bg,
4853 &dev_attr_lpfc_soft_wwnn,
4854 &dev_attr_lpfc_soft_wwpn,
4855 &dev_attr_lpfc_soft_wwn_enable,
4856 &dev_attr_lpfc_enable_hba_reset,
4857 &dev_attr_lpfc_enable_hba_heartbeat,
4858 &dev_attr_lpfc_EnableXLane,
4859 &dev_attr_lpfc_XLanePriority,
4860 &dev_attr_lpfc_xlane_lun,
4861 &dev_attr_lpfc_xlane_tgt,
4862 &dev_attr_lpfc_xlane_vpt,
4863 &dev_attr_lpfc_xlane_lun_state,
4864 &dev_attr_lpfc_xlane_lun_status,
4865 &dev_attr_lpfc_sg_seg_cnt,
4866 &dev_attr_lpfc_max_scsicmpl_time,
4867 &dev_attr_lpfc_stat_data_ctrl,
4868 &dev_attr_lpfc_prot_sg_seg_cnt,
4869 &dev_attr_lpfc_aer_support,
4870 &dev_attr_lpfc_aer_state_cleanup,
4871 &dev_attr_lpfc_sriov_nr_virtfn,
4872 &dev_attr_lpfc_req_fw_upgrade,
4873 &dev_attr_lpfc_suppress_link_up,
4874 &dev_attr_lpfc_iocb_cnt,
4877 &dev_attr_txcmplq_hw,
4878 &dev_attr_lpfc_fips_level,
4879 &dev_attr_lpfc_fips_rev,
4881 &dev_attr_lpfc_sriov_hw_max_virtfn,
4883 &dev_attr_lpfc_xlane_supported,
4887 struct device_attribute *lpfc_vport_attrs[] = {
4889 &dev_attr_link_state,
4890 &dev_attr_num_discovered_ports,
4891 &dev_attr_lpfc_drvr_version,
4892 &dev_attr_lpfc_log_verbose,
4893 &dev_attr_lpfc_lun_queue_depth,
4894 &dev_attr_lpfc_tgt_queue_depth,
4895 &dev_attr_lpfc_nodev_tmo,
4896 &dev_attr_lpfc_devloss_tmo,
4897 &dev_attr_lpfc_hba_queue_depth,
4898 &dev_attr_lpfc_peer_port_login,
4899 &dev_attr_lpfc_restrict_login,
4900 &dev_attr_lpfc_fcp_class,
4901 &dev_attr_lpfc_use_adisc,
4902 &dev_attr_lpfc_first_burst_size,
4903 &dev_attr_lpfc_fdmi_on,
4904 &dev_attr_lpfc_max_luns,
4905 &dev_attr_nport_evt_cnt,
4906 &dev_attr_npiv_info,
4907 &dev_attr_lpfc_enable_da_id,
4908 &dev_attr_lpfc_max_scsicmpl_time,
4909 &dev_attr_lpfc_stat_data_ctrl,
4910 &dev_attr_lpfc_static_vport,
4911 &dev_attr_lpfc_fips_level,
4912 &dev_attr_lpfc_fips_rev,
4917 * sysfs_ctlreg_write - Write method for writing to ctlreg
4918 * @filp: open sysfs file
4919 * @kobj: kernel kobject that contains the kernel class device.
4920 * @bin_attr: kernel attributes passed to us.
4921 * @buf: contains the data to be written to the adapter IOREG space.
4922 * @off: offset into buffer to beginning of data.
4923 * @count: bytes to transfer.
4926 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4927 * Uses the adapter io control registers to send buf contents to the adapter.
4930 * -ERANGE off and count combo out of range
4931 * -EINVAL off, count or buff address invalid
4932 * -EPERM adapter is offline
4933 * value of count, buf contents written
4936 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4937 struct bin_attribute *bin_attr,
4938 char *buf, loff_t off, size_t count)
4941 struct device *dev = container_of(kobj, struct device, kobj);
4942 struct Scsi_Host *shost = class_to_shost(dev);
4943 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4944 struct lpfc_hba *phba = vport->phba;
4946 if (phba->sli_rev >= LPFC_SLI_REV4)
4949 if ((off + count) > FF_REG_AREA_SIZE)
4952 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4955 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4958 /* This is to protect HBA registers from accidental writes. */
4959 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4962 if (!(vport->fc_flag & FC_OFFLINE_MODE))
4965 spin_lock_irq(&phba->hbalock);
4966 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4967 buf_off += sizeof(uint32_t))
4968 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
4969 phba->ctrl_regs_memmap_p + off + buf_off);
4971 spin_unlock_irq(&phba->hbalock);
4977 * sysfs_ctlreg_read - Read method for reading from ctlreg
4978 * @filp: open sysfs file
4979 * @kobj: kernel kobject that contains the kernel class device.
4980 * @bin_attr: kernel attributes passed to us.
4981 * @buf: if successful contains the data from the adapter IOREG space.
4982 * @off: offset into buffer to beginning of data.
4983 * @count: bytes to transfer.
4986 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
4987 * Uses the adapter io control registers to read data into buf.
4990 * -ERANGE off and count combo out of range
4991 * -EINVAL off, count or buff address invalid
4992 * value of count, buf contents read
4995 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4996 struct bin_attribute *bin_attr,
4997 char *buf, loff_t off, size_t count)
5001 struct device *dev = container_of(kobj, struct device, kobj);
5002 struct Scsi_Host *shost = class_to_shost(dev);
5003 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5004 struct lpfc_hba *phba = vport->phba;
5006 if (phba->sli_rev >= LPFC_SLI_REV4)
5009 if (off > FF_REG_AREA_SIZE)
5012 if ((off + count) > FF_REG_AREA_SIZE)
5013 count = FF_REG_AREA_SIZE - off;
5015 if (count == 0) return 0;
5017 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5020 spin_lock_irq(&phba->hbalock);
5022 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5023 tmp_ptr = (uint32_t *)(buf + buf_off);
5024 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5027 spin_unlock_irq(&phba->hbalock);
5032 static struct bin_attribute sysfs_ctlreg_attr = {
5035 .mode = S_IRUSR | S_IWUSR,
5038 .read = sysfs_ctlreg_read,
5039 .write = sysfs_ctlreg_write,
5043 * sysfs_mbox_write - Write method for writing information via mbox
5044 * @filp: open sysfs file
5045 * @kobj: kernel kobject that contains the kernel class device.
5046 * @bin_attr: kernel attributes passed to us.
5047 * @buf: contains the data to be written to sysfs mbox.
5048 * @off: offset into buffer to beginning of data.
5049 * @count: bytes to transfer.
5052 * Deprecated function. All mailbox access from user space is performed via the
5056 * -EPERM operation not permitted
5059 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5060 struct bin_attribute *bin_attr,
5061 char *buf, loff_t off, size_t count)
5067 * sysfs_mbox_read - Read method for reading information via mbox
5068 * @filp: open sysfs file
5069 * @kobj: kernel kobject that contains the kernel class device.
5070 * @bin_attr: kernel attributes passed to us.
5071 * @buf: contains the data to be read from sysfs mbox.
5072 * @off: offset into buffer to beginning of data.
5073 * @count: bytes to transfer.
5076 * Deprecated function. All mailbox access from user space is performed via the
5080 * -EPERM operation not permitted
5083 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5084 struct bin_attribute *bin_attr,
5085 char *buf, loff_t off, size_t count)
5090 static struct bin_attribute sysfs_mbox_attr = {
5093 .mode = S_IRUSR | S_IWUSR,
5095 .size = MAILBOX_SYSFS_MAX,
5096 .read = sysfs_mbox_read,
5097 .write = sysfs_mbox_write,
5101 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5102 * @vport: address of lpfc vport structure.
5106 * error return code from sysfs_create_bin_file()
5109 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5111 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5114 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5115 &sysfs_drvr_stat_data_attr);
5117 /* Virtual ports do not need ctrl_reg and mbox */
5118 if (error || vport->port_type == LPFC_NPIV_PORT)
5121 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5122 &sysfs_ctlreg_attr);
5124 goto out_remove_stat_attr;
5126 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5129 goto out_remove_ctlreg_attr;
5132 out_remove_ctlreg_attr:
5133 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5134 out_remove_stat_attr:
5135 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5136 &sysfs_drvr_stat_data_attr);
5142 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5143 * @vport: address of lpfc vport structure.
5146 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5148 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5149 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5150 &sysfs_drvr_stat_data_attr);
5151 /* Virtual ports do not need ctrl_reg and mbox */
5152 if (vport->port_type == LPFC_NPIV_PORT)
5154 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5155 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5160 * Dynamic FC Host Attributes Support
5164 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5165 * @shost: kernel scsi host pointer.
5168 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5170 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5172 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5173 sizeof fc_host_symbolic_name(shost));
5177 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5178 * @shost: kernel scsi host pointer.
5181 lpfc_get_host_port_id(struct Scsi_Host *shost)
5183 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5185 /* note: fc_myDID already in cpu endianness */
5186 fc_host_port_id(shost) = vport->fc_myDID;
5190 * lpfc_get_host_port_type - Set the value of the scsi host port type
5191 * @shost: kernel scsi host pointer.
5194 lpfc_get_host_port_type(struct Scsi_Host *shost)
5196 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5197 struct lpfc_hba *phba = vport->phba;
5199 spin_lock_irq(shost->host_lock);
5201 if (vport->port_type == LPFC_NPIV_PORT) {
5202 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5203 } else if (lpfc_is_link_up(phba)) {
5204 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5205 if (vport->fc_flag & FC_PUBLIC_LOOP)
5206 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5208 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5210 if (vport->fc_flag & FC_FABRIC)
5211 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5213 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5216 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5218 spin_unlock_irq(shost->host_lock);
5222 * lpfc_get_host_port_state - Set the value of the scsi host port state
5223 * @shost: kernel scsi host pointer.
5226 lpfc_get_host_port_state(struct Scsi_Host *shost)
5228 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5229 struct lpfc_hba *phba = vport->phba;
5231 spin_lock_irq(shost->host_lock);
5233 if (vport->fc_flag & FC_OFFLINE_MODE)
5234 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5236 switch (phba->link_state) {
5237 case LPFC_LINK_UNKNOWN:
5238 case LPFC_LINK_DOWN:
5239 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5243 case LPFC_HBA_READY:
5244 /* Links up, reports port state accordingly */
5245 if (vport->port_state < LPFC_VPORT_READY)
5246 fc_host_port_state(shost) =
5247 FC_PORTSTATE_BYPASSED;
5249 fc_host_port_state(shost) =
5250 FC_PORTSTATE_ONLINE;
5252 case LPFC_HBA_ERROR:
5253 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5256 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5261 spin_unlock_irq(shost->host_lock);
5265 * lpfc_get_host_speed - Set the value of the scsi host speed
5266 * @shost: kernel scsi host pointer.
5269 lpfc_get_host_speed(struct Scsi_Host *shost)
5271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5272 struct lpfc_hba *phba = vport->phba;
5274 spin_lock_irq(shost->host_lock);
5276 if (lpfc_is_link_up(phba)) {
5277 switch(phba->fc_linkspeed) {
5278 case LPFC_LINK_SPEED_1GHZ:
5279 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5281 case LPFC_LINK_SPEED_2GHZ:
5282 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5284 case LPFC_LINK_SPEED_4GHZ:
5285 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5287 case LPFC_LINK_SPEED_8GHZ:
5288 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5290 case LPFC_LINK_SPEED_10GHZ:
5291 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5293 case LPFC_LINK_SPEED_16GHZ:
5294 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5296 case LPFC_LINK_SPEED_32GHZ:
5297 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5300 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5304 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5306 spin_unlock_irq(shost->host_lock);
5310 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5311 * @shost: kernel scsi host pointer.
5314 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5316 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5317 struct lpfc_hba *phba = vport->phba;
5320 spin_lock_irq(shost->host_lock);
5322 if ((vport->port_state > LPFC_FLOGI) &&
5323 ((vport->fc_flag & FC_FABRIC) ||
5324 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5325 (vport->fc_flag & FC_PUBLIC_LOOP))))
5326 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5328 /* fabric is local port if there is no F/FL_Port */
5331 spin_unlock_irq(shost->host_lock);
5333 fc_host_fabric_name(shost) = node_name;
5337 * lpfc_get_stats - Return statistical information about the adapter
5338 * @shost: kernel scsi host pointer.
5341 * NULL on error for link down, no mbox pool, sli2 active,
5342 * management not allowed, memory allocation error, or mbox error.
5346 * address of the adapter host statistics
5348 static struct fc_host_statistics *
5349 lpfc_get_stats(struct Scsi_Host *shost)
5351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5352 struct lpfc_hba *phba = vport->phba;
5353 struct lpfc_sli *psli = &phba->sli;
5354 struct fc_host_statistics *hs = &phba->link_stats;
5355 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5356 LPFC_MBOXQ_t *pmboxq;
5358 unsigned long seconds;
5362 * prevent udev from issuing mailbox commands until the port is
5365 if (phba->link_state < LPFC_LINK_DOWN ||
5366 !phba->mbox_mem_pool ||
5367 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5370 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5373 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5376 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5378 pmb = &pmboxq->u.mb;
5379 pmb->mbxCommand = MBX_READ_STATUS;
5380 pmb->mbxOwner = OWN_HOST;
5381 pmboxq->context1 = NULL;
5382 pmboxq->vport = vport;
5384 if (vport->fc_flag & FC_OFFLINE_MODE)
5385 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5387 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5389 if (rc != MBX_SUCCESS) {
5390 if (rc != MBX_TIMEOUT)
5391 mempool_free(pmboxq, phba->mbox_mem_pool);
5395 memset(hs, 0, sizeof (struct fc_host_statistics));
5397 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5399 * The MBX_READ_STATUS returns tx_k_bytes which has to
5400 * converted to words
5402 hs->tx_words = (uint64_t)
5403 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5405 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5406 hs->rx_words = (uint64_t)
5407 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5410 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5411 pmb->mbxCommand = MBX_READ_LNK_STAT;
5412 pmb->mbxOwner = OWN_HOST;
5413 pmboxq->context1 = NULL;
5414 pmboxq->vport = vport;
5416 if (vport->fc_flag & FC_OFFLINE_MODE)
5417 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5419 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5421 if (rc != MBX_SUCCESS) {
5422 if (rc != MBX_TIMEOUT)
5423 mempool_free(pmboxq, phba->mbox_mem_pool);
5427 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5428 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5429 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5430 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5431 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5432 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5433 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5435 hs->link_failure_count -= lso->link_failure_count;
5436 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5437 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5438 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5439 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5440 hs->invalid_crc_count -= lso->invalid_crc_count;
5441 hs->error_frames -= lso->error_frames;
5443 if (phba->hba_flag & HBA_FCOE_MODE) {
5445 hs->nos_count = (phba->link_events >> 1);
5446 hs->nos_count -= lso->link_events;
5447 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5448 hs->lip_count = (phba->fc_eventTag >> 1);
5449 hs->lip_count -= lso->link_events;
5453 hs->nos_count = (phba->fc_eventTag >> 1);
5454 hs->nos_count -= lso->link_events;
5457 hs->dumped_frames = -1;
5459 seconds = get_seconds();
5460 if (seconds < psli->stats_start)
5461 hs->seconds_since_last_reset = seconds +
5462 ((unsigned long)-1 - psli->stats_start);
5464 hs->seconds_since_last_reset = seconds - psli->stats_start;
5466 mempool_free(pmboxq, phba->mbox_mem_pool);
5472 * lpfc_reset_stats - Copy the adapter link stats information
5473 * @shost: kernel scsi host pointer.
5476 lpfc_reset_stats(struct Scsi_Host *shost)
5478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5479 struct lpfc_hba *phba = vport->phba;
5480 struct lpfc_sli *psli = &phba->sli;
5481 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5482 LPFC_MBOXQ_t *pmboxq;
5486 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5489 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5492 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5494 pmb = &pmboxq->u.mb;
5495 pmb->mbxCommand = MBX_READ_STATUS;
5496 pmb->mbxOwner = OWN_HOST;
5497 pmb->un.varWords[0] = 0x1; /* reset request */
5498 pmboxq->context1 = NULL;
5499 pmboxq->vport = vport;
5501 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5502 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5503 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5505 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5507 if (rc != MBX_SUCCESS) {
5508 if (rc != MBX_TIMEOUT)
5509 mempool_free(pmboxq, phba->mbox_mem_pool);
5513 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5514 pmb->mbxCommand = MBX_READ_LNK_STAT;
5515 pmb->mbxOwner = OWN_HOST;
5516 pmboxq->context1 = NULL;
5517 pmboxq->vport = vport;
5519 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5520 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5521 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5523 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5525 if (rc != MBX_SUCCESS) {
5526 if (rc != MBX_TIMEOUT)
5527 mempool_free( pmboxq, phba->mbox_mem_pool);
5531 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5532 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5533 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5534 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5535 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5536 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5537 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5538 if (phba->hba_flag & HBA_FCOE_MODE)
5539 lso->link_events = (phba->link_events >> 1);
5541 lso->link_events = (phba->fc_eventTag >> 1);
5543 psli->stats_start = get_seconds();
5545 mempool_free(pmboxq, phba->mbox_mem_pool);
5551 * The LPFC driver treats linkdown handling as target loss events so there
5552 * are no sysfs handlers for link_down_tmo.
5556 * lpfc_get_node_by_target - Return the nodelist for a target
5557 * @starget: kernel scsi target pointer.
5560 * address of the node list if found
5561 * NULL target not found
5563 static struct lpfc_nodelist *
5564 lpfc_get_node_by_target(struct scsi_target *starget)
5566 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5567 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5568 struct lpfc_nodelist *ndlp;
5570 spin_lock_irq(shost->host_lock);
5571 /* Search for this, mapped, target ID */
5572 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5573 if (NLP_CHK_NODE_ACT(ndlp) &&
5574 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5575 starget->id == ndlp->nlp_sid) {
5576 spin_unlock_irq(shost->host_lock);
5580 spin_unlock_irq(shost->host_lock);
5585 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5586 * @starget: kernel scsi target pointer.
5589 lpfc_get_starget_port_id(struct scsi_target *starget)
5591 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5593 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5597 * lpfc_get_starget_node_name - Set the target node name
5598 * @starget: kernel scsi target pointer.
5600 * Description: Set the target node name to the ndlp node name wwn or zero.
5603 lpfc_get_starget_node_name(struct scsi_target *starget)
5605 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5607 fc_starget_node_name(starget) =
5608 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5612 * lpfc_get_starget_port_name - Set the target port name
5613 * @starget: kernel scsi target pointer.
5615 * Description: set the target port name to the ndlp port name wwn or zero.
5618 lpfc_get_starget_port_name(struct scsi_target *starget)
5620 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5622 fc_starget_port_name(starget) =
5623 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5627 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5628 * @rport: fc rport address.
5629 * @timeout: new value for dev loss tmo.
5632 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5633 * dev_loss_tmo to one.
5636 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5639 rport->dev_loss_tmo = timeout;
5641 rport->dev_loss_tmo = 1;
5645 * lpfc_rport_show_function - Return rport target information
5648 * Macro that uses field to generate a function with the name lpfc_show_rport_
5650 * lpfc_show_rport_##field: returns the bytes formatted in buf
5651 * @cdev: class converted to an fc_rport.
5652 * @buf: on return contains the target_field or zero.
5654 * Returns: size of formatted string.
5656 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5658 lpfc_show_rport_##field (struct device *dev, \
5659 struct device_attribute *attr, \
5662 struct fc_rport *rport = transport_class_to_rport(dev); \
5663 struct lpfc_rport_data *rdata = rport->hostdata; \
5664 return snprintf(buf, sz, format_string, \
5665 (rdata->target) ? cast rdata->target->field : 0); \
5668 #define lpfc_rport_rd_attr(field, format_string, sz) \
5669 lpfc_rport_show_function(field, format_string, sz, ) \
5670 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5673 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
5674 * @fc_vport: The fc_vport who's symbolic name has been changed.
5677 * This function is called by the transport after the @fc_vport's symbolic name
5678 * has been changed. This function re-registers the symbolic name with the
5679 * switch to propagate the change into the fabric if the vport is active.
5682 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5684 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5686 if (vport->port_state == LPFC_VPORT_READY)
5687 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5691 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5692 * @phba: Pointer to lpfc_hba struct.
5694 * This function is called by the lpfc_get_cfgparam() routine to set the
5695 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
5696 * log message according to the module's lpfc_log_verbose parameter setting
5697 * before hba port or vport created.
5700 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5702 phba->cfg_log_verbose = verbose;
5705 struct fc_function_template lpfc_transport_functions = {
5706 /* fixed attributes the driver supports */
5707 .show_host_node_name = 1,
5708 .show_host_port_name = 1,
5709 .show_host_supported_classes = 1,
5710 .show_host_supported_fc4s = 1,
5711 .show_host_supported_speeds = 1,
5712 .show_host_maxframe_size = 1,
5714 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
5715 .show_host_symbolic_name = 1,
5717 /* dynamic attributes the driver supports */
5718 .get_host_port_id = lpfc_get_host_port_id,
5719 .show_host_port_id = 1,
5721 .get_host_port_type = lpfc_get_host_port_type,
5722 .show_host_port_type = 1,
5724 .get_host_port_state = lpfc_get_host_port_state,
5725 .show_host_port_state = 1,
5727 /* active_fc4s is shown but doesn't change (thus no get function) */
5728 .show_host_active_fc4s = 1,
5730 .get_host_speed = lpfc_get_host_speed,
5731 .show_host_speed = 1,
5733 .get_host_fabric_name = lpfc_get_host_fabric_name,
5734 .show_host_fabric_name = 1,
5737 * The LPFC driver treats linkdown handling as target loss events
5738 * so there are no sysfs handlers for link_down_tmo.
5741 .get_fc_host_stats = lpfc_get_stats,
5742 .reset_fc_host_stats = lpfc_reset_stats,
5744 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5745 .show_rport_maxframe_size = 1,
5746 .show_rport_supported_classes = 1,
5748 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5749 .show_rport_dev_loss_tmo = 1,
5751 .get_starget_port_id = lpfc_get_starget_port_id,
5752 .show_starget_port_id = 1,
5754 .get_starget_node_name = lpfc_get_starget_node_name,
5755 .show_starget_node_name = 1,
5757 .get_starget_port_name = lpfc_get_starget_port_name,
5758 .show_starget_port_name = 1,
5760 .issue_fc_host_lip = lpfc_issue_lip,
5761 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5762 .terminate_rport_io = lpfc_terminate_rport_io,
5764 .dd_fcvport_size = sizeof(struct lpfc_vport *),
5766 .vport_disable = lpfc_vport_disable,
5768 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5770 .bsg_request = lpfc_bsg_request,
5771 .bsg_timeout = lpfc_bsg_timeout,
5774 struct fc_function_template lpfc_vport_transport_functions = {
5775 /* fixed attributes the driver supports */
5776 .show_host_node_name = 1,
5777 .show_host_port_name = 1,
5778 .show_host_supported_classes = 1,
5779 .show_host_supported_fc4s = 1,
5780 .show_host_supported_speeds = 1,
5781 .show_host_maxframe_size = 1,
5783 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
5784 .show_host_symbolic_name = 1,
5786 /* dynamic attributes the driver supports */
5787 .get_host_port_id = lpfc_get_host_port_id,
5788 .show_host_port_id = 1,
5790 .get_host_port_type = lpfc_get_host_port_type,
5791 .show_host_port_type = 1,
5793 .get_host_port_state = lpfc_get_host_port_state,
5794 .show_host_port_state = 1,
5796 /* active_fc4s is shown but doesn't change (thus no get function) */
5797 .show_host_active_fc4s = 1,
5799 .get_host_speed = lpfc_get_host_speed,
5800 .show_host_speed = 1,
5802 .get_host_fabric_name = lpfc_get_host_fabric_name,
5803 .show_host_fabric_name = 1,
5806 * The LPFC driver treats linkdown handling as target loss events
5807 * so there are no sysfs handlers for link_down_tmo.
5810 .get_fc_host_stats = lpfc_get_stats,
5811 .reset_fc_host_stats = lpfc_reset_stats,
5813 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5814 .show_rport_maxframe_size = 1,
5815 .show_rport_supported_classes = 1,
5817 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5818 .show_rport_dev_loss_tmo = 1,
5820 .get_starget_port_id = lpfc_get_starget_port_id,
5821 .show_starget_port_id = 1,
5823 .get_starget_node_name = lpfc_get_starget_node_name,
5824 .show_starget_node_name = 1,
5826 .get_starget_port_name = lpfc_get_starget_port_name,
5827 .show_starget_port_name = 1,
5829 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5830 .terminate_rport_io = lpfc_terminate_rport_io,
5832 .vport_disable = lpfc_vport_disable,
5834 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5838 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
5839 * @phba: lpfc_hba pointer.
5842 lpfc_get_cfgparam(struct lpfc_hba *phba)
5844 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
5845 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
5846 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5847 lpfc_cr_count_init(phba, lpfc_cr_count);
5848 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5849 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5850 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5851 lpfc_ack0_init(phba, lpfc_ack0);
5852 lpfc_topology_init(phba, lpfc_topology);
5853 lpfc_link_speed_init(phba, lpfc_link_speed);
5854 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5855 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
5856 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5857 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
5858 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5859 lpfc_use_msi_init(phba, lpfc_use_msi);
5860 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5861 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
5862 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
5863 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5864 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5865 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
5866 if (phba->sli_rev != LPFC_SLI_REV4)
5867 phba->cfg_EnableXLane = 0;
5868 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
5869 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
5870 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
5871 phba->cfg_oas_lun_state = 0;
5872 phba->cfg_oas_lun_status = 0;
5873 phba->cfg_oas_flags = 0;
5874 lpfc_enable_bg_init(phba, lpfc_enable_bg);
5875 if (phba->sli_rev == LPFC_SLI_REV4)
5878 phba->cfg_poll = lpfc_poll;
5879 phba->cfg_soft_wwnn = 0L;
5880 phba->cfg_soft_wwpn = 0L;
5881 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5882 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5883 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5884 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5885 lpfc_aer_support_init(phba, lpfc_aer_support);
5886 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5887 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
5888 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5889 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5890 phba->cfg_enable_dss = 1;
5895 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5896 * @vport: lpfc_vport pointer.
5899 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5901 lpfc_log_verbose_init(vport, lpfc_log_verbose);
5902 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5903 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5904 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5905 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5906 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5907 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5908 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5909 lpfc_use_adisc_init(vport, lpfc_use_adisc);
5910 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
5911 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5912 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5913 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5914 lpfc_max_luns_init(vport, lpfc_max_luns);
5915 lpfc_scan_down_init(vport, lpfc_scan_down);
5916 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);