1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/aer.h>
27 #include <linux/gfp.h>
28 #include <linux/kernel.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_tcq.h>
34 #include <scsi/scsi_transport_fc.h>
35 #include <scsi/fc/fc_fs.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_version.h"
47 #include "lpfc_compat.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_vport.h"
51 #define LPFC_DEF_DEVLOSS_TMO 30
52 #define LPFC_MIN_DEVLOSS_TMO 1
53 #define LPFC_MAX_DEVLOSS_TMO 255
56 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
57 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
68 * Coded for 32 bit integers only.
71 lpfc_jedec_to_ascii(int incr, char hdw[])
74 for (i = 0; i < 8; i++) {
77 hdw[7 - i] = 0x30 + j;
79 hdw[7 - i] = 0x61 + j - 10;
87 * lpfc_drvr_version_show - Return the Emulex driver string with version number
88 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
92 * Returns: size of formatted string.
95 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
107 * Returns: size of formatted string.
110 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
120 return snprintf(buf, PAGE_SIZE, "0\n");
124 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
143 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
155 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
167 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
179 * lpfc_info_show - Return some pci info about the host in ascii
180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
184 * Returns: size of formatted string.
187 lpfc_info_show(struct device *dev, struct device_attribute *attr,
190 struct Scsi_Host *host = class_to_shost(dev);
192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
196 * lpfc_serialnum_show - Return the hba serial number in ascii
197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
201 * Returns: size of formatted string.
204 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
207 struct Scsi_Host *shost = class_to_shost(dev);
208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
215 * lpfc_temp_sensor_show - Return the temperature sensor level
216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
224 * Returns: size of formatted string.
227 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
230 struct Scsi_Host *shost = class_to_shost(dev);
231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
237 * lpfc_modeldesc_show - Return the model description of the hba
238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
242 * Returns: size of formatted string.
245 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
248 struct Scsi_Host *shost = class_to_shost(dev);
249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
256 * lpfc_modelname_show - Return the model name of the hba
257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
261 * Returns: size of formatted string.
264 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
267 struct Scsi_Host *shost = class_to_shost(dev);
268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
275 * lpfc_programtype_show - Return the program type of the hba
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
280 * Returns: size of formatted string.
283 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
286 struct Scsi_Host *shost = class_to_shost(dev);
287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
299 * Returns: size of formatted string.
302 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
313 * lpfc_vportnum_show - Return the port number in ascii of the hba
314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
318 * Returns: size of formatted string.
321 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
324 struct Scsi_Host *shost = class_to_shost(dev);
325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
332 * lpfc_fwrev_show - Return the firmware rev running in the hba
333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
337 * Returns: size of formatted string.
340 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
343 struct Scsi_Host *shost = class_to_shost(dev);
344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
348 lpfc_decode_firmware_rev(phba, fwrev, 1);
349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
353 * lpfc_hdw_show - Return the jedec information about the hba
354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
358 * Returns: size of formatted string.
361 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
364 struct Scsi_Host *shost = class_to_shost(dev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367 lpfc_vpd_t *vp = &phba->vpd;
369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
379 * Returns: size of formatted string.
382 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
385 struct Scsi_Host *shost = class_to_shost(dev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
393 * lpfc_state_show - Return the link state of the port
394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
399 * The switch statement has no default so zero will be returned.
401 * Returns: size of formatted string.
404 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
407 struct Scsi_Host *shost = class_to_shost(dev);
408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
414 case LPFC_WARM_START:
415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
423 len += snprintf(buf + len, PAGE_SIZE-len,
429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
431 switch (vport->port_state) {
432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
434 "Configuring Link\n");
438 case LPFC_FABRIC_CFG_LINK:
441 case LPFC_BUILD_DISC_LIST:
443 len += snprintf(buf + len, PAGE_SIZE - len,
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
454 case LPFC_VPORT_UNKNOWN:
455 len += snprintf(buf + len, PAGE_SIZE - len,
459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
463 if (vport->fc_flag & FC_PUBLIC_LOOP)
464 len += snprintf(buf + len, PAGE_SIZE-len,
467 len += snprintf(buf + len, PAGE_SIZE-len,
470 if (vport->fc_flag & FC_FABRIC)
471 len += snprintf(buf + len, PAGE_SIZE-len,
474 len += snprintf(buf + len, PAGE_SIZE-len,
483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
495 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
502 int status = -EINVAL;
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
527 * Returns: size of formatted string.
530 lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
533 struct Scsi_Host *shost = class_to_shost(dev);
534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
541 * lpfc_issue_lip - Misnomer, name carried over from long ago
542 * @shost: Scsi_Host pointer.
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
555 lpfc_issue_lip(struct Scsi_Host *shost)
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
592 lpfc_set_loopback_flag(phba);
593 if (mbxstatus != MBX_TIMEOUT)
594 mempool_free(pmboxq, phba->mbox_mem_pool);
596 if (mbxstatus == MBXERR_ERROR)
603 * lpfc_do_offline - Issues a mailbox command to bring the link down
604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
614 * -EIO error posting the event
618 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
628 init_completion(&online_compl);
629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
630 LPFC_EVT_OFFLINE_PREP);
634 wait_for_completion(&online_compl);
641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
646 while (pring->txcmplq_cnt) {
648 if (cnt++ > 500) { /* 5 secs */
649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
658 init_completion(&online_compl);
659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
663 wait_for_completion(&online_compl);
672 * lpfc_selective_reset - Offline then onlines the port
673 * @phba: lpfc_hba pointer.
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
680 * Assumes any error from lpfc_do_offline() will be negative.
681 * Do not make this function static.
684 * lpfc_do_offline() return code if not zero
685 * -EIO reset not configured or error posting the event
689 lpfc_selective_reset(struct lpfc_hba *phba)
691 struct completion online_compl;
695 if (!phba->cfg_enable_hba_reset)
698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
703 init_completion(&online_compl);
704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
709 wait_for_completion(&online_compl);
718 * lpfc_issue_reset - Selectively resets an adapter
719 * @dev: class device that is converted into a Scsi_host.
720 * @attr: device attribute, not used.
721 * @buf: containing the string "selective".
722 * @count: unused variable.
725 * If the buf contains the string "selective" then lpfc_selective_reset()
726 * is called to perform the reset.
729 * Assumes any error from lpfc_selective_reset() will be negative.
730 * If lpfc_selective_reset() returns zero then the length of the buffer
731 * is returned which indicates success
734 * -EINVAL if the buffer does not contain the string "selective"
735 * length of buf if lpfc-selective_reset() if the call succeeds
736 * return value of lpfc_selective_reset() if the call fails
739 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
740 const char *buf, size_t count)
742 struct Scsi_Host *shost = class_to_shost(dev);
743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
744 struct lpfc_hba *phba = vport->phba;
746 int status = -EINVAL;
748 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
749 status = phba->lpfc_selective_reset(phba);
758 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
759 * @phba: lpfc_hba pointer.
762 * SLI4 interface type-2 device to wait on the sliport status register for
763 * the readyness after performing a firmware reset.
769 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
771 struct lpfc_register portstat_reg;
775 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
776 &portstat_reg.word0);
778 /* wait for the SLI port firmware ready after firmware reset */
779 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
781 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
782 &portstat_reg.word0);
783 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
785 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
787 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
792 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
799 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
800 * @phba: lpfc_hba pointer.
803 * Request SLI4 interface type-2 device to perform a physical register set
810 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
812 struct completion online_compl;
817 if (!phba->cfg_enable_hba_reset)
820 if ((phba->sli_rev < LPFC_SLI_REV4) ||
821 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
822 LPFC_SLI_INTF_IF_TYPE_2))
825 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
830 /* wait for the device to be quiesced before firmware reset */
833 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
834 LPFC_CTL_PDEV_CTL_OFFSET);
836 if (opcode == LPFC_FW_DUMP)
837 reg_val |= LPFC_FW_DUMP_REQUEST;
838 else if (opcode == LPFC_FW_RESET)
839 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
840 else if (opcode == LPFC_DV_RESET)
841 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
843 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
844 LPFC_CTL_PDEV_CTL_OFFSET);
846 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
848 /* delay driver action following IF_TYPE_2 reset */
849 rc = lpfc_sli4_pdev_status_reg_wait(phba);
854 init_completion(&online_compl);
855 rc = lpfc_workq_post_event(phba, &status, &online_compl,
860 wait_for_completion(&online_compl);
869 * lpfc_nport_evt_cnt_show - Return the number of nport events
870 * @dev: class device that is converted into a Scsi_host.
871 * @attr: device attribute, not used.
872 * @buf: on return contains the ascii number of nport events.
874 * Returns: size of formatted string.
877 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
880 struct Scsi_Host *shost = class_to_shost(dev);
881 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
882 struct lpfc_hba *phba = vport->phba;
884 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
888 * lpfc_board_mode_show - Return the state of the board
889 * @dev: class device that is converted into a Scsi_host.
890 * @attr: device attribute, not used.
891 * @buf: on return contains the state of the adapter.
893 * Returns: size of formatted string.
896 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
899 struct Scsi_Host *shost = class_to_shost(dev);
900 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
901 struct lpfc_hba *phba = vport->phba;
904 if (phba->link_state == LPFC_HBA_ERROR)
906 else if (phba->link_state == LPFC_WARM_START)
907 state = "warm start";
908 else if (phba->link_state == LPFC_INIT_START)
913 return snprintf(buf, PAGE_SIZE, "%s\n", state);
917 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
918 * @dev: class device that is converted into a Scsi_host.
919 * @attr: device attribute, not used.
920 * @buf: containing one of the strings "online", "offline", "warm" or "error".
921 * @count: unused variable.
924 * -EACCES if enable hba reset not enabled
925 * -EINVAL if the buffer does not contain a valid string (see above)
926 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
927 * buf length greater than zero indicates success
930 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
931 const char *buf, size_t count)
933 struct Scsi_Host *shost = class_to_shost(dev);
934 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
935 struct lpfc_hba *phba = vport->phba;
936 struct completion online_compl;
940 if (!phba->cfg_enable_hba_reset)
943 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
944 "3050 lpfc_board_mode set to %s\n", buf);
946 init_completion(&online_compl);
948 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
949 rc = lpfc_workq_post_event(phba, &status, &online_compl,
953 wait_for_completion(&online_compl);
954 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
955 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
956 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
957 if (phba->sli_rev == LPFC_SLI_REV4)
960 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
961 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
962 if (phba->sli_rev == LPFC_SLI_REV4)
965 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
966 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
967 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
968 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
969 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
970 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
971 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
982 * lpfc_get_hba_info - Return various bits of informaton about the adapter
983 * @phba: pointer to the adapter structure.
984 * @mxri: max xri count.
985 * @axri: available xri count.
986 * @mrpi: max rpi count.
987 * @arpi: available rpi count.
988 * @mvpi: max vpi count.
989 * @avpi: available vpi count.
992 * If an integer pointer for an count is not null then the value for the
1000 lpfc_get_hba_info(struct lpfc_hba *phba,
1001 uint32_t *mxri, uint32_t *axri,
1002 uint32_t *mrpi, uint32_t *arpi,
1003 uint32_t *mvpi, uint32_t *avpi)
1005 struct lpfc_mbx_read_config *rd_config;
1006 LPFC_MBOXQ_t *pmboxq;
1012 * prevent udev from issuing mailbox commands until the port is
1015 if (phba->link_state < LPFC_LINK_DOWN ||
1016 !phba->mbox_mem_pool ||
1017 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1020 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1023 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1026 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1028 pmb = &pmboxq->u.mb;
1029 pmb->mbxCommand = MBX_READ_CONFIG;
1030 pmb->mbxOwner = OWN_HOST;
1031 pmboxq->context1 = NULL;
1033 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1034 rc = MBX_NOT_FINISHED;
1036 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1038 if (rc != MBX_SUCCESS) {
1039 if (rc != MBX_TIMEOUT)
1040 mempool_free(pmboxq, phba->mbox_mem_pool);
1044 if (phba->sli_rev == LPFC_SLI_REV4) {
1045 rd_config = &pmboxq->u.mqe.un.rd_config;
1047 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1049 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1050 phba->sli4_hba.max_cfg_param.rpi_used;
1052 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1054 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1055 phba->sli4_hba.max_cfg_param.xri_used;
1057 /* Account for differences with SLI-3. Get vpi count from
1058 * mailbox data and subtract one for max vpi value.
1060 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1061 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1066 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1069 *mrpi = pmb->un.varRdConfig.max_rpi;
1071 *arpi = pmb->un.varRdConfig.avail_rpi;
1073 *mxri = pmb->un.varRdConfig.max_xri;
1075 *axri = pmb->un.varRdConfig.avail_xri;
1077 *mvpi = pmb->un.varRdConfig.max_vpi;
1079 *avpi = pmb->un.varRdConfig.avail_vpi;
1082 mempool_free(pmboxq, phba->mbox_mem_pool);
1087 * lpfc_max_rpi_show - Return maximum rpi
1088 * @dev: class device that is converted into a Scsi_host.
1089 * @attr: device attribute, not used.
1090 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1093 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1094 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1095 * to "Unknown" and the buffer length is returned, therefore the caller
1096 * must check for "Unknown" in the buffer to detect a failure.
1098 * Returns: size of formatted string.
1101 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1104 struct Scsi_Host *shost = class_to_shost(dev);
1105 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1106 struct lpfc_hba *phba = vport->phba;
1109 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1110 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1111 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1115 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1116 * @dev: class device that is converted into a Scsi_host.
1117 * @attr: device attribute, not used.
1118 * @buf: containing the used rpi count in decimal or "Unknown".
1121 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1122 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1123 * to "Unknown" and the buffer length is returned, therefore the caller
1124 * must check for "Unknown" in the buffer to detect a failure.
1126 * Returns: size of formatted string.
1129 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1132 struct Scsi_Host *shost = class_to_shost(dev);
1133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1134 struct lpfc_hba *phba = vport->phba;
1137 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1138 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1139 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1143 * lpfc_max_xri_show - Return maximum xri
1144 * @dev: class device that is converted into a Scsi_host.
1145 * @attr: device attribute, not used.
1146 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1149 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1150 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1151 * to "Unknown" and the buffer length is returned, therefore the caller
1152 * must check for "Unknown" in the buffer to detect a failure.
1154 * Returns: size of formatted string.
1157 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1160 struct Scsi_Host *shost = class_to_shost(dev);
1161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1162 struct lpfc_hba *phba = vport->phba;
1165 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1166 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1167 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1171 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1172 * @dev: class device that is converted into a Scsi_host.
1173 * @attr: device attribute, not used.
1174 * @buf: on return contains the used xri count in decimal or "Unknown".
1177 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1178 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1179 * to "Unknown" and the buffer length is returned, therefore the caller
1180 * must check for "Unknown" in the buffer to detect a failure.
1182 * Returns: size of formatted string.
1185 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1188 struct Scsi_Host *shost = class_to_shost(dev);
1189 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1190 struct lpfc_hba *phba = vport->phba;
1193 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1194 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1195 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1199 * lpfc_max_vpi_show - Return maximum vpi
1200 * @dev: class device that is converted into a Scsi_host.
1201 * @attr: device attribute, not used.
1202 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1205 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1206 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1207 * to "Unknown" and the buffer length is returned, therefore the caller
1208 * must check for "Unknown" in the buffer to detect a failure.
1210 * Returns: size of formatted string.
1213 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1216 struct Scsi_Host *shost = class_to_shost(dev);
1217 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1218 struct lpfc_hba *phba = vport->phba;
1221 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1222 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1223 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1227 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1228 * @dev: class device that is converted into a Scsi_host.
1229 * @attr: device attribute, not used.
1230 * @buf: on return contains the used vpi count in decimal or "Unknown".
1233 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1234 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1235 * to "Unknown" and the buffer length is returned, therefore the caller
1236 * must check for "Unknown" in the buffer to detect a failure.
1238 * Returns: size of formatted string.
1241 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1244 struct Scsi_Host *shost = class_to_shost(dev);
1245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1246 struct lpfc_hba *phba = vport->phba;
1249 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1250 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1251 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1255 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1256 * @dev: class device that is converted into a Scsi_host.
1257 * @attr: device attribute, not used.
1258 * @buf: text that must be interpreted to determine if npiv is supported.
1261 * Buffer will contain text indicating npiv is not suppoerted on the port,
1262 * the port is an NPIV physical port, or it is an npiv virtual port with
1263 * the id of the vport.
1265 * Returns: size of formatted string.
1268 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1271 struct Scsi_Host *shost = class_to_shost(dev);
1272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1273 struct lpfc_hba *phba = vport->phba;
1275 if (!(phba->max_vpi))
1276 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1277 if (vport->port_type == LPFC_PHYSICAL_PORT)
1278 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1279 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1283 * lpfc_poll_show - Return text about poll support for the adapter
1284 * @dev: class device that is converted into a Scsi_host.
1285 * @attr: device attribute, not used.
1286 * @buf: on return contains the cfg_poll in hex.
1289 * cfg_poll should be a lpfc_polling_flags type.
1291 * Returns: size of formatted string.
1294 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1297 struct Scsi_Host *shost = class_to_shost(dev);
1298 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1299 struct lpfc_hba *phba = vport->phba;
1301 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1305 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1306 * @dev: class device that is converted into a Scsi_host.
1307 * @attr: device attribute, not used.
1308 * @buf: one or more lpfc_polling_flags values.
1312 * buf contents converted to integer and checked for a valid value.
1315 * -EINVAL if the buffer connot be converted or is out of range
1316 * length of the buf on success
1319 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1320 const char *buf, size_t count)
1322 struct Scsi_Host *shost = class_to_shost(dev);
1323 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1324 struct lpfc_hba *phba = vport->phba;
1329 if (!isdigit(buf[0]))
1332 if (sscanf(buf, "%i", &val) != 1)
1335 if ((val & 0x3) != val)
1338 if (phba->sli_rev == LPFC_SLI_REV4)
1341 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1342 "3051 lpfc_poll changed from %d to %d\n",
1343 phba->cfg_poll, val);
1345 spin_lock_irq(&phba->hbalock);
1347 old_val = phba->cfg_poll;
1349 if (val & ENABLE_FCP_RING_POLLING) {
1350 if ((val & DISABLE_FCP_RING_INT) &&
1351 !(old_val & DISABLE_FCP_RING_INT)) {
1352 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1353 spin_unlock_irq(&phba->hbalock);
1356 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1357 writel(creg_val, phba->HCregaddr);
1358 readl(phba->HCregaddr); /* flush */
1360 lpfc_poll_start_timer(phba);
1362 } else if (val != 0x0) {
1363 spin_unlock_irq(&phba->hbalock);
1367 if (!(val & DISABLE_FCP_RING_INT) &&
1368 (old_val & DISABLE_FCP_RING_INT))
1370 spin_unlock_irq(&phba->hbalock);
1371 del_timer(&phba->fcp_poll_timer);
1372 spin_lock_irq(&phba->hbalock);
1373 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1374 spin_unlock_irq(&phba->hbalock);
1377 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1378 writel(creg_val, phba->HCregaddr);
1379 readl(phba->HCregaddr); /* flush */
1382 phba->cfg_poll = val;
1384 spin_unlock_irq(&phba->hbalock);
1390 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1391 * @dev: class unused variable.
1392 * @attr: device attribute, not used.
1393 * @buf: on return contains the module description text.
1395 * Returns: size of formatted string.
1398 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1401 struct Scsi_Host *shost = class_to_shost(dev);
1402 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1403 struct lpfc_hba *phba = vport->phba;
1405 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1409 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1410 * @dev: class unused variable.
1411 * @attr: device attribute, not used.
1412 * @buf: on return contains the module description text.
1414 * Returns: size of formatted string.
1417 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1420 struct Scsi_Host *shost = class_to_shost(dev);
1421 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1422 struct lpfc_hba *phba = vport->phba;
1424 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1428 * lpfc_dss_show - Return the current state of dss and the configured state
1429 * @dev: class converted to a Scsi_host structure.
1430 * @attr: device attribute, not used.
1431 * @buf: on return contains the formatted text.
1433 * Returns: size of formatted string.
1436 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1439 struct Scsi_Host *shost = class_to_shost(dev);
1440 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1441 struct lpfc_hba *phba = vport->phba;
1443 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1444 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1445 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1450 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1451 * @dev: class converted to a Scsi_host structure.
1452 * @attr: device attribute, not used.
1453 * @buf: on return contains the formatted support level.
1456 * Returns the maximum number of virtual functions a physical function can
1457 * support, 0 will be returned if called on virtual function.
1459 * Returns: size of formatted string.
1462 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1463 struct device_attribute *attr,
1466 struct Scsi_Host *shost = class_to_shost(dev);
1467 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1468 struct lpfc_hba *phba = vport->phba;
1469 struct pci_dev *pdev = phba->pcidev;
1470 union lpfc_sli4_cfg_shdr *shdr;
1471 uint32_t shdr_status, shdr_add_status;
1472 LPFC_MBOXQ_t *mboxq;
1473 struct lpfc_mbx_get_prof_cfg *get_prof_cfg;
1474 struct lpfc_rsrc_desc_pcie *desc;
1475 uint32_t max_nr_virtfn;
1476 uint32_t desc_count;
1479 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1480 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1481 LPFC_SLI_INTF_IF_TYPE_2))
1484 if (!pdev->is_physfn)
1485 return snprintf(buf, PAGE_SIZE, "%d\n", 0);
1487 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1491 /* get the maximum number of virtfn support by physfn */
1492 length = (sizeof(struct lpfc_mbx_get_prof_cfg) -
1493 sizeof(struct lpfc_sli4_cfg_mhdr));
1494 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
1495 LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG,
1496 length, LPFC_SLI4_MBX_EMBED);
1497 shdr = (union lpfc_sli4_cfg_shdr *)
1498 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
1499 bf_set(lpfc_mbox_hdr_pf_num, &shdr->request,
1500 phba->sli4_hba.iov.pf_number + 1);
1502 get_prof_cfg = &mboxq->u.mqe.un.get_prof_cfg;
1503 bf_set(lpfc_mbx_get_prof_cfg_prof_tp, &get_prof_cfg->u.request,
1504 LPFC_CFG_TYPE_CURRENT_ACTIVE);
1506 rc = lpfc_sli_issue_mbox_wait(phba, mboxq,
1507 lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG));
1509 if (rc != MBX_TIMEOUT) {
1510 /* check return status */
1511 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1512 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
1514 if (shdr_status || shdr_add_status || rc)
1520 desc_count = get_prof_cfg->u.response.prof_cfg.rsrc_desc_count;
1522 for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) {
1523 desc = (struct lpfc_rsrc_desc_pcie *)
1524 &get_prof_cfg->u.response.prof_cfg.desc[i];
1525 if (LPFC_RSRC_DESC_TYPE_PCIE ==
1526 bf_get(lpfc_rsrc_desc_pcie_type, desc)) {
1527 max_nr_virtfn = bf_get(lpfc_rsrc_desc_pcie_nr_virtfn,
1533 if (i < LPFC_RSRC_DESC_MAX_NUM) {
1534 if (rc != MBX_TIMEOUT)
1535 mempool_free(mboxq, phba->mbox_mem_pool);
1536 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1540 if (rc != MBX_TIMEOUT)
1541 mempool_free(mboxq, phba->mbox_mem_pool);
1546 * lpfc_param_show - Return a cfg attribute value in decimal
1549 * Macro that given an attr e.g. hba_queue_depth expands
1550 * into a function with the name lpfc_hba_queue_depth_show.
1552 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1553 * @dev: class device that is converted into a Scsi_host.
1554 * @attr: device attribute, not used.
1555 * @buf: on return contains the attribute value in decimal.
1557 * Returns: size of formatted string.
1559 #define lpfc_param_show(attr) \
1561 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1564 struct Scsi_Host *shost = class_to_shost(dev);\
1565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1566 struct lpfc_hba *phba = vport->phba;\
1568 val = phba->cfg_##attr;\
1569 return snprintf(buf, PAGE_SIZE, "%d\n",\
1574 * lpfc_param_hex_show - Return a cfg attribute value in hex
1577 * Macro that given an attr e.g. hba_queue_depth expands
1578 * into a function with the name lpfc_hba_queue_depth_show
1580 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1581 * @dev: class device that is converted into a Scsi_host.
1582 * @attr: device attribute, not used.
1583 * @buf: on return contains the attribute value in hexadecimal.
1585 * Returns: size of formatted string.
1587 #define lpfc_param_hex_show(attr) \
1589 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1592 struct Scsi_Host *shost = class_to_shost(dev);\
1593 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1594 struct lpfc_hba *phba = vport->phba;\
1596 val = phba->cfg_##attr;\
1597 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1602 * lpfc_param_init - Initializes a cfg attribute
1605 * Macro that given an attr e.g. hba_queue_depth expands
1606 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1607 * takes a default argument, a minimum and maximum argument.
1609 * lpfc_##attr##_init: Initializes an attribute.
1610 * @phba: pointer the the adapter structure.
1611 * @val: integer attribute value.
1613 * Validates the min and max values then sets the adapter config field
1614 * accordingly, or uses the default if out of range and prints an error message.
1618 * -EINVAL if default used
1620 #define lpfc_param_init(attr, default, minval, maxval) \
1622 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1624 if (val >= minval && val <= maxval) {\
1625 phba->cfg_##attr = val;\
1628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1629 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1630 "allowed range is ["#minval", "#maxval"]\n", val); \
1631 phba->cfg_##attr = default;\
1636 * lpfc_param_set - Set a cfg attribute value
1639 * Macro that given an attr e.g. hba_queue_depth expands
1640 * into a function with the name lpfc_hba_queue_depth_set
1642 * lpfc_##attr##_set: Sets an attribute value.
1643 * @phba: pointer the the adapter structure.
1644 * @val: integer attribute value.
1647 * Validates the min and max values then sets the
1648 * adapter config field if in the valid range. prints error message
1649 * and does not set the parameter if invalid.
1653 * -EINVAL if val is invalid
1655 #define lpfc_param_set(attr, default, minval, maxval) \
1657 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1659 if (val >= minval && val <= maxval) {\
1660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1661 "3052 lpfc_" #attr " changed from %d to %d\n", \
1662 phba->cfg_##attr, val); \
1663 phba->cfg_##attr = val;\
1666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1667 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1668 "allowed range is ["#minval", "#maxval"]\n", val); \
1673 * lpfc_param_store - Set a vport attribute value
1676 * Macro that given an attr e.g. hba_queue_depth expands
1677 * into a function with the name lpfc_hba_queue_depth_store.
1679 * lpfc_##attr##_store: Set an sttribute value.
1680 * @dev: class device that is converted into a Scsi_host.
1681 * @attr: device attribute, not used.
1682 * @buf: contains the attribute value in ascii.
1686 * Convert the ascii text number to an integer, then
1687 * use the lpfc_##attr##_set function to set the value.
1690 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1691 * length of buffer upon success.
1693 #define lpfc_param_store(attr) \
1695 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1696 const char *buf, size_t count) \
1698 struct Scsi_Host *shost = class_to_shost(dev);\
1699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1700 struct lpfc_hba *phba = vport->phba;\
1702 if (!isdigit(buf[0]))\
1704 if (sscanf(buf, "%i", &val) != 1)\
1706 if (lpfc_##attr##_set(phba, val) == 0) \
1707 return strlen(buf);\
1713 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1716 * Macro that given an attr e.g. hba_queue_depth expands
1717 * into a function with the name lpfc_hba_queue_depth_show
1719 * lpfc_##attr##_show: prints the attribute value in decimal.
1720 * @dev: class device that is converted into a Scsi_host.
1721 * @attr: device attribute, not used.
1722 * @buf: on return contains the attribute value in decimal.
1724 * Returns: length of formatted string.
1726 #define lpfc_vport_param_show(attr) \
1728 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1731 struct Scsi_Host *shost = class_to_shost(dev);\
1732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1734 val = vport->cfg_##attr;\
1735 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1739 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1742 * Macro that given an attr e.g.
1743 * hba_queue_depth expands into a function with the name
1744 * lpfc_hba_queue_depth_show
1746 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1747 * @dev: class device that is converted into a Scsi_host.
1748 * @attr: device attribute, not used.
1749 * @buf: on return contains the attribute value in hexadecimal.
1751 * Returns: length of formatted string.
1753 #define lpfc_vport_param_hex_show(attr) \
1755 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1758 struct Scsi_Host *shost = class_to_shost(dev);\
1759 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1761 val = vport->cfg_##attr;\
1762 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1766 * lpfc_vport_param_init - Initialize a vport cfg attribute
1769 * Macro that given an attr e.g. hba_queue_depth expands
1770 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1771 * takes a default argument, a minimum and maximum argument.
1773 * lpfc_##attr##_init: validates the min and max values then sets the
1774 * adapter config field accordingly, or uses the default if out of range
1775 * and prints an error message.
1776 * @phba: pointer the the adapter structure.
1777 * @val: integer attribute value.
1781 * -EINVAL if default used
1783 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1785 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1787 if (val >= minval && val <= maxval) {\
1788 vport->cfg_##attr = val;\
1791 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1792 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1793 "allowed range is ["#minval", "#maxval"]\n", val); \
1794 vport->cfg_##attr = default;\
1799 * lpfc_vport_param_set - Set a vport cfg attribute
1802 * Macro that given an attr e.g. hba_queue_depth expands
1803 * into a function with the name lpfc_hba_queue_depth_set
1805 * lpfc_##attr##_set: validates the min and max values then sets the
1806 * adapter config field if in the valid range. prints error message
1807 * and does not set the parameter if invalid.
1808 * @phba: pointer the the adapter structure.
1809 * @val: integer attribute value.
1813 * -EINVAL if val is invalid
1815 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1817 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1819 if (val >= minval && val <= maxval) {\
1820 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1821 "3053 lpfc_" #attr " changed from %d to %d\n", \
1822 vport->cfg_##attr, val); \
1823 vport->cfg_##attr = val;\
1826 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1827 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1828 "allowed range is ["#minval", "#maxval"]\n", val); \
1833 * lpfc_vport_param_store - Set a vport attribute
1836 * Macro that given an attr e.g. hba_queue_depth
1837 * expands into a function with the name lpfc_hba_queue_depth_store
1839 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1840 * use the lpfc_##attr##_set function to set the value.
1841 * @cdev: class device that is converted into a Scsi_host.
1842 * @buf: contains the attribute value in decimal.
1846 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1847 * length of buffer upon success.
1849 #define lpfc_vport_param_store(attr) \
1851 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1852 const char *buf, size_t count) \
1854 struct Scsi_Host *shost = class_to_shost(dev);\
1855 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1857 if (!isdigit(buf[0]))\
1859 if (sscanf(buf, "%i", &val) != 1)\
1861 if (lpfc_##attr##_set(vport, val) == 0) \
1862 return strlen(buf);\
1868 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1869 static uint lpfc_##name = defval;\
1870 module_param(lpfc_##name, uint, S_IRUGO);\
1871 MODULE_PARM_DESC(lpfc_##name, desc);\
1872 lpfc_param_init(name, defval, minval, maxval)
1874 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1875 static uint lpfc_##name = defval;\
1876 module_param(lpfc_##name, uint, S_IRUGO);\
1877 MODULE_PARM_DESC(lpfc_##name, desc);\
1878 lpfc_param_show(name)\
1879 lpfc_param_init(name, defval, minval, maxval)\
1880 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1882 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1883 static uint lpfc_##name = defval;\
1884 module_param(lpfc_##name, uint, S_IRUGO);\
1885 MODULE_PARM_DESC(lpfc_##name, desc);\
1886 lpfc_param_show(name)\
1887 lpfc_param_init(name, defval, minval, maxval)\
1888 lpfc_param_set(name, defval, minval, maxval)\
1889 lpfc_param_store(name)\
1890 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1891 lpfc_##name##_show, lpfc_##name##_store)
1893 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1894 static uint lpfc_##name = defval;\
1895 module_param(lpfc_##name, uint, S_IRUGO);\
1896 MODULE_PARM_DESC(lpfc_##name, desc);\
1897 lpfc_param_hex_show(name)\
1898 lpfc_param_init(name, defval, minval, maxval)\
1899 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1901 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1902 static uint lpfc_##name = defval;\
1903 module_param(lpfc_##name, uint, S_IRUGO);\
1904 MODULE_PARM_DESC(lpfc_##name, desc);\
1905 lpfc_param_hex_show(name)\
1906 lpfc_param_init(name, defval, minval, maxval)\
1907 lpfc_param_set(name, defval, minval, maxval)\
1908 lpfc_param_store(name)\
1909 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1910 lpfc_##name##_show, lpfc_##name##_store)
1912 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1913 static uint lpfc_##name = defval;\
1914 module_param(lpfc_##name, uint, S_IRUGO);\
1915 MODULE_PARM_DESC(lpfc_##name, desc);\
1916 lpfc_vport_param_init(name, defval, minval, maxval)
1918 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1919 static uint lpfc_##name = defval;\
1920 module_param(lpfc_##name, uint, S_IRUGO);\
1921 MODULE_PARM_DESC(lpfc_##name, desc);\
1922 lpfc_vport_param_show(name)\
1923 lpfc_vport_param_init(name, defval, minval, maxval)\
1924 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1926 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1927 static uint lpfc_##name = defval;\
1928 module_param(lpfc_##name, uint, S_IRUGO);\
1929 MODULE_PARM_DESC(lpfc_##name, desc);\
1930 lpfc_vport_param_show(name)\
1931 lpfc_vport_param_init(name, defval, minval, maxval)\
1932 lpfc_vport_param_set(name, defval, minval, maxval)\
1933 lpfc_vport_param_store(name)\
1934 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1935 lpfc_##name##_show, lpfc_##name##_store)
1937 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1938 static uint lpfc_##name = defval;\
1939 module_param(lpfc_##name, uint, S_IRUGO);\
1940 MODULE_PARM_DESC(lpfc_##name, desc);\
1941 lpfc_vport_param_hex_show(name)\
1942 lpfc_vport_param_init(name, defval, minval, maxval)\
1943 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1945 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1946 static uint lpfc_##name = defval;\
1947 module_param(lpfc_##name, uint, S_IRUGO);\
1948 MODULE_PARM_DESC(lpfc_##name, desc);\
1949 lpfc_vport_param_hex_show(name)\
1950 lpfc_vport_param_init(name, defval, minval, maxval)\
1951 lpfc_vport_param_set(name, defval, minval, maxval)\
1952 lpfc_vport_param_store(name)\
1953 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1954 lpfc_##name##_show, lpfc_##name##_store)
1956 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1957 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1958 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1959 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1960 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1961 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1962 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1963 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1964 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1965 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1966 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1967 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1968 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1969 lpfc_link_state_store);
1970 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1971 lpfc_option_rom_version_show, NULL);
1972 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1973 lpfc_num_discovered_ports_show, NULL);
1974 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1975 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1976 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1977 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1978 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1979 lpfc_board_mode_show, lpfc_board_mode_store);
1980 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1981 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1982 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1983 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1984 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1985 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1986 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1987 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1988 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1989 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1990 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1991 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1992 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1993 lpfc_sriov_hw_max_virtfn_show, NULL);
1995 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1998 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1999 * @dev: class device that is converted into a Scsi_host.
2000 * @attr: device attribute, not used.
2001 * @buf: containing the string lpfc_soft_wwn_key.
2002 * @count: must be size of lpfc_soft_wwn_key.
2005 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2006 * length of buf indicates success
2009 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2010 const char *buf, size_t count)
2012 struct Scsi_Host *shost = class_to_shost(dev);
2013 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2014 struct lpfc_hba *phba = vport->phba;
2015 unsigned int cnt = count;
2018 * We're doing a simple sanity check for soft_wwpn setting.
2019 * We require that the user write a specific key to enable
2020 * the soft_wwpn attribute to be settable. Once the attribute
2021 * is written, the enable key resets. If further updates are
2022 * desired, the key must be written again to re-enable the
2025 * The "key" is not secret - it is a hardcoded string shown
2026 * here. The intent is to protect against the random user or
2027 * application that is just writing attributes.
2030 /* count may include a LF at end of string */
2031 if (buf[cnt-1] == '\n')
2034 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2035 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2038 phba->soft_wwn_enable = 1;
2041 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2042 lpfc_soft_wwn_enable_store);
2045 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2046 * @dev: class device that is converted into a Scsi_host.
2047 * @attr: device attribute, not used.
2048 * @buf: on return contains the wwpn in hexadecimal.
2050 * Returns: size of formatted string.
2053 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2056 struct Scsi_Host *shost = class_to_shost(dev);
2057 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2058 struct lpfc_hba *phba = vport->phba;
2060 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2061 (unsigned long long)phba->cfg_soft_wwpn);
2065 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2066 * @dev class device that is converted into a Scsi_host.
2067 * @attr: device attribute, not used.
2068 * @buf: contains the wwpn in hexadecimal.
2069 * @count: number of wwpn bytes in buf
2072 * -EACCES hba reset not enabled, adapter over temp
2073 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2074 * -EIO error taking adapter offline or online
2075 * value of count on success
2078 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2079 const char *buf, size_t count)
2081 struct Scsi_Host *shost = class_to_shost(dev);
2082 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2083 struct lpfc_hba *phba = vport->phba;
2084 struct completion online_compl;
2085 int stat1=0, stat2=0;
2086 unsigned int i, j, cnt=count;
2090 if (!phba->cfg_enable_hba_reset)
2092 spin_lock_irq(&phba->hbalock);
2093 if (phba->over_temp_state == HBA_OVER_TEMP) {
2094 spin_unlock_irq(&phba->hbalock);
2097 spin_unlock_irq(&phba->hbalock);
2098 /* count may include a LF at end of string */
2099 if (buf[cnt-1] == '\n')
2102 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2103 ((cnt == 17) && (*buf++ != 'x')) ||
2104 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2107 phba->soft_wwn_enable = 0;
2109 memset(wwpn, 0, sizeof(wwpn));
2111 /* Validate and store the new name */
2112 for (i=0, j=0; i < 16; i++) {
2115 value = hex_to_bin(*buf++);
2117 j = (j << 4) | value;
2121 wwpn[i/2] = j & 0xff;
2125 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2126 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2127 if (phba->cfg_soft_wwnn)
2128 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2130 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2131 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2133 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2135 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2136 "0463 lpfc_soft_wwpn attribute set failed to "
2137 "reinit adapter - %d\n", stat1);
2138 init_completion(&online_compl);
2139 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2144 wait_for_completion(&online_compl);
2146 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2147 "0464 lpfc_soft_wwpn attribute set failed to "
2148 "reinit adapter - %d\n", stat2);
2149 return (stat1 || stat2) ? -EIO : count;
2151 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2152 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2155 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2156 * @dev: class device that is converted into a Scsi_host.
2157 * @attr: device attribute, not used.
2158 * @buf: on return contains the wwnn in hexadecimal.
2160 * Returns: size of formatted string.
2163 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2166 struct Scsi_Host *shost = class_to_shost(dev);
2167 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2168 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2169 (unsigned long long)phba->cfg_soft_wwnn);
2173 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2174 * @cdev: class device that is converted into a Scsi_host.
2175 * @buf: contains the ww node name in hexadecimal.
2176 * @count: number of wwnn bytes in buf.
2179 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2180 * value of count on success
2183 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2184 const char *buf, size_t count)
2186 struct Scsi_Host *shost = class_to_shost(dev);
2187 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2188 unsigned int i, j, cnt=count;
2191 /* count may include a LF at end of string */
2192 if (buf[cnt-1] == '\n')
2195 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2196 ((cnt == 17) && (*buf++ != 'x')) ||
2197 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2201 * Allow wwnn to be set many times, as long as the enable is set.
2202 * However, once the wwpn is set, everything locks.
2205 memset(wwnn, 0, sizeof(wwnn));
2207 /* Validate and store the new name */
2208 for (i=0, j=0; i < 16; i++) {
2211 value = hex_to_bin(*buf++);
2213 j = (j << 4) | value;
2217 wwnn[i/2] = j & 0xff;
2221 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2223 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2224 "lpfc%d: soft_wwnn set. Value will take effect upon "
2225 "setting of the soft_wwpn\n", phba->brd_no);
2229 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2230 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2233 static int lpfc_poll = 0;
2234 module_param(lpfc_poll, int, S_IRUGO);
2235 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2237 " 1 - poll with interrupts enabled"
2238 " 3 - poll and disable FCP ring interrupts");
2240 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2241 lpfc_poll_show, lpfc_poll_store);
2243 int lpfc_sli_mode = 0;
2244 module_param(lpfc_sli_mode, int, S_IRUGO);
2245 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2246 " 0 - auto (SLI-3 if supported),"
2247 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2248 " 3 - select SLI-3");
2250 int lpfc_enable_npiv = 1;
2251 module_param(lpfc_enable_npiv, int, S_IRUGO);
2252 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2253 lpfc_param_show(enable_npiv);
2254 lpfc_param_init(enable_npiv, 1, 0, 1);
2255 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2257 int lpfc_enable_rrq;
2258 module_param(lpfc_enable_rrq, int, S_IRUGO);
2259 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2260 lpfc_param_show(enable_rrq);
2261 lpfc_param_init(enable_rrq, 0, 0, 1);
2262 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2265 # lpfc_suppress_link_up: Bring link up at initialization
2266 # 0x0 = bring link up (issue MBX_INIT_LINK)
2267 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2268 # 0x2 = never bring up link
2269 # Default value is 0.
2271 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2272 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2273 "Suppress Link Up at initialization");
2275 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2283 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2285 struct Scsi_Host *shost = class_to_shost(dev);
2286 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2288 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2291 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2292 lpfc_iocb_hw_show, NULL);
2294 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2296 struct Scsi_Host *shost = class_to_shost(dev);
2297 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2299 return snprintf(buf, PAGE_SIZE, "%d\n",
2300 phba->sli.ring[LPFC_ELS_RING].txq_max);
2303 static DEVICE_ATTR(txq_hw, S_IRUGO,
2304 lpfc_txq_hw_show, NULL);
2306 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2309 struct Scsi_Host *shost = class_to_shost(dev);
2310 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2312 return snprintf(buf, PAGE_SIZE, "%d\n",
2313 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2316 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2317 lpfc_txcmplq_hw_show, NULL);
2319 int lpfc_iocb_cnt = 2;
2320 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2321 MODULE_PARM_DESC(lpfc_iocb_cnt,
2322 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2323 lpfc_param_show(iocb_cnt);
2324 lpfc_param_init(iocb_cnt, 2, 1, 5);
2325 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2326 lpfc_iocb_cnt_show, NULL);
2329 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2330 # until the timer expires. Value range is [0,255]. Default value is 30.
2332 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2333 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2334 module_param(lpfc_nodev_tmo, int, 0);
2335 MODULE_PARM_DESC(lpfc_nodev_tmo,
2336 "Seconds driver will hold I/O waiting "
2337 "for a device to come back");
2340 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2341 * @dev: class converted to a Scsi_host structure.
2342 * @attr: device attribute, not used.
2343 * @buf: on return contains the dev loss timeout in decimal.
2345 * Returns: size of formatted string.
2348 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2351 struct Scsi_Host *shost = class_to_shost(dev);
2352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2354 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2358 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2359 * @vport: lpfc vport structure pointer.
2360 * @val: contains the nodev timeout value.
2363 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2364 * a kernel error message is printed and zero is returned.
2365 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2366 * Otherwise nodev tmo is set to the default value.
2369 * zero if already set or if val is in range
2370 * -EINVAL val out of range
2373 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2375 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2376 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2377 if (val != LPFC_DEF_DEVLOSS_TMO)
2378 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2379 "0407 Ignoring nodev_tmo module "
2380 "parameter because devloss_tmo is "
2385 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2386 vport->cfg_nodev_tmo = val;
2387 vport->cfg_devloss_tmo = val;
2390 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2391 "0400 lpfc_nodev_tmo attribute cannot be set to"
2392 " %d, allowed range is [%d, %d]\n",
2393 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2394 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2399 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2400 * @vport: lpfc vport structure pointer.
2403 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2406 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2408 struct Scsi_Host *shost;
2409 struct lpfc_nodelist *ndlp;
2411 shost = lpfc_shost_from_vport(vport);
2412 spin_lock_irq(shost->host_lock);
2413 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2414 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2415 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2416 spin_unlock_irq(shost->host_lock);
2420 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2421 * @vport: lpfc vport structure pointer.
2422 * @val: contains the tmo value.
2425 * If the devloss tmo is already set or the vport dev loss tmo has changed
2426 * then a kernel error message is printed and zero is returned.
2427 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2428 * Otherwise nodev tmo is set to the default value.
2431 * zero if already set or if val is in range
2432 * -EINVAL val out of range
2435 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2437 if (vport->dev_loss_tmo_changed ||
2438 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2439 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2440 "0401 Ignoring change to nodev_tmo "
2441 "because devloss_tmo is set.\n");
2444 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2445 vport->cfg_nodev_tmo = val;
2446 vport->cfg_devloss_tmo = val;
2448 * For compat: set the fc_host dev loss so new rports
2449 * will get the value.
2451 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2452 lpfc_update_rport_devloss_tmo(vport);
2455 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2456 "0403 lpfc_nodev_tmo attribute cannot be set to"
2457 "%d, allowed range is [%d, %d]\n",
2458 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2462 lpfc_vport_param_store(nodev_tmo)
2464 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2465 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2468 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2469 # disappear until the timer expires. Value range is [0,255]. Default
2472 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2473 MODULE_PARM_DESC(lpfc_devloss_tmo,
2474 "Seconds driver will hold I/O waiting "
2475 "for a device to come back");
2476 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2477 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2478 lpfc_vport_param_show(devloss_tmo)
2481 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2482 * @vport: lpfc vport structure pointer.
2483 * @val: contains the tmo value.
2486 * If val is in a valid range then set the vport nodev tmo,
2487 * devloss tmo, also set the vport dev loss tmo changed flag.
2488 * Else a kernel error message is printed.
2491 * zero if val is in range
2492 * -EINVAL val out of range
2495 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2497 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2498 vport->cfg_nodev_tmo = val;
2499 vport->cfg_devloss_tmo = val;
2500 vport->dev_loss_tmo_changed = 1;
2501 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2502 lpfc_update_rport_devloss_tmo(vport);
2506 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2507 "0404 lpfc_devloss_tmo attribute cannot be set to"
2508 " %d, allowed range is [%d, %d]\n",
2509 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2513 lpfc_vport_param_store(devloss_tmo)
2514 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2515 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2518 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2519 # deluged with LOTS of information.
2520 # You can set a bit mask to record specific types of verbose messages:
2521 # See lpfc_logmsh.h for definitions.
2523 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2524 "Verbose logging bit-mask");
2527 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2528 # objects that have been registered with the nameserver after login.
2530 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2531 "Deregister nameserver objects before LOGO");
2534 # lun_queue_depth: This parameter is used to limit the number of outstanding
2535 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2537 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2538 "Max number of FCP commands we can queue to a specific LUN");
2541 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2542 # commands per target port. Value range is [10,65535]. Default value is 65535.
2544 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2545 "Max number of FCP commands we can queue to a specific target port");
2548 # hba_queue_depth: This parameter is used to limit the number of outstanding
2549 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2550 # value is greater than the maximum number of exchanges supported by the HBA,
2551 # then maximum number of exchanges supported by the HBA is used to determine
2552 # the hba_queue_depth.
2554 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2555 "Max number of FCP commands we can queue to a lpfc HBA");
2558 # peer_port_login: This parameter allows/prevents logins
2559 # between peer ports hosted on the same physical port.
2560 # When this parameter is set 0 peer ports of same physical port
2561 # are not allowed to login to each other.
2562 # When this parameter is set 1 peer ports of same physical port
2563 # are allowed to login to each other.
2564 # Default value of this parameter is 0.
2566 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2567 "Allow peer ports on the same physical port to login to each "
2571 # restrict_login: This parameter allows/prevents logins
2572 # between Virtual Ports and remote initiators.
2573 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2574 # other initiators and will attempt to PLOGI all remote ports.
2575 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2576 # remote ports and will not attempt to PLOGI to other initiators.
2577 # This parameter does not restrict to the physical port.
2578 # This parameter does not restrict logins to Fabric resident remote ports.
2579 # Default value of this parameter is 1.
2581 static int lpfc_restrict_login = 1;
2582 module_param(lpfc_restrict_login, int, S_IRUGO);
2583 MODULE_PARM_DESC(lpfc_restrict_login,
2584 "Restrict virtual ports login to remote initiators.");
2585 lpfc_vport_param_show(restrict_login);
2588 * lpfc_restrict_login_init - Set the vport restrict login flag
2589 * @vport: lpfc vport structure pointer.
2590 * @val: contains the restrict login value.
2593 * If val is not in a valid range then log a kernel error message and set
2594 * the vport restrict login to one.
2595 * If the port type is physical clear the restrict login flag and return.
2596 * Else set the restrict login flag to val.
2599 * zero if val is in range
2600 * -EINVAL val out of range
2603 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2605 if (val < 0 || val > 1) {
2606 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2607 "0422 lpfc_restrict_login attribute cannot "
2608 "be set to %d, allowed range is [0, 1]\n",
2610 vport->cfg_restrict_login = 1;
2613 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2614 vport->cfg_restrict_login = 0;
2617 vport->cfg_restrict_login = val;
2622 * lpfc_restrict_login_set - Set the vport restrict login flag
2623 * @vport: lpfc vport structure pointer.
2624 * @val: contains the restrict login value.
2627 * If val is not in a valid range then log a kernel error message and set
2628 * the vport restrict login to one.
2629 * If the port type is physical and the val is not zero log a kernel
2630 * error message, clear the restrict login flag and return zero.
2631 * Else set the restrict login flag to val.
2634 * zero if val is in range
2635 * -EINVAL val out of range
2638 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2640 if (val < 0 || val > 1) {
2641 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2642 "0425 lpfc_restrict_login attribute cannot "
2643 "be set to %d, allowed range is [0, 1]\n",
2645 vport->cfg_restrict_login = 1;
2648 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2649 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2650 "0468 lpfc_restrict_login must be 0 for "
2651 "Physical ports.\n");
2652 vport->cfg_restrict_login = 0;
2655 vport->cfg_restrict_login = val;
2658 lpfc_vport_param_store(restrict_login);
2659 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2660 lpfc_restrict_login_show, lpfc_restrict_login_store);
2663 # Some disk devices have a "select ID" or "select Target" capability.
2664 # From a protocol standpoint "select ID" usually means select the
2665 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2666 # annex" which contains a table that maps a "select ID" (a number
2667 # between 0 and 7F) to an ALPA. By default, for compatibility with
2668 # older drivers, the lpfc driver scans this table from low ALPA to high
2671 # Turning on the scan-down variable (on = 1, off = 0) will
2672 # cause the lpfc driver to use an inverted table, effectively
2673 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2675 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2676 # and will not work across a fabric. Also this parameter will take
2677 # effect only in the case when ALPA map is not available.)
2679 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2680 "Start scanning for devices from highest ALPA to lowest");
2683 # lpfc_topology: link topology for init link
2684 # 0x0 = attempt loop mode then point-to-point
2685 # 0x01 = internal loopback mode
2686 # 0x02 = attempt point-to-point mode only
2687 # 0x04 = attempt loop mode only
2688 # 0x06 = attempt point-to-point mode then loop
2689 # Set point-to-point mode if you want to run as an N_Port.
2690 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2691 # Default value is 0.
2695 * lpfc_topology_set - Set the adapters topology field
2696 * @phba: lpfc_hba pointer.
2697 * @val: topology value.
2700 * If val is in a valid range then set the adapter's topology field and
2701 * issue a lip; if the lip fails reset the topology to the old value.
2703 * If the value is not in range log a kernel error message and return an error.
2706 * zero if val is in range and lip okay
2707 * non-zero return value from lpfc_issue_lip()
2708 * -EINVAL val out of range
2711 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2712 const char *buf, size_t count)
2714 struct Scsi_Host *shost = class_to_shost(dev);
2715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2716 struct lpfc_hba *phba = vport->phba;
2719 const char *val_buf = buf;
2723 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2725 val_buf = &buf[strlen("nolip ")];
2728 if (!isdigit(val_buf[0]))
2730 if (sscanf(val_buf, "%i", &val) != 1)
2733 if (val >= 0 && val <= 6) {
2734 prev_val = phba->cfg_topology;
2735 phba->cfg_topology = val;
2739 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2740 "3054 lpfc_topology changed from %d to %d\n",
2742 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2744 phba->cfg_topology = prev_val;
2749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2750 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2751 "allowed range is [0, 6]\n",
2755 static int lpfc_topology = 0;
2756 module_param(lpfc_topology, int, S_IRUGO);
2757 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2758 lpfc_param_show(topology)
2759 lpfc_param_init(topology, 0, 0, 6)
2760 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2761 lpfc_topology_show, lpfc_topology_store);
2764 * lpfc_static_vport_show: Read callback function for
2765 * lpfc_static_vport sysfs file.
2766 * @dev: Pointer to class device object.
2767 * @attr: device attribute structure.
2768 * @buf: Data buffer.
2770 * This function is the read call back function for
2771 * lpfc_static_vport sysfs file. The lpfc_static_vport
2772 * sysfs file report the mageability of the vport.
2775 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2778 struct Scsi_Host *shost = class_to_shost(dev);
2779 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2780 if (vport->vport_flag & STATIC_VPORT)
2781 sprintf(buf, "1\n");
2783 sprintf(buf, "0\n");
2789 * Sysfs attribute to control the statistical data collection.
2791 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2792 lpfc_static_vport_show, NULL);
2795 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2796 * @dev: Pointer to class device.
2797 * @buf: Data buffer.
2798 * @count: Size of the data buffer.
2800 * This function get called when an user write to the lpfc_stat_data_ctrl
2801 * sysfs file. This function parse the command written to the sysfs file
2802 * and take appropriate action. These commands are used for controlling
2803 * driver statistical data collection.
2804 * Following are the command this function handles.
2806 * setbucket <bucket_type> <base> <step>
2807 * = Set the latency buckets.
2808 * destroybucket = destroy all the buckets.
2809 * start = start data collection
2810 * stop = stop data collection
2811 * reset = reset the collected data
2814 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2815 const char *buf, size_t count)
2817 struct Scsi_Host *shost = class_to_shost(dev);
2818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2819 struct lpfc_hba *phba = vport->phba;
2820 #define LPFC_MAX_DATA_CTRL_LEN 1024
2821 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2823 char *str_ptr, *token;
2824 struct lpfc_vport **vports;
2825 struct Scsi_Host *v_shost;
2826 char *bucket_type_str, *base_str, *step_str;
2827 unsigned long base, step, bucket_type;
2829 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2830 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2833 strcpy(bucket_data, buf);
2834 str_ptr = &bucket_data[0];
2835 /* Ignore this token - this is command token */
2836 token = strsep(&str_ptr, "\t ");
2840 bucket_type_str = strsep(&str_ptr, "\t ");
2841 if (!bucket_type_str)
2844 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2845 bucket_type = LPFC_LINEAR_BUCKET;
2846 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2847 bucket_type = LPFC_POWER2_BUCKET;
2851 base_str = strsep(&str_ptr, "\t ");
2854 base = simple_strtoul(base_str, NULL, 0);
2856 step_str = strsep(&str_ptr, "\t ");
2859 step = simple_strtoul(step_str, NULL, 0);
2863 /* Block the data collection for every vport */
2864 vports = lpfc_create_vport_work_array(phba);
2868 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2869 v_shost = lpfc_shost_from_vport(vports[i]);
2870 spin_lock_irq(v_shost->host_lock);
2871 /* Block and reset data collection */
2872 vports[i]->stat_data_blocked = 1;
2873 if (vports[i]->stat_data_enabled)
2874 lpfc_vport_reset_stat_data(vports[i]);
2875 spin_unlock_irq(v_shost->host_lock);
2878 /* Set the bucket attributes */
2879 phba->bucket_type = bucket_type;
2880 phba->bucket_base = base;
2881 phba->bucket_step = step;
2883 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2884 v_shost = lpfc_shost_from_vport(vports[i]);
2886 /* Unblock data collection */
2887 spin_lock_irq(v_shost->host_lock);
2888 vports[i]->stat_data_blocked = 0;
2889 spin_unlock_irq(v_shost->host_lock);
2891 lpfc_destroy_vport_work_array(phba, vports);
2895 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2896 vports = lpfc_create_vport_work_array(phba);
2900 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2901 v_shost = lpfc_shost_from_vport(vports[i]);
2902 spin_lock_irq(shost->host_lock);
2903 vports[i]->stat_data_blocked = 1;
2904 lpfc_free_bucket(vport);
2905 vport->stat_data_enabled = 0;
2906 vports[i]->stat_data_blocked = 0;
2907 spin_unlock_irq(shost->host_lock);
2909 lpfc_destroy_vport_work_array(phba, vports);
2910 phba->bucket_type = LPFC_NO_BUCKET;
2911 phba->bucket_base = 0;
2912 phba->bucket_step = 0;
2916 if (!strncmp(buf, "start", strlen("start"))) {
2917 /* If no buckets configured return error */
2918 if (phba->bucket_type == LPFC_NO_BUCKET)
2920 spin_lock_irq(shost->host_lock);
2921 if (vport->stat_data_enabled) {
2922 spin_unlock_irq(shost->host_lock);
2925 lpfc_alloc_bucket(vport);
2926 vport->stat_data_enabled = 1;
2927 spin_unlock_irq(shost->host_lock);
2931 if (!strncmp(buf, "stop", strlen("stop"))) {
2932 spin_lock_irq(shost->host_lock);
2933 if (vport->stat_data_enabled == 0) {
2934 spin_unlock_irq(shost->host_lock);
2937 lpfc_free_bucket(vport);
2938 vport->stat_data_enabled = 0;
2939 spin_unlock_irq(shost->host_lock);
2943 if (!strncmp(buf, "reset", strlen("reset"))) {
2944 if ((phba->bucket_type == LPFC_NO_BUCKET)
2945 || !vport->stat_data_enabled)
2947 spin_lock_irq(shost->host_lock);
2948 vport->stat_data_blocked = 1;
2949 lpfc_vport_reset_stat_data(vport);
2950 vport->stat_data_blocked = 0;
2951 spin_unlock_irq(shost->host_lock);
2959 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2960 * @dev: Pointer to class device object.
2961 * @buf: Data buffer.
2963 * This function is the read call back function for
2964 * lpfc_stat_data_ctrl sysfs file. This function report the
2965 * current statistical data collection state.
2968 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2971 struct Scsi_Host *shost = class_to_shost(dev);
2972 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2973 struct lpfc_hba *phba = vport->phba;
2977 unsigned long bucket_value;
2979 switch (phba->bucket_type) {
2980 case LPFC_LINEAR_BUCKET:
2981 bucket_type = "linear";
2983 case LPFC_POWER2_BUCKET:
2984 bucket_type = "power2";
2987 bucket_type = "No Bucket";
2991 sprintf(&buf[index], "Statistical Data enabled :%d, "
2992 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2993 " Bucket step :%d\nLatency Ranges :",
2994 vport->stat_data_enabled, vport->stat_data_blocked,
2995 bucket_type, phba->bucket_base, phba->bucket_step);
2996 index = strlen(buf);
2997 if (phba->bucket_type != LPFC_NO_BUCKET) {
2998 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2999 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3000 bucket_value = phba->bucket_base +
3001 phba->bucket_step * i;
3003 bucket_value = phba->bucket_base +
3004 (1 << i) * phba->bucket_step;
3006 if (index + 10 > PAGE_SIZE)
3008 sprintf(&buf[index], "%08ld ", bucket_value);
3009 index = strlen(buf);
3012 sprintf(&buf[index], "\n");
3017 * Sysfs attribute to control the statistical data collection.
3019 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3020 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3023 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3027 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3030 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3031 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3032 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3036 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3038 * @kobj: Pointer to the kernel object
3039 * @bin_attr: Attribute object
3040 * @buff: Buffer pointer
3042 * @count: Buffer size
3044 * This function is the read call back function for lpfc_drvr_stat_data
3045 * sysfs file. This function export the statistical data to user
3049 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3050 struct bin_attribute *bin_attr,
3051 char *buf, loff_t off, size_t count)
3053 struct device *dev = container_of(kobj, struct device,
3055 struct Scsi_Host *shost = class_to_shost(dev);
3056 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3057 struct lpfc_hba *phba = vport->phba;
3058 int i = 0, index = 0;
3059 unsigned long nport_index;
3060 struct lpfc_nodelist *ndlp = NULL;
3061 nport_index = (unsigned long)off /
3062 MAX_STAT_DATA_SIZE_PER_TARGET;
3064 if (!vport->stat_data_enabled || vport->stat_data_blocked
3065 || (phba->bucket_type == LPFC_NO_BUCKET))
3068 spin_lock_irq(shost->host_lock);
3069 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3070 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3073 if (nport_index > 0) {
3078 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3082 if (!ndlp->lat_data)
3086 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3087 ndlp->nlp_portname.u.wwn[0],
3088 ndlp->nlp_portname.u.wwn[1],
3089 ndlp->nlp_portname.u.wwn[2],
3090 ndlp->nlp_portname.u.wwn[3],
3091 ndlp->nlp_portname.u.wwn[4],
3092 ndlp->nlp_portname.u.wwn[5],
3093 ndlp->nlp_portname.u.wwn[6],
3094 ndlp->nlp_portname.u.wwn[7]);
3096 index = strlen(buf);
3098 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3099 sprintf(&buf[index], "%010u,",
3100 ndlp->lat_data[i].cmd_count);
3101 index = strlen(buf);
3103 sprintf(&buf[index], "\n");
3104 index = strlen(buf);
3106 spin_unlock_irq(shost->host_lock);
3110 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3112 .name = "lpfc_drvr_stat_data",
3115 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3116 .read = sysfs_drvr_stat_data_read,
3121 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3123 # Value range is [0,16]. Default value is 0.
3126 * lpfc_link_speed_set - Set the adapters link speed
3127 * @phba: lpfc_hba pointer.
3128 * @val: link speed value.
3131 * If val is in a valid range then set the adapter's link speed field and
3132 * issue a lip; if the lip fails reset the link speed to the old value.
3135 * If the value is not in range log a kernel error message and return an error.
3138 * zero if val is in range and lip okay.
3139 * non-zero return value from lpfc_issue_lip()
3140 * -EINVAL val out of range
3143 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3144 const char *buf, size_t count)
3146 struct Scsi_Host *shost = class_to_shost(dev);
3147 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3148 struct lpfc_hba *phba = vport->phba;
3149 int val = LPFC_USER_LINK_SPEED_AUTO;
3151 const char *val_buf = buf;
3155 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3157 val_buf = &buf[strlen("nolip ")];
3160 if (!isdigit(val_buf[0]))
3162 if (sscanf(val_buf, "%i", &val) != 1)
3165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3166 "3055 lpfc_link_speed changed from %d to %d %s\n",
3167 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3169 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3170 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3171 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3172 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3173 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3174 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3175 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3176 "2879 lpfc_link_speed attribute cannot be set "
3177 "to %d. Speed is not supported by this port.\n",
3181 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3182 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3183 prev_val = phba->cfg_link_speed;
3184 phba->cfg_link_speed = val;
3188 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3190 phba->cfg_link_speed = prev_val;
3195 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3196 "0469 lpfc_link_speed attribute cannot be set to %d, "
3197 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3201 static int lpfc_link_speed = 0;
3202 module_param(lpfc_link_speed, int, S_IRUGO);
3203 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3204 lpfc_param_show(link_speed)
3207 * lpfc_link_speed_init - Set the adapters link speed
3208 * @phba: lpfc_hba pointer.
3209 * @val: link speed value.
3212 * If val is in a valid range then set the adapter's link speed field.
3215 * If the value is not in range log a kernel error message, clear the link
3216 * speed and return an error.
3219 * zero if val saved.
3220 * -EINVAL val out of range
3223 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3225 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3226 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3227 phba->cfg_link_speed = val;
3230 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3231 "0405 lpfc_link_speed attribute cannot "
3232 "be set to %d, allowed values are "
3233 "["LPFC_LINK_SPEED_STRING"]\n", val);
3234 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3238 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3239 lpfc_link_speed_show, lpfc_link_speed_store);
3242 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3243 # 0 = aer disabled or not supported
3244 # 1 = aer supported and enabled (default)
3245 # Value range is [0,1]. Default value is 1.
3249 * lpfc_aer_support_store - Set the adapter for aer support
3251 * @dev: class device that is converted into a Scsi_host.
3252 * @attr: device attribute, not used.
3253 * @buf: containing enable or disable aer flag.
3254 * @count: unused variable.
3257 * If the val is 1 and currently the device's AER capability was not
3258 * enabled, invoke the kernel's enable AER helper routine, trying to
3259 * enable the device's AER capability. If the helper routine enabling
3260 * AER returns success, update the device's cfg_aer_support flag to
3261 * indicate AER is supported by the device; otherwise, if the device
3262 * AER capability is already enabled to support AER, then do nothing.
3264 * If the val is 0 and currently the device's AER support was enabled,
3265 * invoke the kernel's disable AER helper routine. After that, update
3266 * the device's cfg_aer_support flag to indicate AER is not supported
3267 * by the device; otherwise, if the device AER capability is already
3268 * disabled from supporting AER, then do nothing.
3271 * length of the buf on success if val is in range the intended mode
3273 * -EINVAL if val out of range or intended mode is not supported.
3276 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3277 const char *buf, size_t count)
3279 struct Scsi_Host *shost = class_to_shost(dev);
3280 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3281 struct lpfc_hba *phba = vport->phba;
3282 int val = 0, rc = -EINVAL;
3284 if (!isdigit(buf[0]))
3286 if (sscanf(buf, "%i", &val) != 1)
3291 if (phba->hba_flag & HBA_AER_ENABLED) {
3292 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3294 spin_lock_irq(&phba->hbalock);
3295 phba->hba_flag &= ~HBA_AER_ENABLED;
3296 spin_unlock_irq(&phba->hbalock);
3297 phba->cfg_aer_support = 0;
3302 phba->cfg_aer_support = 0;
3307 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3308 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3310 spin_lock_irq(&phba->hbalock);
3311 phba->hba_flag |= HBA_AER_ENABLED;
3312 spin_unlock_irq(&phba->hbalock);
3313 phba->cfg_aer_support = 1;
3318 phba->cfg_aer_support = 1;
3329 static int lpfc_aer_support = 1;
3330 module_param(lpfc_aer_support, int, S_IRUGO);
3331 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3332 lpfc_param_show(aer_support)
3335 * lpfc_aer_support_init - Set the initial adapters aer support flag
3336 * @phba: lpfc_hba pointer.
3337 * @val: enable aer or disable aer flag.
3340 * If val is in a valid range [0,1], then set the adapter's initial
3341 * cfg_aer_support field. It will be up to the driver's probe_one
3342 * routine to determine whether the device's AER support can be set
3346 * If the value is not in range log a kernel error message, and
3347 * choose the default value of setting AER support and return.
3350 * zero if val saved.
3351 * -EINVAL val out of range
3354 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3356 if (val == 0 || val == 1) {
3357 phba->cfg_aer_support = val;
3360 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3361 "2712 lpfc_aer_support attribute value %d out "
3362 "of range, allowed values are 0|1, setting it "
3363 "to default value of 1\n", val);
3364 /* By default, try to enable AER on a device */
3365 phba->cfg_aer_support = 1;
3369 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3370 lpfc_aer_support_show, lpfc_aer_support_store);
3373 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3374 * @dev: class device that is converted into a Scsi_host.
3375 * @attr: device attribute, not used.
3376 * @buf: containing flag 1 for aer cleanup state.
3377 * @count: unused variable.
3380 * If the @buf contains 1 and the device currently has the AER support
3381 * enabled, then invokes the kernel AER helper routine
3382 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3383 * error status register.
3388 * -EINVAL if the buf does not contain the 1 or the device is not currently
3389 * enabled with the AER support.
3392 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3393 const char *buf, size_t count)
3395 struct Scsi_Host *shost = class_to_shost(dev);
3396 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3397 struct lpfc_hba *phba = vport->phba;
3400 if (!isdigit(buf[0]))
3402 if (sscanf(buf, "%i", &val) != 1)
3407 if (phba->hba_flag & HBA_AER_ENABLED)
3408 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3416 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3417 lpfc_aer_cleanup_state);
3420 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3422 * @dev: class device that is converted into a Scsi_host.
3423 * @attr: device attribute, not used.
3424 * @buf: containing the string the number of vfs to be enabled.
3425 * @count: unused variable.
3428 * When this api is called either through user sysfs, the driver shall
3429 * try to enable or disable SR-IOV virtual functions according to the
3432 * If zero virtual function has been enabled to the physical function,
3433 * the driver shall invoke the pci enable virtual function api trying
3434 * to enable the virtual functions. If the nr_vfn provided is greater
3435 * than the maximum supported, the maximum virtual function number will
3436 * be used for invoking the api; otherwise, the nr_vfn provided shall
3437 * be used for invoking the api. If the api call returned success, the
3438 * actual number of virtual functions enabled will be set to the driver
3439 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3440 * cfg_sriov_nr_virtfn remains zero.
3442 * If none-zero virtual functions have already been enabled to the
3443 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3444 * -EINVAL will be returned and the driver does nothing;
3446 * If the nr_vfn provided is zero and none-zero virtual functions have
3447 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3448 * disabling virtual function api shall be invoded to disable all the
3449 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3450 * zero. Otherwise, if zero virtual function has been enabled, do
3454 * length of the buf on success if val is in range the intended mode
3456 * -EINVAL if val out of range or intended mode is not supported.
3459 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3460 const char *buf, size_t count)
3462 struct Scsi_Host *shost = class_to_shost(dev);
3463 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3464 struct lpfc_hba *phba = vport->phba;
3465 struct pci_dev *pdev = phba->pcidev;
3466 int val = 0, rc = -EINVAL;
3468 /* Sanity check on user data */
3469 if (!isdigit(buf[0]))
3471 if (sscanf(buf, "%i", &val) != 1)
3476 /* Request disabling virtual functions */
3478 if (phba->cfg_sriov_nr_virtfn > 0) {
3479 pci_disable_sriov(pdev);
3480 phba->cfg_sriov_nr_virtfn = 0;
3485 /* Request enabling virtual functions */
3486 if (phba->cfg_sriov_nr_virtfn > 0) {
3487 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3488 "3018 There are %d virtual functions "
3489 "enabled on physical function.\n",
3490 phba->cfg_sriov_nr_virtfn);
3494 if (val <= LPFC_MAX_VFN_PER_PFN)
3495 phba->cfg_sriov_nr_virtfn = val;
3497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3498 "3019 Enabling %d virtual functions is not "
3503 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3505 phba->cfg_sriov_nr_virtfn = 0;
3513 static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3514 module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3515 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3516 lpfc_param_show(sriov_nr_virtfn)
3519 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3520 * @phba: lpfc_hba pointer.
3521 * @val: link speed value.
3524 * If val is in a valid range [0,255], then set the adapter's initial
3525 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3526 * number shall be used instead. It will be up to the driver's probe_one
3527 * routine to determine whether the device's SR-IOV is supported or not.
3530 * zero if val saved.
3531 * -EINVAL val out of range
3534 lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3536 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3537 phba->cfg_sriov_nr_virtfn = val;
3541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3542 "3017 Enabling %d virtual functions is not "
3546 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3547 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3550 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3551 # Value range is [2,3]. Default value is 3.
3553 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3554 "Select Fibre Channel class of service for FCP sequences");
3557 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3558 # is [0,1]. Default value is 0.
3560 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3561 "Use ADISC on rediscovery to authenticate FCP devices");
3564 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3565 # depth. Default value is 0. When the value of this parameter is zero the
3566 # SCSI command completion time is not used for controlling I/O queue depth. When
3567 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3568 # to limit the I/O completion time to the parameter value.
3569 # The value is set in milliseconds.
3571 static int lpfc_max_scsicmpl_time;
3572 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3573 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3574 "Use command completion time to control queue depth");
3575 lpfc_vport_param_show(max_scsicmpl_time);
3576 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3578 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3581 struct lpfc_nodelist *ndlp, *next_ndlp;
3583 if (val == vport->cfg_max_scsicmpl_time)
3585 if ((val < 0) || (val > 60000))
3587 vport->cfg_max_scsicmpl_time = val;
3589 spin_lock_irq(shost->host_lock);
3590 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3591 if (!NLP_CHK_NODE_ACT(ndlp))
3593 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3595 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3597 spin_unlock_irq(shost->host_lock);
3600 lpfc_vport_param_store(max_scsicmpl_time);
3601 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3602 lpfc_max_scsicmpl_time_show,
3603 lpfc_max_scsicmpl_time_store);
3606 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3607 # range is [0,1]. Default value is 0.
3609 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3612 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3613 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3614 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3615 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3616 # cr_delay is set to 0.
3618 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3619 "interrupt response is generated");
3621 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3622 "interrupt response is generated");
3625 # lpfc_multi_ring_support: Determines how many rings to spread available
3626 # cmd/rsp IOCB entries across.
3627 # Value range is [1,2]. Default value is 1.
3629 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3630 "SLI rings to spread IOCB entries across");
3633 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3634 # identifies what rctl value to configure the additional ring for.
3635 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3637 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3638 255, "Identifies RCTL for additional ring configuration");
3641 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3642 # identifies what type value to configure the additional ring for.
3643 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3645 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3646 255, "Identifies TYPE for additional ring configuration");
3649 # lpfc_fdmi_on: controls FDMI support.
3650 # 0 = no FDMI support
3651 # 1 = support FDMI without attribute of hostname
3652 # 2 = support FDMI with attribute of hostname
3653 # Value range [0,2]. Default value is 0.
3655 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3658 # Specifies the maximum number of ELS cmds we can have outstanding (for
3659 # discovery). Value range is [1,64]. Default value = 32.
3661 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3662 "during discovery");
3665 # lpfc_max_luns: maximum allowed LUN.
3666 # Value range is [0,65535]. Default value is 255.
3667 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3669 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3672 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3673 # Value range is [1,255], default value is 10.
3675 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3676 "Milliseconds driver will wait between polling FCP ring");
3679 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3680 # support this feature
3683 # 2 = MSI-X enabled (default)
3684 # Value range is [0,2]. Default value is 2.
3686 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3687 "MSI-X (2), if possible");
3690 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3692 # Value range is [636,651042]. Default value is 10000.
3694 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3695 "Set the maximum number of fast-path FCP interrupts per second");
3698 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3700 # Value range is [1,31]. Default value is 4.
3702 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3703 "Set the number of fast-path FCP work queues, if possible");
3706 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3708 # Value range is [1,7]. Default value is 1.
3710 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3711 "Set the number of fast-path FCP event queues, if possible");
3714 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3715 # 0 = HBA resets disabled
3716 # 1 = HBA resets enabled (default)
3717 # Value range is [0,1]. Default value is 1.
3719 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3722 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3723 # 0 = HBA Heartbeat disabled
3724 # 1 = HBA Heartbeat enabled (default)
3725 # Value range is [0,1]. Default value is 1.
3727 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3730 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3731 # 0 = BlockGuard disabled (default)
3732 # 1 = BlockGuard enabled
3733 # Value range is [0,1]. Default value is 0.
3735 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3739 # - Bit mask of host protection capabilities used to register with the
3741 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3742 # - Allows you to ultimately specify which profiles to use
3743 # - Default will result in registering capabilities for all profiles.
3746 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3747 SHOST_DIX_TYPE0_PROTECTION |
3748 SHOST_DIX_TYPE1_PROTECTION;
3750 module_param(lpfc_prot_mask, uint, S_IRUGO);
3751 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3754 # lpfc_prot_guard: i
3755 # - Bit mask of protection guard types to register with the SCSI mid-layer
3756 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3757 # - Allows you to ultimately specify which profiles to use
3758 # - Default will result in registering capabilities for all guard types
3761 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3762 module_param(lpfc_prot_guard, byte, S_IRUGO);
3763 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3766 * Delay initial NPort discovery when Clean Address bit is cleared in
3767 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3768 * This parameter can have value 0 or 1.
3769 * When this parameter is set to 0, no delay is added to the initial
3771 * When this parameter is set to non-zero value, initial Nport discovery is
3772 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3773 * accept and FCID/Fabric name/Fabric portname is changed.
3774 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3775 * when Clean Address bit is cleared in FLOGI/FDISC
3776 * accept and FCID/Fabric name/Fabric portname is changed.
3777 * Default value is 0.
3779 int lpfc_delay_discovery;
3780 module_param(lpfc_delay_discovery, int, S_IRUGO);
3781 MODULE_PARM_DESC(lpfc_delay_discovery,
3782 "Delay NPort discovery when Clean Address bit is cleared. "
3783 "Allowed values: 0,1.");
3786 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3787 * This value can be set to values between 64 and 256. The default value is
3788 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3789 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3791 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3792 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3794 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3795 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3796 "Max Protection Scatter Gather Segment Count");
3798 struct device_attribute *lpfc_hba_attrs[] = {
3800 &dev_attr_bg_guard_err,
3801 &dev_attr_bg_apptag_err,
3802 &dev_attr_bg_reftag_err,
3804 &dev_attr_serialnum,
3805 &dev_attr_modeldesc,
3806 &dev_attr_modelname,
3807 &dev_attr_programtype,
3811 &dev_attr_option_rom_version,
3812 &dev_attr_link_state,
3813 &dev_attr_num_discovered_ports,
3814 &dev_attr_menlo_mgmt_mode,
3815 &dev_attr_lpfc_drvr_version,
3816 &dev_attr_lpfc_enable_fip,
3817 &dev_attr_lpfc_temp_sensor,
3818 &dev_attr_lpfc_log_verbose,
3819 &dev_attr_lpfc_lun_queue_depth,
3820 &dev_attr_lpfc_tgt_queue_depth,
3821 &dev_attr_lpfc_hba_queue_depth,
3822 &dev_attr_lpfc_peer_port_login,
3823 &dev_attr_lpfc_nodev_tmo,
3824 &dev_attr_lpfc_devloss_tmo,
3825 &dev_attr_lpfc_fcp_class,
3826 &dev_attr_lpfc_use_adisc,
3827 &dev_attr_lpfc_ack0,
3828 &dev_attr_lpfc_topology,
3829 &dev_attr_lpfc_scan_down,
3830 &dev_attr_lpfc_link_speed,
3831 &dev_attr_lpfc_cr_delay,
3832 &dev_attr_lpfc_cr_count,
3833 &dev_attr_lpfc_multi_ring_support,
3834 &dev_attr_lpfc_multi_ring_rctl,
3835 &dev_attr_lpfc_multi_ring_type,
3836 &dev_attr_lpfc_fdmi_on,
3837 &dev_attr_lpfc_max_luns,
3838 &dev_attr_lpfc_enable_npiv,
3839 &dev_attr_lpfc_enable_rrq,
3840 &dev_attr_nport_evt_cnt,
3841 &dev_attr_board_mode,
3848 &dev_attr_npiv_info,
3849 &dev_attr_issue_reset,
3850 &dev_attr_lpfc_poll,
3851 &dev_attr_lpfc_poll_tmo,
3852 &dev_attr_lpfc_use_msi,
3853 &dev_attr_lpfc_fcp_imax,
3854 &dev_attr_lpfc_fcp_wq_count,
3855 &dev_attr_lpfc_fcp_eq_count,
3856 &dev_attr_lpfc_enable_bg,
3857 &dev_attr_lpfc_soft_wwnn,
3858 &dev_attr_lpfc_soft_wwpn,
3859 &dev_attr_lpfc_soft_wwn_enable,
3860 &dev_attr_lpfc_enable_hba_reset,
3861 &dev_attr_lpfc_enable_hba_heartbeat,
3862 &dev_attr_lpfc_sg_seg_cnt,
3863 &dev_attr_lpfc_max_scsicmpl_time,
3864 &dev_attr_lpfc_stat_data_ctrl,
3865 &dev_attr_lpfc_prot_sg_seg_cnt,
3866 &dev_attr_lpfc_aer_support,
3867 &dev_attr_lpfc_aer_state_cleanup,
3868 &dev_attr_lpfc_sriov_nr_virtfn,
3869 &dev_attr_lpfc_suppress_link_up,
3870 &dev_attr_lpfc_iocb_cnt,
3873 &dev_attr_txcmplq_hw,
3874 &dev_attr_lpfc_fips_level,
3875 &dev_attr_lpfc_fips_rev,
3877 &dev_attr_lpfc_sriov_hw_max_virtfn,
3881 struct device_attribute *lpfc_vport_attrs[] = {
3883 &dev_attr_link_state,
3884 &dev_attr_num_discovered_ports,
3885 &dev_attr_lpfc_drvr_version,
3886 &dev_attr_lpfc_log_verbose,
3887 &dev_attr_lpfc_lun_queue_depth,
3888 &dev_attr_lpfc_tgt_queue_depth,
3889 &dev_attr_lpfc_nodev_tmo,
3890 &dev_attr_lpfc_devloss_tmo,
3891 &dev_attr_lpfc_hba_queue_depth,
3892 &dev_attr_lpfc_peer_port_login,
3893 &dev_attr_lpfc_restrict_login,
3894 &dev_attr_lpfc_fcp_class,
3895 &dev_attr_lpfc_use_adisc,
3896 &dev_attr_lpfc_fdmi_on,
3897 &dev_attr_lpfc_max_luns,
3898 &dev_attr_nport_evt_cnt,
3899 &dev_attr_npiv_info,
3900 &dev_attr_lpfc_enable_da_id,
3901 &dev_attr_lpfc_max_scsicmpl_time,
3902 &dev_attr_lpfc_stat_data_ctrl,
3903 &dev_attr_lpfc_static_vport,
3904 &dev_attr_lpfc_fips_level,
3905 &dev_attr_lpfc_fips_rev,
3910 * sysfs_ctlreg_write - Write method for writing to ctlreg
3911 * @filp: open sysfs file
3912 * @kobj: kernel kobject that contains the kernel class device.
3913 * @bin_attr: kernel attributes passed to us.
3914 * @buf: contains the data to be written to the adapter IOREG space.
3915 * @off: offset into buffer to beginning of data.
3916 * @count: bytes to transfer.
3919 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3920 * Uses the adapter io control registers to send buf contents to the adapter.
3923 * -ERANGE off and count combo out of range
3924 * -EINVAL off, count or buff address invalid
3925 * -EPERM adapter is offline
3926 * value of count, buf contents written
3929 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3930 struct bin_attribute *bin_attr,
3931 char *buf, loff_t off, size_t count)
3934 struct device *dev = container_of(kobj, struct device, kobj);
3935 struct Scsi_Host *shost = class_to_shost(dev);
3936 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3937 struct lpfc_hba *phba = vport->phba;
3939 if (phba->sli_rev >= LPFC_SLI_REV4)
3942 if ((off + count) > FF_REG_AREA_SIZE)
3945 if (count == 0) return 0;
3947 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3950 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3954 spin_lock_irq(&phba->hbalock);
3955 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3956 writel(*((uint32_t *)(buf + buf_off)),
3957 phba->ctrl_regs_memmap_p + off + buf_off);
3959 spin_unlock_irq(&phba->hbalock);
3965 * sysfs_ctlreg_read - Read method for reading from ctlreg
3966 * @filp: open sysfs file
3967 * @kobj: kernel kobject that contains the kernel class device.
3968 * @bin_attr: kernel attributes passed to us.
3969 * @buf: if successful contains the data from the adapter IOREG space.
3970 * @off: offset into buffer to beginning of data.
3971 * @count: bytes to transfer.
3974 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3975 * Uses the adapter io control registers to read data into buf.
3978 * -ERANGE off and count combo out of range
3979 * -EINVAL off, count or buff address invalid
3980 * value of count, buf contents read
3983 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3984 struct bin_attribute *bin_attr,
3985 char *buf, loff_t off, size_t count)
3989 struct device *dev = container_of(kobj, struct device, kobj);
3990 struct Scsi_Host *shost = class_to_shost(dev);
3991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3992 struct lpfc_hba *phba = vport->phba;
3994 if (phba->sli_rev >= LPFC_SLI_REV4)
3997 if (off > FF_REG_AREA_SIZE)
4000 if ((off + count) > FF_REG_AREA_SIZE)
4001 count = FF_REG_AREA_SIZE - off;
4003 if (count == 0) return 0;
4005 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4008 spin_lock_irq(&phba->hbalock);
4010 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4011 tmp_ptr = (uint32_t *)(buf + buf_off);
4012 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4015 spin_unlock_irq(&phba->hbalock);
4020 static struct bin_attribute sysfs_ctlreg_attr = {
4023 .mode = S_IRUSR | S_IWUSR,
4026 .read = sysfs_ctlreg_read,
4027 .write = sysfs_ctlreg_write,
4031 * sysfs_mbox_idle - frees the sysfs mailbox
4032 * @phba: lpfc_hba pointer
4035 sysfs_mbox_idle(struct lpfc_hba *phba)
4037 phba->sysfs_mbox.state = SMBOX_IDLE;
4038 phba->sysfs_mbox.offset = 0;
4040 if (phba->sysfs_mbox.mbox) {
4041 mempool_free(phba->sysfs_mbox.mbox,
4042 phba->mbox_mem_pool);
4043 phba->sysfs_mbox.mbox = NULL;
4048 * sysfs_mbox_write - Write method for writing information via mbox
4049 * @filp: open sysfs file
4050 * @kobj: kernel kobject that contains the kernel class device.
4051 * @bin_attr: kernel attributes passed to us.
4052 * @buf: contains the data to be written to sysfs mbox.
4053 * @off: offset into buffer to beginning of data.
4054 * @count: bytes to transfer.
4057 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4058 * Uses the sysfs mbox to send buf contents to the adapter.
4061 * -ERANGE off and count combo out of range
4062 * -EINVAL off, count or buff address invalid
4063 * zero if count is zero
4064 * -EPERM adapter is offline
4065 * -ENOMEM failed to allocate memory for the mail box
4066 * -EAGAIN offset, state or mbox is NULL
4067 * count number of bytes transferred
4070 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4071 struct bin_attribute *bin_attr,
4072 char *buf, loff_t off, size_t count)
4074 struct device *dev = container_of(kobj, struct device, kobj);
4075 struct Scsi_Host *shost = class_to_shost(dev);
4076 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4077 struct lpfc_hba *phba = vport->phba;
4078 struct lpfcMboxq *mbox = NULL;
4080 if ((count + off) > MAILBOX_CMD_SIZE)
4083 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4090 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4093 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
4096 spin_lock_irq(&phba->hbalock);
4099 if (phba->sysfs_mbox.mbox)
4100 mempool_free(mbox, phba->mbox_mem_pool);
4102 phba->sysfs_mbox.mbox = mbox;
4103 phba->sysfs_mbox.state = SMBOX_WRITING;
4105 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4106 phba->sysfs_mbox.offset != off ||
4107 phba->sysfs_mbox.mbox == NULL) {
4108 sysfs_mbox_idle(phba);
4109 spin_unlock_irq(&phba->hbalock);
4114 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
4117 phba->sysfs_mbox.offset = off + count;
4119 spin_unlock_irq(&phba->hbalock);
4125 * sysfs_mbox_read - Read method for reading information via mbox
4126 * @filp: open sysfs file
4127 * @kobj: kernel kobject that contains the kernel class device.
4128 * @bin_attr: kernel attributes passed to us.
4129 * @buf: contains the data to be read from sysfs mbox.
4130 * @off: offset into buffer to beginning of data.
4131 * @count: bytes to transfer.
4134 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4135 * Uses the sysfs mbox to receive data from to the adapter.
4138 * -ERANGE off greater than mailbox command size
4139 * -EINVAL off, count or buff address invalid
4140 * zero if off and count are zero
4141 * -EACCES adapter over temp
4142 * -EPERM garbage can value to catch a multitude of errors
4143 * -EAGAIN management IO not permitted, state or off error
4144 * -ETIME mailbox timeout
4145 * -ENODEV mailbox error
4146 * count number of bytes transferred
4149 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4150 struct bin_attribute *bin_attr,
4151 char *buf, loff_t off, size_t count)
4153 struct device *dev = container_of(kobj, struct device, kobj);
4154 struct Scsi_Host *shost = class_to_shost(dev);
4155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4156 struct lpfc_hba *phba = vport->phba;
4160 if (off > MAILBOX_CMD_SIZE)
4163 if ((count + off) > MAILBOX_CMD_SIZE)
4164 count = MAILBOX_CMD_SIZE - off;
4166 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4169 if (off && count == 0)
4172 spin_lock_irq(&phba->hbalock);
4174 if (phba->over_temp_state == HBA_OVER_TEMP) {
4175 sysfs_mbox_idle(phba);
4176 spin_unlock_irq(&phba->hbalock);
4181 phba->sysfs_mbox.state == SMBOX_WRITING &&
4182 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
4183 pmb = &phba->sysfs_mbox.mbox->u.mb;
4184 switch (pmb->mbxCommand) {
4188 case MBX_CONFIG_LINK:
4189 case MBX_CONFIG_RING:
4190 case MBX_RESET_RING:
4191 case MBX_UNREG_LOGIN:
4193 case MBX_DUMP_CONTEXT:
4198 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
4199 printk(KERN_WARNING "mbox_read:Command 0x%x "
4200 "is illegal in on-line state\n",
4202 sysfs_mbox_idle(phba);
4203 spin_unlock_irq(&phba->hbalock);
4207 case MBX_WRITE_VPARMS:
4210 case MBX_READ_CONFIG:
4211 case MBX_READ_RCONFIG:
4212 case MBX_READ_STATUS:
4215 case MBX_READ_LNK_STAT:
4216 case MBX_DUMP_MEMORY:
4218 case MBX_UPDATE_CFG:
4219 case MBX_KILL_BOARD:
4221 case MBX_LOAD_EXP_ROM:
4223 case MBX_DEL_LD_ENTRY:
4224 case MBX_SET_VARIABLE:
4226 case MBX_PORT_CAPABILITIES:
4227 case MBX_PORT_IOV_CONTROL:
4229 case MBX_SECURITY_MGMT:
4231 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4232 printk(KERN_WARNING "mbox_read:Command 0x%x "
4233 "is not permitted\n", pmb->mbxCommand);
4234 sysfs_mbox_idle(phba);
4235 spin_unlock_irq(&phba->hbalock);
4239 case MBX_READ_SPARM64:
4240 case MBX_READ_TOPOLOGY:
4242 case MBX_REG_LOGIN64:
4243 case MBX_CONFIG_PORT:
4244 case MBX_RUN_BIU_DIAG:
4245 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
4247 sysfs_mbox_idle(phba);
4248 spin_unlock_irq(&phba->hbalock);
4251 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
4253 sysfs_mbox_idle(phba);
4254 spin_unlock_irq(&phba->hbalock);
4258 /* If HBA encountered an error attention, allow only DUMP
4259 * or RESTART mailbox commands until the HBA is restarted.
4261 if (phba->pport->stopped &&
4262 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4263 pmb->mbxCommand != MBX_RESTART &&
4264 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4265 pmb->mbxCommand != MBX_WRITE_WWN)
4266 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4267 "1259 mbox: Issued mailbox cmd "
4268 "0x%x while in stopped state.\n",
4271 phba->sysfs_mbox.mbox->vport = vport;
4273 /* Don't allow mailbox commands to be sent when blocked
4274 * or when in the middle of discovery
4276 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
4277 sysfs_mbox_idle(phba);
4278 spin_unlock_irq(&phba->hbalock);
4282 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4283 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
4285 spin_unlock_irq(&phba->hbalock);
4286 rc = lpfc_sli_issue_mbox (phba,
4287 phba->sysfs_mbox.mbox,
4289 spin_lock_irq(&phba->hbalock);
4292 spin_unlock_irq(&phba->hbalock);
4293 rc = lpfc_sli_issue_mbox_wait (phba,
4294 phba->sysfs_mbox.mbox,
4295 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
4296 spin_lock_irq(&phba->hbalock);
4299 if (rc != MBX_SUCCESS) {
4300 if (rc == MBX_TIMEOUT) {
4301 phba->sysfs_mbox.mbox = NULL;
4303 sysfs_mbox_idle(phba);
4304 spin_unlock_irq(&phba->hbalock);
4305 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
4307 phba->sysfs_mbox.state = SMBOX_READING;
4309 else if (phba->sysfs_mbox.offset != off ||
4310 phba->sysfs_mbox.state != SMBOX_READING) {
4311 printk(KERN_WARNING "mbox_read: Bad State\n");
4312 sysfs_mbox_idle(phba);
4313 spin_unlock_irq(&phba->hbalock);
4317 memcpy(buf, (uint8_t *) &pmb + off, count);
4319 phba->sysfs_mbox.offset = off + count;
4321 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
4322 sysfs_mbox_idle(phba);
4324 spin_unlock_irq(&phba->hbalock);
4329 static struct bin_attribute sysfs_mbox_attr = {
4332 .mode = S_IRUSR | S_IWUSR,
4334 .size = MAILBOX_SYSFS_MAX,
4335 .read = sysfs_mbox_read,
4336 .write = sysfs_mbox_write,
4340 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
4341 * @vport: address of lpfc vport structure.
4345 * error return code from sysfs_create_bin_file()
4348 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
4350 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4353 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4354 &sysfs_drvr_stat_data_attr);
4356 /* Virtual ports do not need ctrl_reg and mbox */
4357 if (error || vport->port_type == LPFC_NPIV_PORT)
4360 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4361 &sysfs_ctlreg_attr);
4363 goto out_remove_stat_attr;
4365 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4368 goto out_remove_ctlreg_attr;
4371 out_remove_ctlreg_attr:
4372 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4373 out_remove_stat_attr:
4374 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4375 &sysfs_drvr_stat_data_attr);
4381 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4382 * @vport: address of lpfc vport structure.
4385 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4388 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4389 &sysfs_drvr_stat_data_attr);
4390 /* Virtual ports do not need ctrl_reg and mbox */
4391 if (vport->port_type == LPFC_NPIV_PORT)
4393 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4394 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4399 * Dynamic FC Host Attributes Support
4403 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4404 * @shost: kernel scsi host pointer.
4407 lpfc_get_host_port_id(struct Scsi_Host *shost)
4409 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4411 /* note: fc_myDID already in cpu endianness */
4412 fc_host_port_id(shost) = vport->fc_myDID;
4416 * lpfc_get_host_port_type - Set the value of the scsi host port type
4417 * @shost: kernel scsi host pointer.
4420 lpfc_get_host_port_type(struct Scsi_Host *shost)
4422 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4423 struct lpfc_hba *phba = vport->phba;
4425 spin_lock_irq(shost->host_lock);
4427 if (vport->port_type == LPFC_NPIV_PORT) {
4428 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4429 } else if (lpfc_is_link_up(phba)) {
4430 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4431 if (vport->fc_flag & FC_PUBLIC_LOOP)
4432 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4434 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4436 if (vport->fc_flag & FC_FABRIC)
4437 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4439 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4442 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4444 spin_unlock_irq(shost->host_lock);
4448 * lpfc_get_host_port_state - Set the value of the scsi host port state
4449 * @shost: kernel scsi host pointer.
4452 lpfc_get_host_port_state(struct Scsi_Host *shost)
4454 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4455 struct lpfc_hba *phba = vport->phba;
4457 spin_lock_irq(shost->host_lock);
4459 if (vport->fc_flag & FC_OFFLINE_MODE)
4460 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4462 switch (phba->link_state) {
4463 case LPFC_LINK_UNKNOWN:
4464 case LPFC_LINK_DOWN:
4465 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4469 case LPFC_HBA_READY:
4470 /* Links up, beyond this port_type reports state */
4471 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4473 case LPFC_HBA_ERROR:
4474 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4477 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4482 spin_unlock_irq(shost->host_lock);
4486 * lpfc_get_host_speed - Set the value of the scsi host speed
4487 * @shost: kernel scsi host pointer.
4490 lpfc_get_host_speed(struct Scsi_Host *shost)
4492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4493 struct lpfc_hba *phba = vport->phba;
4495 spin_lock_irq(shost->host_lock);
4497 if (lpfc_is_link_up(phba)) {
4498 switch(phba->fc_linkspeed) {
4499 case LPFC_LINK_SPEED_1GHZ:
4500 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4502 case LPFC_LINK_SPEED_2GHZ:
4503 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4505 case LPFC_LINK_SPEED_4GHZ:
4506 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4508 case LPFC_LINK_SPEED_8GHZ:
4509 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4511 case LPFC_LINK_SPEED_10GHZ:
4512 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4514 case LPFC_LINK_SPEED_16GHZ:
4515 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4518 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4522 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4524 spin_unlock_irq(shost->host_lock);
4528 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4529 * @shost: kernel scsi host pointer.
4532 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4535 struct lpfc_hba *phba = vport->phba;
4538 spin_lock_irq(shost->host_lock);
4540 if ((vport->fc_flag & FC_FABRIC) ||
4541 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4542 (vport->fc_flag & FC_PUBLIC_LOOP)))
4543 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4545 /* fabric is local port if there is no F/FL_Port */
4548 spin_unlock_irq(shost->host_lock);
4550 fc_host_fabric_name(shost) = node_name;
4554 * lpfc_get_stats - Return statistical information about the adapter
4555 * @shost: kernel scsi host pointer.
4558 * NULL on error for link down, no mbox pool, sli2 active,
4559 * management not allowed, memory allocation error, or mbox error.
4563 * address of the adapter host statistics
4565 static struct fc_host_statistics *
4566 lpfc_get_stats(struct Scsi_Host *shost)
4568 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4569 struct lpfc_hba *phba = vport->phba;
4570 struct lpfc_sli *psli = &phba->sli;
4571 struct fc_host_statistics *hs = &phba->link_stats;
4572 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4573 LPFC_MBOXQ_t *pmboxq;
4575 unsigned long seconds;
4579 * prevent udev from issuing mailbox commands until the port is
4582 if (phba->link_state < LPFC_LINK_DOWN ||
4583 !phba->mbox_mem_pool ||
4584 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4587 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4590 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4593 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4595 pmb = &pmboxq->u.mb;
4596 pmb->mbxCommand = MBX_READ_STATUS;
4597 pmb->mbxOwner = OWN_HOST;
4598 pmboxq->context1 = NULL;
4599 pmboxq->vport = vport;
4601 if (vport->fc_flag & FC_OFFLINE_MODE)
4602 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4604 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4606 if (rc != MBX_SUCCESS) {
4607 if (rc != MBX_TIMEOUT)
4608 mempool_free(pmboxq, phba->mbox_mem_pool);
4612 memset(hs, 0, sizeof (struct fc_host_statistics));
4614 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4615 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4616 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4617 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4619 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4620 pmb->mbxCommand = MBX_READ_LNK_STAT;
4621 pmb->mbxOwner = OWN_HOST;
4622 pmboxq->context1 = NULL;
4623 pmboxq->vport = vport;
4625 if (vport->fc_flag & FC_OFFLINE_MODE)
4626 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4628 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4630 if (rc != MBX_SUCCESS) {
4631 if (rc != MBX_TIMEOUT)
4632 mempool_free(pmboxq, phba->mbox_mem_pool);
4636 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4637 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4638 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4639 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4640 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4641 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4642 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4644 hs->link_failure_count -= lso->link_failure_count;
4645 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4646 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4647 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4648 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4649 hs->invalid_crc_count -= lso->invalid_crc_count;
4650 hs->error_frames -= lso->error_frames;
4652 if (phba->hba_flag & HBA_FCOE_MODE) {
4654 hs->nos_count = (phba->link_events >> 1);
4655 hs->nos_count -= lso->link_events;
4656 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4657 hs->lip_count = (phba->fc_eventTag >> 1);
4658 hs->lip_count -= lso->link_events;
4662 hs->nos_count = (phba->fc_eventTag >> 1);
4663 hs->nos_count -= lso->link_events;
4666 hs->dumped_frames = -1;
4668 seconds = get_seconds();
4669 if (seconds < psli->stats_start)
4670 hs->seconds_since_last_reset = seconds +
4671 ((unsigned long)-1 - psli->stats_start);
4673 hs->seconds_since_last_reset = seconds - psli->stats_start;
4675 mempool_free(pmboxq, phba->mbox_mem_pool);
4681 * lpfc_reset_stats - Copy the adapter link stats information
4682 * @shost: kernel scsi host pointer.
4685 lpfc_reset_stats(struct Scsi_Host *shost)
4687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4688 struct lpfc_hba *phba = vport->phba;
4689 struct lpfc_sli *psli = &phba->sli;
4690 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4691 LPFC_MBOXQ_t *pmboxq;
4695 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4698 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4701 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4703 pmb = &pmboxq->u.mb;
4704 pmb->mbxCommand = MBX_READ_STATUS;
4705 pmb->mbxOwner = OWN_HOST;
4706 pmb->un.varWords[0] = 0x1; /* reset request */
4707 pmboxq->context1 = NULL;
4708 pmboxq->vport = vport;
4710 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4711 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4712 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4714 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4716 if (rc != MBX_SUCCESS) {
4717 if (rc != MBX_TIMEOUT)
4718 mempool_free(pmboxq, phba->mbox_mem_pool);
4722 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4723 pmb->mbxCommand = MBX_READ_LNK_STAT;
4724 pmb->mbxOwner = OWN_HOST;
4725 pmboxq->context1 = NULL;
4726 pmboxq->vport = vport;
4728 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4729 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4730 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4732 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4734 if (rc != MBX_SUCCESS) {
4735 if (rc != MBX_TIMEOUT)
4736 mempool_free( pmboxq, phba->mbox_mem_pool);
4740 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4741 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4742 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4743 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4744 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4745 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4746 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4747 if (phba->hba_flag & HBA_FCOE_MODE)
4748 lso->link_events = (phba->link_events >> 1);
4750 lso->link_events = (phba->fc_eventTag >> 1);
4752 psli->stats_start = get_seconds();
4754 mempool_free(pmboxq, phba->mbox_mem_pool);
4760 * The LPFC driver treats linkdown handling as target loss events so there
4761 * are no sysfs handlers for link_down_tmo.
4765 * lpfc_get_node_by_target - Return the nodelist for a target
4766 * @starget: kernel scsi target pointer.
4769 * address of the node list if found
4770 * NULL target not found
4772 static struct lpfc_nodelist *
4773 lpfc_get_node_by_target(struct scsi_target *starget)
4775 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4777 struct lpfc_nodelist *ndlp;
4779 spin_lock_irq(shost->host_lock);
4780 /* Search for this, mapped, target ID */
4781 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4782 if (NLP_CHK_NODE_ACT(ndlp) &&
4783 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4784 starget->id == ndlp->nlp_sid) {
4785 spin_unlock_irq(shost->host_lock);
4789 spin_unlock_irq(shost->host_lock);
4794 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4795 * @starget: kernel scsi target pointer.
4798 lpfc_get_starget_port_id(struct scsi_target *starget)
4800 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4802 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4806 * lpfc_get_starget_node_name - Set the target node name
4807 * @starget: kernel scsi target pointer.
4809 * Description: Set the target node name to the ndlp node name wwn or zero.
4812 lpfc_get_starget_node_name(struct scsi_target *starget)
4814 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4816 fc_starget_node_name(starget) =
4817 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4821 * lpfc_get_starget_port_name - Set the target port name
4822 * @starget: kernel scsi target pointer.
4824 * Description: set the target port name to the ndlp port name wwn or zero.
4827 lpfc_get_starget_port_name(struct scsi_target *starget)
4829 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4831 fc_starget_port_name(starget) =
4832 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4836 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4837 * @rport: fc rport address.
4838 * @timeout: new value for dev loss tmo.
4841 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4842 * dev_loss_tmo to one.
4845 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4848 rport->dev_loss_tmo = timeout;
4850 rport->dev_loss_tmo = 1;
4854 * lpfc_rport_show_function - Return rport target information
4857 * Macro that uses field to generate a function with the name lpfc_show_rport_
4859 * lpfc_show_rport_##field: returns the bytes formatted in buf
4860 * @cdev: class converted to an fc_rport.
4861 * @buf: on return contains the target_field or zero.
4863 * Returns: size of formatted string.
4865 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4867 lpfc_show_rport_##field (struct device *dev, \
4868 struct device_attribute *attr, \
4871 struct fc_rport *rport = transport_class_to_rport(dev); \
4872 struct lpfc_rport_data *rdata = rport->hostdata; \
4873 return snprintf(buf, sz, format_string, \
4874 (rdata->target) ? cast rdata->target->field : 0); \
4877 #define lpfc_rport_rd_attr(field, format_string, sz) \
4878 lpfc_rport_show_function(field, format_string, sz, ) \
4879 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4882 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4883 * @fc_vport: The fc_vport who's symbolic name has been changed.
4886 * This function is called by the transport after the @fc_vport's symbolic name
4887 * has been changed. This function re-registers the symbolic name with the
4888 * switch to propagate the change into the fabric if the vport is active.
4891 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4893 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4895 if (vport->port_state == LPFC_VPORT_READY)
4896 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4900 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4901 * @phba: Pointer to lpfc_hba struct.
4903 * This function is called by the lpfc_get_cfgparam() routine to set the
4904 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4905 * log message according to the module's lpfc_log_verbose parameter setting
4906 * before hba port or vport created.
4909 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4911 phba->cfg_log_verbose = verbose;
4914 struct fc_function_template lpfc_transport_functions = {
4915 /* fixed attributes the driver supports */
4916 .show_host_node_name = 1,
4917 .show_host_port_name = 1,
4918 .show_host_supported_classes = 1,
4919 .show_host_supported_fc4s = 1,
4920 .show_host_supported_speeds = 1,
4921 .show_host_maxframe_size = 1,
4922 .show_host_symbolic_name = 1,
4924 /* dynamic attributes the driver supports */
4925 .get_host_port_id = lpfc_get_host_port_id,
4926 .show_host_port_id = 1,
4928 .get_host_port_type = lpfc_get_host_port_type,
4929 .show_host_port_type = 1,
4931 .get_host_port_state = lpfc_get_host_port_state,
4932 .show_host_port_state = 1,
4934 /* active_fc4s is shown but doesn't change (thus no get function) */
4935 .show_host_active_fc4s = 1,
4937 .get_host_speed = lpfc_get_host_speed,
4938 .show_host_speed = 1,
4940 .get_host_fabric_name = lpfc_get_host_fabric_name,
4941 .show_host_fabric_name = 1,
4944 * The LPFC driver treats linkdown handling as target loss events
4945 * so there are no sysfs handlers for link_down_tmo.
4948 .get_fc_host_stats = lpfc_get_stats,
4949 .reset_fc_host_stats = lpfc_reset_stats,
4951 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4952 .show_rport_maxframe_size = 1,
4953 .show_rport_supported_classes = 1,
4955 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4956 .show_rport_dev_loss_tmo = 1,
4958 .get_starget_port_id = lpfc_get_starget_port_id,
4959 .show_starget_port_id = 1,
4961 .get_starget_node_name = lpfc_get_starget_node_name,
4962 .show_starget_node_name = 1,
4964 .get_starget_port_name = lpfc_get_starget_port_name,
4965 .show_starget_port_name = 1,
4967 .issue_fc_host_lip = lpfc_issue_lip,
4968 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4969 .terminate_rport_io = lpfc_terminate_rport_io,
4971 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4973 .vport_disable = lpfc_vport_disable,
4975 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4977 .bsg_request = lpfc_bsg_request,
4978 .bsg_timeout = lpfc_bsg_timeout,
4981 struct fc_function_template lpfc_vport_transport_functions = {
4982 /* fixed attributes the driver supports */
4983 .show_host_node_name = 1,
4984 .show_host_port_name = 1,
4985 .show_host_supported_classes = 1,
4986 .show_host_supported_fc4s = 1,
4987 .show_host_supported_speeds = 1,
4988 .show_host_maxframe_size = 1,
4989 .show_host_symbolic_name = 1,
4991 /* dynamic attributes the driver supports */
4992 .get_host_port_id = lpfc_get_host_port_id,
4993 .show_host_port_id = 1,
4995 .get_host_port_type = lpfc_get_host_port_type,
4996 .show_host_port_type = 1,
4998 .get_host_port_state = lpfc_get_host_port_state,
4999 .show_host_port_state = 1,
5001 /* active_fc4s is shown but doesn't change (thus no get function) */
5002 .show_host_active_fc4s = 1,
5004 .get_host_speed = lpfc_get_host_speed,
5005 .show_host_speed = 1,
5007 .get_host_fabric_name = lpfc_get_host_fabric_name,
5008 .show_host_fabric_name = 1,
5011 * The LPFC driver treats linkdown handling as target loss events
5012 * so there are no sysfs handlers for link_down_tmo.
5015 .get_fc_host_stats = lpfc_get_stats,
5016 .reset_fc_host_stats = lpfc_reset_stats,
5018 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5019 .show_rport_maxframe_size = 1,
5020 .show_rport_supported_classes = 1,
5022 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5023 .show_rport_dev_loss_tmo = 1,
5025 .get_starget_port_id = lpfc_get_starget_port_id,
5026 .show_starget_port_id = 1,
5028 .get_starget_node_name = lpfc_get_starget_node_name,
5029 .show_starget_node_name = 1,
5031 .get_starget_port_name = lpfc_get_starget_port_name,
5032 .show_starget_port_name = 1,
5034 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5035 .terminate_rport_io = lpfc_terminate_rport_io,
5037 .vport_disable = lpfc_vport_disable,
5039 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5043 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
5044 * @phba: lpfc_hba pointer.
5047 lpfc_get_cfgparam(struct lpfc_hba *phba)
5049 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5050 lpfc_cr_count_init(phba, lpfc_cr_count);
5051 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5052 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5053 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5054 lpfc_ack0_init(phba, lpfc_ack0);
5055 lpfc_topology_init(phba, lpfc_topology);
5056 lpfc_link_speed_init(phba, lpfc_link_speed);
5057 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5058 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5059 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5060 lpfc_use_msi_init(phba, lpfc_use_msi);
5061 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5062 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5063 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
5064 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5065 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5066 lpfc_enable_bg_init(phba, lpfc_enable_bg);
5067 if (phba->sli_rev == LPFC_SLI_REV4)
5070 phba->cfg_poll = lpfc_poll;
5071 phba->cfg_soft_wwnn = 0L;
5072 phba->cfg_soft_wwpn = 0L;
5073 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5074 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5075 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5076 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5077 lpfc_aer_support_init(phba, lpfc_aer_support);
5078 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5079 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5080 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5081 phba->cfg_enable_dss = 1;
5086 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5087 * @vport: lpfc_vport pointer.
5090 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5092 lpfc_log_verbose_init(vport, lpfc_log_verbose);
5093 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5094 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5095 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5096 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5097 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5098 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5099 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5100 lpfc_use_adisc_init(vport, lpfc_use_adisc);
5101 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5102 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5103 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5104 lpfc_max_luns_init(vport, lpfc_max_luns);
5105 lpfc_scan_down_init(vport, lpfc_scan_down);
5106 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);