1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/aer.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_tcq.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_version.h"
45 #include "lpfc_compat.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
49 #define LPFC_DEF_DEVLOSS_TMO 30
50 #define LPFC_MIN_DEVLOSS_TMO 1
51 #define LPFC_MAX_DEVLOSS_TMO 255
53 #define LPFC_MAX_LINK_SPEED 8
54 #define LPFC_LINK_SPEED_BITMAP 0x00000117
55 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
58 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
59 * @incr: integer to convert.
60 * @hdw: ascii string holding converted integer plus a string terminator.
63 * JEDEC Joint Electron Device Engineering Council.
64 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
65 * character string. The string is then terminated with a NULL in byte 9.
66 * Hex 0-9 becomes ascii '0' to '9'.
67 * Hex a-f becomes ascii '=' to 'B' capital B.
70 * Coded for 32 bit integers only.
73 lpfc_jedec_to_ascii(int incr, char hdw[])
76 for (i = 0; i < 8; i++) {
79 hdw[7 - i] = 0x30 + j;
81 hdw[7 - i] = 0x61 + j - 10;
89 * lpfc_drvr_version_show - Return the Emulex driver string with version number
90 * @dev: class unused variable.
91 * @attr: device attribute, not used.
92 * @buf: on return contains the module description text.
94 * Returns: size of formatted string.
97 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
100 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
104 * lpfc_enable_fip_show - Return the fip mode of the HBA
105 * @dev: class unused variable.
106 * @attr: device attribute, not used.
107 * @buf: on return contains the module description text.
109 * Returns: size of formatted string.
112 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
115 struct Scsi_Host *shost = class_to_shost(dev);
116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
117 struct lpfc_hba *phba = vport->phba;
119 if (phba->hba_flag & HBA_FIP_SUPPORT)
120 return snprintf(buf, PAGE_SIZE, "1\n");
122 return snprintf(buf, PAGE_SIZE, "0\n");
126 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
129 struct Scsi_Host *shost = class_to_shost(dev);
130 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
131 struct lpfc_hba *phba = vport->phba;
133 if (phba->cfg_enable_bg)
134 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
135 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
137 return snprintf(buf, PAGE_SIZE,
138 "BlockGuard Not Supported\n");
140 return snprintf(buf, PAGE_SIZE,
141 "BlockGuard Disabled\n");
145 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
148 struct Scsi_Host *shost = class_to_shost(dev);
149 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
150 struct lpfc_hba *phba = vport->phba;
152 return snprintf(buf, PAGE_SIZE, "%llu\n",
153 (unsigned long long)phba->bg_guard_err_cnt);
157 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
160 struct Scsi_Host *shost = class_to_shost(dev);
161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
162 struct lpfc_hba *phba = vport->phba;
164 return snprintf(buf, PAGE_SIZE, "%llu\n",
165 (unsigned long long)phba->bg_apptag_err_cnt);
169 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
172 struct Scsi_Host *shost = class_to_shost(dev);
173 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
174 struct lpfc_hba *phba = vport->phba;
176 return snprintf(buf, PAGE_SIZE, "%llu\n",
177 (unsigned long long)phba->bg_reftag_err_cnt);
181 * lpfc_info_show - Return some pci info about the host in ascii
182 * @dev: class converted to a Scsi_host structure.
183 * @attr: device attribute, not used.
184 * @buf: on return contains the formatted text from lpfc_info().
186 * Returns: size of formatted string.
189 lpfc_info_show(struct device *dev, struct device_attribute *attr,
192 struct Scsi_Host *host = class_to_shost(dev);
194 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
198 * lpfc_serialnum_show - Return the hba serial number in ascii
199 * @dev: class converted to a Scsi_host structure.
200 * @attr: device attribute, not used.
201 * @buf: on return contains the formatted text serial number.
203 * Returns: size of formatted string.
206 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
209 struct Scsi_Host *shost = class_to_shost(dev);
210 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
211 struct lpfc_hba *phba = vport->phba;
213 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
217 * lpfc_temp_sensor_show - Return the temperature sensor level
218 * @dev: class converted to a Scsi_host structure.
219 * @attr: device attribute, not used.
220 * @buf: on return contains the formatted support level.
223 * Returns a number indicating the temperature sensor level currently
224 * supported, zero or one in ascii.
226 * Returns: size of formatted string.
229 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
232 struct Scsi_Host *shost = class_to_shost(dev);
233 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
234 struct lpfc_hba *phba = vport->phba;
235 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
239 * lpfc_modeldesc_show - Return the model description of the hba
240 * @dev: class converted to a Scsi_host structure.
241 * @attr: device attribute, not used.
242 * @buf: on return contains the scsi vpd model description.
244 * Returns: size of formatted string.
247 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
250 struct Scsi_Host *shost = class_to_shost(dev);
251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
252 struct lpfc_hba *phba = vport->phba;
254 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
258 * lpfc_modelname_show - Return the model name of the hba
259 * @dev: class converted to a Scsi_host structure.
260 * @attr: device attribute, not used.
261 * @buf: on return contains the scsi vpd model name.
263 * Returns: size of formatted string.
266 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
269 struct Scsi_Host *shost = class_to_shost(dev);
270 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
271 struct lpfc_hba *phba = vport->phba;
273 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
277 * lpfc_programtype_show - Return the program type of the hba
278 * @dev: class converted to a Scsi_host structure.
279 * @attr: device attribute, not used.
280 * @buf: on return contains the scsi vpd program type.
282 * Returns: size of formatted string.
285 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
288 struct Scsi_Host *shost = class_to_shost(dev);
289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
290 struct lpfc_hba *phba = vport->phba;
292 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
296 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
297 * @dev: class converted to a Scsi_host structure.
298 * @attr: device attribute, not used.
299 * @buf: on return contains the Menlo Maintenance sli flag.
301 * Returns: size of formatted string.
304 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
306 struct Scsi_Host *shost = class_to_shost(dev);
307 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
308 struct lpfc_hba *phba = vport->phba;
310 return snprintf(buf, PAGE_SIZE, "%d\n",
311 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
315 * lpfc_vportnum_show - Return the port number in ascii of the hba
316 * @dev: class converted to a Scsi_host structure.
317 * @attr: device attribute, not used.
318 * @buf: on return contains scsi vpd program type.
320 * Returns: size of formatted string.
323 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
326 struct Scsi_Host *shost = class_to_shost(dev);
327 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
328 struct lpfc_hba *phba = vport->phba;
330 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
334 * lpfc_fwrev_show - Return the firmware rev running in the hba
335 * @dev: class converted to a Scsi_host structure.
336 * @attr: device attribute, not used.
337 * @buf: on return contains the scsi vpd program type.
339 * Returns: size of formatted string.
342 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
345 struct Scsi_Host *shost = class_to_shost(dev);
346 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
347 struct lpfc_hba *phba = vport->phba;
350 lpfc_decode_firmware_rev(phba, fwrev, 1);
351 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
355 * lpfc_hdw_show - Return the jedec information about the hba
356 * @dev: class converted to a Scsi_host structure.
357 * @attr: device attribute, not used.
358 * @buf: on return contains the scsi vpd program type.
360 * Returns: size of formatted string.
363 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
366 struct Scsi_Host *shost = class_to_shost(dev);
367 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
368 struct lpfc_hba *phba = vport->phba;
369 lpfc_vpd_t *vp = &phba->vpd;
371 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
372 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
376 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
377 * @dev: class converted to a Scsi_host structure.
378 * @attr: device attribute, not used.
379 * @buf: on return contains the ROM and FCode ascii strings.
381 * Returns: size of formatted string.
384 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
387 struct Scsi_Host *shost = class_to_shost(dev);
388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
389 struct lpfc_hba *phba = vport->phba;
391 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
395 * lpfc_state_show - Return the link state of the port
396 * @dev: class converted to a Scsi_host structure.
397 * @attr: device attribute, not used.
398 * @buf: on return contains text describing the state of the link.
401 * The switch statement has no default so zero will be returned.
403 * Returns: size of formatted string.
406 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
409 struct Scsi_Host *shost = class_to_shost(dev);
410 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
411 struct lpfc_hba *phba = vport->phba;
414 switch (phba->link_state) {
415 case LPFC_LINK_UNKNOWN:
416 case LPFC_WARM_START:
417 case LPFC_INIT_START:
418 case LPFC_INIT_MBX_CMDS:
421 if (phba->hba_flag & LINK_DISABLED)
422 len += snprintf(buf + len, PAGE_SIZE-len,
423 "Link Down - User disabled\n");
425 len += snprintf(buf + len, PAGE_SIZE-len,
431 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
433 switch (vport->port_state) {
434 case LPFC_LOCAL_CFG_LINK:
435 len += snprintf(buf + len, PAGE_SIZE-len,
436 "Configuring Link\n");
440 case LPFC_FABRIC_CFG_LINK:
443 case LPFC_BUILD_DISC_LIST:
445 len += snprintf(buf + len, PAGE_SIZE - len,
448 case LPFC_VPORT_READY:
449 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
452 case LPFC_VPORT_FAILED:
453 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
456 case LPFC_VPORT_UNKNOWN:
457 len += snprintf(buf + len, PAGE_SIZE - len,
461 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
462 len += snprintf(buf + len, PAGE_SIZE-len,
463 " Menlo Maint Mode\n");
464 else if (phba->fc_topology == TOPOLOGY_LOOP) {
465 if (vport->fc_flag & FC_PUBLIC_LOOP)
466 len += snprintf(buf + len, PAGE_SIZE-len,
469 len += snprintf(buf + len, PAGE_SIZE-len,
472 if (vport->fc_flag & FC_FABRIC)
473 len += snprintf(buf + len, PAGE_SIZE-len,
476 len += snprintf(buf + len, PAGE_SIZE-len,
485 * lpfc_link_state_store - Transition the link_state on an HBA port
486 * @dev: class device that is converted into a Scsi_host.
487 * @attr: device attribute, not used.
488 * @buf: one or more lpfc_polling_flags values.
492 * -EINVAL if the buffer is not "up" or "down"
493 * return from link state change function if non-zero
494 * length of the buf on success
497 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
498 const char *buf, size_t count)
500 struct Scsi_Host *shost = class_to_shost(dev);
501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
502 struct lpfc_hba *phba = vport->phba;
504 int status = -EINVAL;
506 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
507 (phba->link_state == LPFC_LINK_DOWN))
508 status = phba->lpfc_hba_init_link(phba);
509 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
510 (phba->link_state >= LPFC_LINK_UP))
511 status = phba->lpfc_hba_down_link(phba);
520 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
521 * @dev: class device that is converted into a Scsi_host.
522 * @attr: device attribute, not used.
523 * @buf: on return contains the sum of fc mapped and unmapped.
526 * Returns the ascii text number of the sum of the fc mapped and unmapped
529 * Returns: size of formatted string.
532 lpfc_num_discovered_ports_show(struct device *dev,
533 struct device_attribute *attr, char *buf)
535 struct Scsi_Host *shost = class_to_shost(dev);
536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
538 return snprintf(buf, PAGE_SIZE, "%d\n",
539 vport->fc_map_cnt + vport->fc_unmap_cnt);
543 * lpfc_issue_lip - Misnomer, name carried over from long ago
544 * @shost: Scsi_Host pointer.
547 * Bring the link down gracefully then re-init the link. The firmware will
548 * re-init the fiber channel interface as required. Does not issue a LIP.
551 * -EPERM port offline or management commands are being blocked
552 * -ENOMEM cannot allocate memory for the mailbox command
553 * -EIO error sending the mailbox command
557 lpfc_issue_lip(struct Scsi_Host *shost)
559 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
560 struct lpfc_hba *phba = vport->phba;
561 LPFC_MBOXQ_t *pmboxq;
562 int mbxstatus = MBXERR_ERROR;
564 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
565 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
568 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
573 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
574 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
575 pmboxq->u.mb.mbxOwner = OWN_HOST;
577 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
579 if ((mbxstatus == MBX_SUCCESS) &&
580 (pmboxq->u.mb.mbxStatus == 0 ||
581 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
582 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
583 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
584 phba->cfg_link_speed);
585 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
589 lpfc_set_loopback_flag(phba);
590 if (mbxstatus != MBX_TIMEOUT)
591 mempool_free(pmboxq, phba->mbox_mem_pool);
593 if (mbxstatus == MBXERR_ERROR)
600 * lpfc_do_offline - Issues a mailbox command to bring the link down
601 * @phba: lpfc_hba pointer.
602 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
605 * Assumes any error from lpfc_do_offline() will be negative.
606 * Can wait up to 5 seconds for the port ring buffers count
607 * to reach zero, prints a warning if it is not zero and continues.
608 * lpfc_workq_post_event() returns a non-zero return code if call fails.
611 * -EIO error posting the event
615 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
617 struct completion online_compl;
618 struct lpfc_sli_ring *pring;
619 struct lpfc_sli *psli;
624 init_completion(&online_compl);
625 lpfc_workq_post_event(phba, &status, &online_compl,
626 LPFC_EVT_OFFLINE_PREP);
627 wait_for_completion(&online_compl);
634 /* Wait a little for things to settle down, but not
635 * long enough for dev loss timeout to expire.
637 for (i = 0; i < psli->num_rings; i++) {
638 pring = &psli->ring[i];
639 while (pring->txcmplq_cnt) {
641 if (cnt++ > 500) { /* 5 secs */
642 lpfc_printf_log(phba,
643 KERN_WARNING, LOG_INIT,
644 "0466 Outstanding IO when "
645 "bringing Adapter offline\n");
651 init_completion(&online_compl);
652 lpfc_workq_post_event(phba, &status, &online_compl, type);
653 wait_for_completion(&online_compl);
662 * lpfc_selective_reset - Offline then onlines the port
663 * @phba: lpfc_hba pointer.
666 * If the port is configured to allow a reset then the hba is brought
667 * offline then online.
670 * Assumes any error from lpfc_do_offline() will be negative.
673 * lpfc_do_offline() return code if not zero
674 * -EIO reset not configured or error posting the event
678 lpfc_selective_reset(struct lpfc_hba *phba)
680 struct completion online_compl;
683 if (!phba->cfg_enable_hba_reset)
686 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
691 init_completion(&online_compl);
692 lpfc_workq_post_event(phba, &status, &online_compl,
694 wait_for_completion(&online_compl);
703 * lpfc_issue_reset - Selectively resets an adapter
704 * @dev: class device that is converted into a Scsi_host.
705 * @attr: device attribute, not used.
706 * @buf: containing the string "selective".
707 * @count: unused variable.
710 * If the buf contains the string "selective" then lpfc_selective_reset()
711 * is called to perform the reset.
714 * Assumes any error from lpfc_selective_reset() will be negative.
715 * If lpfc_selective_reset() returns zero then the length of the buffer
716 * is returned which indicates success
719 * -EINVAL if the buffer does not contain the string "selective"
720 * length of buf if lpfc-selective_reset() if the call succeeds
721 * return value of lpfc_selective_reset() if the call fails
724 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
725 const char *buf, size_t count)
727 struct Scsi_Host *shost = class_to_shost(dev);
728 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
729 struct lpfc_hba *phba = vport->phba;
731 int status = -EINVAL;
733 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
734 status = lpfc_selective_reset(phba);
743 * lpfc_nport_evt_cnt_show - Return the number of nport events
744 * @dev: class device that is converted into a Scsi_host.
745 * @attr: device attribute, not used.
746 * @buf: on return contains the ascii number of nport events.
748 * Returns: size of formatted string.
751 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
754 struct Scsi_Host *shost = class_to_shost(dev);
755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
756 struct lpfc_hba *phba = vport->phba;
758 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
762 * lpfc_board_mode_show - Return the state of the board
763 * @dev: class device that is converted into a Scsi_host.
764 * @attr: device attribute, not used.
765 * @buf: on return contains the state of the adapter.
767 * Returns: size of formatted string.
770 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
773 struct Scsi_Host *shost = class_to_shost(dev);
774 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
775 struct lpfc_hba *phba = vport->phba;
778 if (phba->link_state == LPFC_HBA_ERROR)
780 else if (phba->link_state == LPFC_WARM_START)
781 state = "warm start";
782 else if (phba->link_state == LPFC_INIT_START)
787 return snprintf(buf, PAGE_SIZE, "%s\n", state);
791 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
792 * @dev: class device that is converted into a Scsi_host.
793 * @attr: device attribute, not used.
794 * @buf: containing one of the strings "online", "offline", "warm" or "error".
795 * @count: unused variable.
798 * -EACCES if enable hba reset not enabled
799 * -EINVAL if the buffer does not contain a valid string (see above)
800 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
801 * buf length greater than zero indicates success
804 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
805 const char *buf, size_t count)
807 struct Scsi_Host *shost = class_to_shost(dev);
808 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
809 struct lpfc_hba *phba = vport->phba;
810 struct completion online_compl;
813 if (!phba->cfg_enable_hba_reset)
815 init_completion(&online_compl);
817 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
818 lpfc_workq_post_event(phba, &status, &online_compl,
820 wait_for_completion(&online_compl);
821 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
822 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
823 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
824 if (phba->sli_rev == LPFC_SLI_REV4)
827 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
828 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
829 if (phba->sli_rev == LPFC_SLI_REV4)
832 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
843 * lpfc_get_hba_info - Return various bits of informaton about the adapter
844 * @phba: pointer to the adapter structure.
845 * @mxri: max xri count.
846 * @axri: available xri count.
847 * @mrpi: max rpi count.
848 * @arpi: available rpi count.
849 * @mvpi: max vpi count.
850 * @avpi: available vpi count.
853 * If an integer pointer for an count is not null then the value for the
861 lpfc_get_hba_info(struct lpfc_hba *phba,
862 uint32_t *mxri, uint32_t *axri,
863 uint32_t *mrpi, uint32_t *arpi,
864 uint32_t *mvpi, uint32_t *avpi)
866 struct lpfc_sli *psli = &phba->sli;
867 struct lpfc_mbx_read_config *rd_config;
868 LPFC_MBOXQ_t *pmboxq;
873 * prevent udev from issuing mailbox commands until the port is
876 if (phba->link_state < LPFC_LINK_DOWN ||
877 !phba->mbox_mem_pool ||
878 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
881 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
884 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
887 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
890 pmb->mbxCommand = MBX_READ_CONFIG;
891 pmb->mbxOwner = OWN_HOST;
892 pmboxq->context1 = NULL;
894 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
895 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
896 rc = MBX_NOT_FINISHED;
898 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
900 if (rc != MBX_SUCCESS) {
901 if (rc != MBX_TIMEOUT)
902 mempool_free(pmboxq, phba->mbox_mem_pool);
906 if (phba->sli_rev == LPFC_SLI_REV4) {
907 rd_config = &pmboxq->u.mqe.un.rd_config;
909 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
911 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
912 phba->sli4_hba.max_cfg_param.rpi_used;
914 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
916 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
917 phba->sli4_hba.max_cfg_param.xri_used;
919 *mvpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
921 *avpi = bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) -
922 phba->sli4_hba.max_cfg_param.vpi_used;
925 *mrpi = pmb->un.varRdConfig.max_rpi;
927 *arpi = pmb->un.varRdConfig.avail_rpi;
929 *mxri = pmb->un.varRdConfig.max_xri;
931 *axri = pmb->un.varRdConfig.avail_xri;
933 *mvpi = pmb->un.varRdConfig.max_vpi;
935 *avpi = pmb->un.varRdConfig.avail_vpi;
938 mempool_free(pmboxq, phba->mbox_mem_pool);
943 * lpfc_max_rpi_show - Return maximum rpi
944 * @dev: class device that is converted into a Scsi_host.
945 * @attr: device attribute, not used.
946 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
949 * Calls lpfc_get_hba_info() asking for just the mrpi count.
950 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
951 * to "Unknown" and the buffer length is returned, therefore the caller
952 * must check for "Unknown" in the buffer to detect a failure.
954 * Returns: size of formatted string.
957 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
960 struct Scsi_Host *shost = class_to_shost(dev);
961 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
962 struct lpfc_hba *phba = vport->phba;
965 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
966 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
967 return snprintf(buf, PAGE_SIZE, "Unknown\n");
971 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
972 * @dev: class device that is converted into a Scsi_host.
973 * @attr: device attribute, not used.
974 * @buf: containing the used rpi count in decimal or "Unknown".
977 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
978 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
979 * to "Unknown" and the buffer length is returned, therefore the caller
980 * must check for "Unknown" in the buffer to detect a failure.
982 * Returns: size of formatted string.
985 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
988 struct Scsi_Host *shost = class_to_shost(dev);
989 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
990 struct lpfc_hba *phba = vport->phba;
993 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
994 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
995 return snprintf(buf, PAGE_SIZE, "Unknown\n");
999 * lpfc_max_xri_show - Return maximum xri
1000 * @dev: class device that is converted into a Scsi_host.
1001 * @attr: device attribute, not used.
1002 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1005 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1006 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1007 * to "Unknown" and the buffer length is returned, therefore the caller
1008 * must check for "Unknown" in the buffer to detect a failure.
1010 * Returns: size of formatted string.
1013 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1016 struct Scsi_Host *shost = class_to_shost(dev);
1017 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1018 struct lpfc_hba *phba = vport->phba;
1021 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1022 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1023 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1027 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1028 * @dev: class device that is converted into a Scsi_host.
1029 * @attr: device attribute, not used.
1030 * @buf: on return contains the used xri count in decimal or "Unknown".
1033 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1034 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1035 * to "Unknown" and the buffer length is returned, therefore the caller
1036 * must check for "Unknown" in the buffer to detect a failure.
1038 * Returns: size of formatted string.
1041 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1044 struct Scsi_Host *shost = class_to_shost(dev);
1045 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1046 struct lpfc_hba *phba = vport->phba;
1049 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1050 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1051 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1055 * lpfc_max_vpi_show - Return maximum vpi
1056 * @dev: class device that is converted into a Scsi_host.
1057 * @attr: device attribute, not used.
1058 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1061 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1062 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1063 * to "Unknown" and the buffer length is returned, therefore the caller
1064 * must check for "Unknown" in the buffer to detect a failure.
1066 * Returns: size of formatted string.
1069 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1072 struct Scsi_Host *shost = class_to_shost(dev);
1073 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1074 struct lpfc_hba *phba = vport->phba;
1077 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1078 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1079 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1083 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1084 * @dev: class device that is converted into a Scsi_host.
1085 * @attr: device attribute, not used.
1086 * @buf: on return contains the used vpi count in decimal or "Unknown".
1089 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1090 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1091 * to "Unknown" and the buffer length is returned, therefore the caller
1092 * must check for "Unknown" in the buffer to detect a failure.
1094 * Returns: size of formatted string.
1097 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1100 struct Scsi_Host *shost = class_to_shost(dev);
1101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1102 struct lpfc_hba *phba = vport->phba;
1105 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1106 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1107 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1111 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1112 * @dev: class device that is converted into a Scsi_host.
1113 * @attr: device attribute, not used.
1114 * @buf: text that must be interpreted to determine if npiv is supported.
1117 * Buffer will contain text indicating npiv is not suppoerted on the port,
1118 * the port is an NPIV physical port, or it is an npiv virtual port with
1119 * the id of the vport.
1121 * Returns: size of formatted string.
1124 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1127 struct Scsi_Host *shost = class_to_shost(dev);
1128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1129 struct lpfc_hba *phba = vport->phba;
1131 if (!(phba->max_vpi))
1132 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1133 if (vport->port_type == LPFC_PHYSICAL_PORT)
1134 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1135 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1139 * lpfc_poll_show - Return text about poll support for the adapter
1140 * @dev: class device that is converted into a Scsi_host.
1141 * @attr: device attribute, not used.
1142 * @buf: on return contains the cfg_poll in hex.
1145 * cfg_poll should be a lpfc_polling_flags type.
1147 * Returns: size of formatted string.
1150 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1153 struct Scsi_Host *shost = class_to_shost(dev);
1154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1155 struct lpfc_hba *phba = vport->phba;
1157 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1161 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1162 * @dev: class device that is converted into a Scsi_host.
1163 * @attr: device attribute, not used.
1164 * @buf: one or more lpfc_polling_flags values.
1168 * buf contents converted to integer and checked for a valid value.
1171 * -EINVAL if the buffer connot be converted or is out of range
1172 * length of the buf on success
1175 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1176 const char *buf, size_t count)
1178 struct Scsi_Host *shost = class_to_shost(dev);
1179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1180 struct lpfc_hba *phba = vport->phba;
1185 if (!isdigit(buf[0]))
1188 if (sscanf(buf, "%i", &val) != 1)
1191 if ((val & 0x3) != val)
1194 if (phba->sli_rev == LPFC_SLI_REV4)
1197 spin_lock_irq(&phba->hbalock);
1199 old_val = phba->cfg_poll;
1201 if (val & ENABLE_FCP_RING_POLLING) {
1202 if ((val & DISABLE_FCP_RING_INT) &&
1203 !(old_val & DISABLE_FCP_RING_INT)) {
1204 creg_val = readl(phba->HCregaddr);
1205 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1206 writel(creg_val, phba->HCregaddr);
1207 readl(phba->HCregaddr); /* flush */
1209 lpfc_poll_start_timer(phba);
1211 } else if (val != 0x0) {
1212 spin_unlock_irq(&phba->hbalock);
1216 if (!(val & DISABLE_FCP_RING_INT) &&
1217 (old_val & DISABLE_FCP_RING_INT))
1219 spin_unlock_irq(&phba->hbalock);
1220 del_timer(&phba->fcp_poll_timer);
1221 spin_lock_irq(&phba->hbalock);
1222 creg_val = readl(phba->HCregaddr);
1223 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1224 writel(creg_val, phba->HCregaddr);
1225 readl(phba->HCregaddr); /* flush */
1228 phba->cfg_poll = val;
1230 spin_unlock_irq(&phba->hbalock);
1236 * lpfc_param_show - Return a cfg attribute value in decimal
1239 * Macro that given an attr e.g. hba_queue_depth expands
1240 * into a function with the name lpfc_hba_queue_depth_show.
1242 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1243 * @dev: class device that is converted into a Scsi_host.
1244 * @attr: device attribute, not used.
1245 * @buf: on return contains the attribute value in decimal.
1247 * Returns: size of formatted string.
1249 #define lpfc_param_show(attr) \
1251 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1254 struct Scsi_Host *shost = class_to_shost(dev);\
1255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1256 struct lpfc_hba *phba = vport->phba;\
1258 val = phba->cfg_##attr;\
1259 return snprintf(buf, PAGE_SIZE, "%d\n",\
1264 * lpfc_param_hex_show - Return a cfg attribute value in hex
1267 * Macro that given an attr e.g. hba_queue_depth expands
1268 * into a function with the name lpfc_hba_queue_depth_show
1270 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1271 * @dev: class device that is converted into a Scsi_host.
1272 * @attr: device attribute, not used.
1273 * @buf: on return contains the attribute value in hexadecimal.
1275 * Returns: size of formatted string.
1277 #define lpfc_param_hex_show(attr) \
1279 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1282 struct Scsi_Host *shost = class_to_shost(dev);\
1283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1284 struct lpfc_hba *phba = vport->phba;\
1286 val = phba->cfg_##attr;\
1287 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1292 * lpfc_param_init - Intializes a cfg attribute
1295 * Macro that given an attr e.g. hba_queue_depth expands
1296 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1297 * takes a default argument, a minimum and maximum argument.
1299 * lpfc_##attr##_init: Initializes an attribute.
1300 * @phba: pointer the the adapter structure.
1301 * @val: integer attribute value.
1303 * Validates the min and max values then sets the adapter config field
1304 * accordingly, or uses the default if out of range and prints an error message.
1308 * -EINVAL if default used
1310 #define lpfc_param_init(attr, default, minval, maxval) \
1312 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1314 if (val >= minval && val <= maxval) {\
1315 phba->cfg_##attr = val;\
1318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1319 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1320 "allowed range is ["#minval", "#maxval"]\n", val); \
1321 phba->cfg_##attr = default;\
1326 * lpfc_param_set - Set a cfg attribute value
1329 * Macro that given an attr e.g. hba_queue_depth expands
1330 * into a function with the name lpfc_hba_queue_depth_set
1332 * lpfc_##attr##_set: Sets an attribute value.
1333 * @phba: pointer the the adapter structure.
1334 * @val: integer attribute value.
1337 * Validates the min and max values then sets the
1338 * adapter config field if in the valid range. prints error message
1339 * and does not set the parameter if invalid.
1343 * -EINVAL if val is invalid
1345 #define lpfc_param_set(attr, default, minval, maxval) \
1347 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1349 if (val >= minval && val <= maxval) {\
1350 phba->cfg_##attr = val;\
1353 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1354 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1355 "allowed range is ["#minval", "#maxval"]\n", val); \
1360 * lpfc_param_store - Set a vport attribute value
1363 * Macro that given an attr e.g. hba_queue_depth expands
1364 * into a function with the name lpfc_hba_queue_depth_store.
1366 * lpfc_##attr##_store: Set an sttribute value.
1367 * @dev: class device that is converted into a Scsi_host.
1368 * @attr: device attribute, not used.
1369 * @buf: contains the attribute value in ascii.
1373 * Convert the ascii text number to an integer, then
1374 * use the lpfc_##attr##_set function to set the value.
1377 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1378 * length of buffer upon success.
1380 #define lpfc_param_store(attr) \
1382 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1383 const char *buf, size_t count) \
1385 struct Scsi_Host *shost = class_to_shost(dev);\
1386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1387 struct lpfc_hba *phba = vport->phba;\
1389 if (!isdigit(buf[0]))\
1391 if (sscanf(buf, "%i", &val) != 1)\
1393 if (lpfc_##attr##_set(phba, val) == 0) \
1394 return strlen(buf);\
1400 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1403 * Macro that given an attr e.g. hba_queue_depth expands
1404 * into a function with the name lpfc_hba_queue_depth_show
1406 * lpfc_##attr##_show: prints the attribute value in decimal.
1407 * @dev: class device that is converted into a Scsi_host.
1408 * @attr: device attribute, not used.
1409 * @buf: on return contains the attribute value in decimal.
1411 * Returns: length of formatted string.
1413 #define lpfc_vport_param_show(attr) \
1415 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1418 struct Scsi_Host *shost = class_to_shost(dev);\
1419 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1421 val = vport->cfg_##attr;\
1422 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1426 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1429 * Macro that given an attr e.g.
1430 * hba_queue_depth expands into a function with the name
1431 * lpfc_hba_queue_depth_show
1433 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1434 * @dev: class device that is converted into a Scsi_host.
1435 * @attr: device attribute, not used.
1436 * @buf: on return contains the attribute value in hexadecimal.
1438 * Returns: length of formatted string.
1440 #define lpfc_vport_param_hex_show(attr) \
1442 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1445 struct Scsi_Host *shost = class_to_shost(dev);\
1446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1448 val = vport->cfg_##attr;\
1449 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1453 * lpfc_vport_param_init - Initialize a vport cfg attribute
1456 * Macro that given an attr e.g. hba_queue_depth expands
1457 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1458 * takes a default argument, a minimum and maximum argument.
1460 * lpfc_##attr##_init: validates the min and max values then sets the
1461 * adapter config field accordingly, or uses the default if out of range
1462 * and prints an error message.
1463 * @phba: pointer the the adapter structure.
1464 * @val: integer attribute value.
1468 * -EINVAL if default used
1470 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1472 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1474 if (val >= minval && val <= maxval) {\
1475 vport->cfg_##attr = val;\
1478 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1479 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1480 "allowed range is ["#minval", "#maxval"]\n", val); \
1481 vport->cfg_##attr = default;\
1486 * lpfc_vport_param_set - Set a vport cfg attribute
1489 * Macro that given an attr e.g. hba_queue_depth expands
1490 * into a function with the name lpfc_hba_queue_depth_set
1492 * lpfc_##attr##_set: validates the min and max values then sets the
1493 * adapter config field if in the valid range. prints error message
1494 * and does not set the parameter if invalid.
1495 * @phba: pointer the the adapter structure.
1496 * @val: integer attribute value.
1500 * -EINVAL if val is invalid
1502 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1504 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1506 if (val >= minval && val <= maxval) {\
1507 vport->cfg_##attr = val;\
1510 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1511 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1512 "allowed range is ["#minval", "#maxval"]\n", val); \
1517 * lpfc_vport_param_store - Set a vport attribute
1520 * Macro that given an attr e.g. hba_queue_depth
1521 * expands into a function with the name lpfc_hba_queue_depth_store
1523 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1524 * use the lpfc_##attr##_set function to set the value.
1525 * @cdev: class device that is converted into a Scsi_host.
1526 * @buf: contains the attribute value in decimal.
1530 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1531 * length of buffer upon success.
1533 #define lpfc_vport_param_store(attr) \
1535 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1536 const char *buf, size_t count) \
1538 struct Scsi_Host *shost = class_to_shost(dev);\
1539 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1541 if (!isdigit(buf[0]))\
1543 if (sscanf(buf, "%i", &val) != 1)\
1545 if (lpfc_##attr##_set(vport, val) == 0) \
1546 return strlen(buf);\
1552 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1553 static uint lpfc_##name = defval;\
1554 module_param(lpfc_##name, uint, 0);\
1555 MODULE_PARM_DESC(lpfc_##name, desc);\
1556 lpfc_param_init(name, defval, minval, maxval)
1558 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1559 static uint lpfc_##name = defval;\
1560 module_param(lpfc_##name, uint, 0);\
1561 MODULE_PARM_DESC(lpfc_##name, desc);\
1562 lpfc_param_show(name)\
1563 lpfc_param_init(name, defval, minval, maxval)\
1564 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1566 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1567 static uint lpfc_##name = defval;\
1568 module_param(lpfc_##name, uint, 0);\
1569 MODULE_PARM_DESC(lpfc_##name, desc);\
1570 lpfc_param_show(name)\
1571 lpfc_param_init(name, defval, minval, maxval)\
1572 lpfc_param_set(name, defval, minval, maxval)\
1573 lpfc_param_store(name)\
1574 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1575 lpfc_##name##_show, lpfc_##name##_store)
1577 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1578 static uint lpfc_##name = defval;\
1579 module_param(lpfc_##name, uint, 0);\
1580 MODULE_PARM_DESC(lpfc_##name, desc);\
1581 lpfc_param_hex_show(name)\
1582 lpfc_param_init(name, defval, minval, maxval)\
1583 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1585 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1586 static uint lpfc_##name = defval;\
1587 module_param(lpfc_##name, uint, 0);\
1588 MODULE_PARM_DESC(lpfc_##name, desc);\
1589 lpfc_param_hex_show(name)\
1590 lpfc_param_init(name, defval, minval, maxval)\
1591 lpfc_param_set(name, defval, minval, maxval)\
1592 lpfc_param_store(name)\
1593 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1594 lpfc_##name##_show, lpfc_##name##_store)
1596 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1597 static uint lpfc_##name = defval;\
1598 module_param(lpfc_##name, uint, 0);\
1599 MODULE_PARM_DESC(lpfc_##name, desc);\
1600 lpfc_vport_param_init(name, defval, minval, maxval)
1602 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1603 static uint lpfc_##name = defval;\
1604 module_param(lpfc_##name, uint, 0);\
1605 MODULE_PARM_DESC(lpfc_##name, desc);\
1606 lpfc_vport_param_show(name)\
1607 lpfc_vport_param_init(name, defval, minval, maxval)\
1608 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1610 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1611 static uint lpfc_##name = defval;\
1612 module_param(lpfc_##name, uint, 0);\
1613 MODULE_PARM_DESC(lpfc_##name, desc);\
1614 lpfc_vport_param_show(name)\
1615 lpfc_vport_param_init(name, defval, minval, maxval)\
1616 lpfc_vport_param_set(name, defval, minval, maxval)\
1617 lpfc_vport_param_store(name)\
1618 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1619 lpfc_##name##_show, lpfc_##name##_store)
1621 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1622 static uint lpfc_##name = defval;\
1623 module_param(lpfc_##name, uint, 0);\
1624 MODULE_PARM_DESC(lpfc_##name, desc);\
1625 lpfc_vport_param_hex_show(name)\
1626 lpfc_vport_param_init(name, defval, minval, maxval)\
1627 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1629 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1630 static uint lpfc_##name = defval;\
1631 module_param(lpfc_##name, uint, 0);\
1632 MODULE_PARM_DESC(lpfc_##name, desc);\
1633 lpfc_vport_param_hex_show(name)\
1634 lpfc_vport_param_init(name, defval, minval, maxval)\
1635 lpfc_vport_param_set(name, defval, minval, maxval)\
1636 lpfc_vport_param_store(name)\
1637 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1638 lpfc_##name##_show, lpfc_##name##_store)
1640 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1641 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1642 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1643 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1644 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1645 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1646 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1647 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1648 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1649 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1650 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1651 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1652 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1653 lpfc_link_state_store);
1654 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1655 lpfc_option_rom_version_show, NULL);
1656 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1657 lpfc_num_discovered_ports_show, NULL);
1658 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1659 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1660 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1661 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1662 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1663 lpfc_board_mode_show, lpfc_board_mode_store);
1664 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1665 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1666 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1667 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1668 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1669 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1670 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1671 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1672 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1675 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1678 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1679 * @dev: class device that is converted into a Scsi_host.
1680 * @attr: device attribute, not used.
1681 * @buf: containing the string lpfc_soft_wwn_key.
1682 * @count: must be size of lpfc_soft_wwn_key.
1685 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1686 * length of buf indicates success
1689 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1690 const char *buf, size_t count)
1692 struct Scsi_Host *shost = class_to_shost(dev);
1693 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1694 struct lpfc_hba *phba = vport->phba;
1695 unsigned int cnt = count;
1698 * We're doing a simple sanity check for soft_wwpn setting.
1699 * We require that the user write a specific key to enable
1700 * the soft_wwpn attribute to be settable. Once the attribute
1701 * is written, the enable key resets. If further updates are
1702 * desired, the key must be written again to re-enable the
1705 * The "key" is not secret - it is a hardcoded string shown
1706 * here. The intent is to protect against the random user or
1707 * application that is just writing attributes.
1710 /* count may include a LF at end of string */
1711 if (buf[cnt-1] == '\n')
1714 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1715 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1718 phba->soft_wwn_enable = 1;
1721 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1722 lpfc_soft_wwn_enable_store);
1725 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1726 * @dev: class device that is converted into a Scsi_host.
1727 * @attr: device attribute, not used.
1728 * @buf: on return contains the wwpn in hexadecimal.
1730 * Returns: size of formatted string.
1733 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1736 struct Scsi_Host *shost = class_to_shost(dev);
1737 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1738 struct lpfc_hba *phba = vport->phba;
1740 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1741 (unsigned long long)phba->cfg_soft_wwpn);
1745 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1746 * @dev class device that is converted into a Scsi_host.
1747 * @attr: device attribute, not used.
1748 * @buf: contains the wwpn in hexadecimal.
1749 * @count: number of wwpn bytes in buf
1752 * -EACCES hba reset not enabled, adapter over temp
1753 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1754 * -EIO error taking adapter offline or online
1755 * value of count on success
1758 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1759 const char *buf, size_t count)
1761 struct Scsi_Host *shost = class_to_shost(dev);
1762 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1763 struct lpfc_hba *phba = vport->phba;
1764 struct completion online_compl;
1765 int stat1=0, stat2=0;
1766 unsigned int i, j, cnt=count;
1769 if (!phba->cfg_enable_hba_reset)
1771 spin_lock_irq(&phba->hbalock);
1772 if (phba->over_temp_state == HBA_OVER_TEMP) {
1773 spin_unlock_irq(&phba->hbalock);
1776 spin_unlock_irq(&phba->hbalock);
1777 /* count may include a LF at end of string */
1778 if (buf[cnt-1] == '\n')
1781 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1782 ((cnt == 17) && (*buf++ != 'x')) ||
1783 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1786 phba->soft_wwn_enable = 0;
1788 memset(wwpn, 0, sizeof(wwpn));
1790 /* Validate and store the new name */
1791 for (i=0, j=0; i < 16; i++) {
1792 if ((*buf >= 'a') && (*buf <= 'f'))
1793 j = ((j << 4) | ((*buf++ -'a') + 10));
1794 else if ((*buf >= 'A') && (*buf <= 'F'))
1795 j = ((j << 4) | ((*buf++ -'A') + 10));
1796 else if ((*buf >= '0') && (*buf <= '9'))
1797 j = ((j << 4) | (*buf++ -'0'));
1801 wwpn[i/2] = j & 0xff;
1805 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1806 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1807 if (phba->cfg_soft_wwnn)
1808 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1810 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1811 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1813 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1816 "0463 lpfc_soft_wwpn attribute set failed to "
1817 "reinit adapter - %d\n", stat1);
1818 init_completion(&online_compl);
1819 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1820 wait_for_completion(&online_compl);
1822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1823 "0464 lpfc_soft_wwpn attribute set failed to "
1824 "reinit adapter - %d\n", stat2);
1825 return (stat1 || stat2) ? -EIO : count;
1827 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1828 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1831 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1832 * @dev: class device that is converted into a Scsi_host.
1833 * @attr: device attribute, not used.
1834 * @buf: on return contains the wwnn in hexadecimal.
1836 * Returns: size of formatted string.
1839 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1842 struct Scsi_Host *shost = class_to_shost(dev);
1843 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1844 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1845 (unsigned long long)phba->cfg_soft_wwnn);
1849 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1850 * @cdev: class device that is converted into a Scsi_host.
1851 * @buf: contains the ww node name in hexadecimal.
1852 * @count: number of wwnn bytes in buf.
1855 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1856 * value of count on success
1859 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1860 const char *buf, size_t count)
1862 struct Scsi_Host *shost = class_to_shost(dev);
1863 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1864 unsigned int i, j, cnt=count;
1867 /* count may include a LF at end of string */
1868 if (buf[cnt-1] == '\n')
1871 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1872 ((cnt == 17) && (*buf++ != 'x')) ||
1873 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1877 * Allow wwnn to be set many times, as long as the enable is set.
1878 * However, once the wwpn is set, everything locks.
1881 memset(wwnn, 0, sizeof(wwnn));
1883 /* Validate and store the new name */
1884 for (i=0, j=0; i < 16; i++) {
1885 if ((*buf >= 'a') && (*buf <= 'f'))
1886 j = ((j << 4) | ((*buf++ -'a') + 10));
1887 else if ((*buf >= 'A') && (*buf <= 'F'))
1888 j = ((j << 4) | ((*buf++ -'A') + 10));
1889 else if ((*buf >= '0') && (*buf <= '9'))
1890 j = ((j << 4) | (*buf++ -'0'));
1894 wwnn[i/2] = j & 0xff;
1898 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1900 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1901 "lpfc%d: soft_wwnn set. Value will take effect upon "
1902 "setting of the soft_wwpn\n", phba->brd_no);
1906 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1907 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1910 static int lpfc_poll = 0;
1911 module_param(lpfc_poll, int, 0);
1912 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1914 " 1 - poll with interrupts enabled"
1915 " 3 - poll and disable FCP ring interrupts");
1917 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1918 lpfc_poll_show, lpfc_poll_store);
1920 int lpfc_sli_mode = 0;
1921 module_param(lpfc_sli_mode, int, 0);
1922 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1923 " 0 - auto (SLI-3 if supported),"
1924 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1925 " 3 - select SLI-3");
1927 int lpfc_enable_npiv = 0;
1928 module_param(lpfc_enable_npiv, int, 0);
1929 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1930 lpfc_param_show(enable_npiv);
1931 lpfc_param_init(enable_npiv, 0, 0, 1);
1932 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1933 lpfc_enable_npiv_show, NULL);
1936 # lpfc_suppress_link_up: Bring link up at initialization
1937 # 0x0 = bring link up (issue MBX_INIT_LINK)
1938 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1939 # 0x2 = never bring up link
1940 # Default value is 0.
1942 LPFC_ATTR_R(suppress_link_up, 0, 0, 2, "Suppress Link Up at initialization");
1945 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1946 # until the timer expires. Value range is [0,255]. Default value is 30.
1948 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1949 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1950 module_param(lpfc_nodev_tmo, int, 0);
1951 MODULE_PARM_DESC(lpfc_nodev_tmo,
1952 "Seconds driver will hold I/O waiting "
1953 "for a device to come back");
1956 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
1957 * @dev: class converted to a Scsi_host structure.
1958 * @attr: device attribute, not used.
1959 * @buf: on return contains the dev loss timeout in decimal.
1961 * Returns: size of formatted string.
1964 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1967 struct Scsi_Host *shost = class_to_shost(dev);
1968 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1970 val = vport->cfg_devloss_tmo;
1971 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1975 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
1976 * @vport: lpfc vport structure pointer.
1977 * @val: contains the nodev timeout value.
1980 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1981 * a kernel error message is printed and zero is returned.
1982 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1983 * Otherwise nodev tmo is set to the default value.
1986 * zero if already set or if val is in range
1987 * -EINVAL val out of range
1990 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1992 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1993 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1994 if (val != LPFC_DEF_DEVLOSS_TMO)
1995 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1996 "0407 Ignoring nodev_tmo module "
1997 "parameter because devloss_tmo is "
2002 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2003 vport->cfg_nodev_tmo = val;
2004 vport->cfg_devloss_tmo = val;
2007 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2008 "0400 lpfc_nodev_tmo attribute cannot be set to"
2009 " %d, allowed range is [%d, %d]\n",
2010 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2011 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2016 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2017 * @vport: lpfc vport structure pointer.
2020 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2023 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2025 struct Scsi_Host *shost;
2026 struct lpfc_nodelist *ndlp;
2028 shost = lpfc_shost_from_vport(vport);
2029 spin_lock_irq(shost->host_lock);
2030 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2031 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2032 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2033 spin_unlock_irq(shost->host_lock);
2037 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2038 * @vport: lpfc vport structure pointer.
2039 * @val: contains the tmo value.
2042 * If the devloss tmo is already set or the vport dev loss tmo has changed
2043 * then a kernel error message is printed and zero is returned.
2044 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2045 * Otherwise nodev tmo is set to the default value.
2048 * zero if already set or if val is in range
2049 * -EINVAL val out of range
2052 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2054 if (vport->dev_loss_tmo_changed ||
2055 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2056 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2057 "0401 Ignoring change to nodev_tmo "
2058 "because devloss_tmo is set.\n");
2061 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2062 vport->cfg_nodev_tmo = val;
2063 vport->cfg_devloss_tmo = val;
2064 lpfc_update_rport_devloss_tmo(vport);
2067 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2068 "0403 lpfc_nodev_tmo attribute cannot be set to"
2069 "%d, allowed range is [%d, %d]\n",
2070 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2074 lpfc_vport_param_store(nodev_tmo)
2076 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2077 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2080 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2081 # disappear until the timer expires. Value range is [0,255]. Default
2084 module_param(lpfc_devloss_tmo, int, 0);
2085 MODULE_PARM_DESC(lpfc_devloss_tmo,
2086 "Seconds driver will hold I/O waiting "
2087 "for a device to come back");
2088 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2089 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2090 lpfc_vport_param_show(devloss_tmo)
2093 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2094 * @vport: lpfc vport structure pointer.
2095 * @val: contains the tmo value.
2098 * If val is in a valid range then set the vport nodev tmo,
2099 * devloss tmo, also set the vport dev loss tmo changed flag.
2100 * Else a kernel error message is printed.
2103 * zero if val is in range
2104 * -EINVAL val out of range
2107 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2109 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2110 vport->cfg_nodev_tmo = val;
2111 vport->cfg_devloss_tmo = val;
2112 vport->dev_loss_tmo_changed = 1;
2113 lpfc_update_rport_devloss_tmo(vport);
2117 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2118 "0404 lpfc_devloss_tmo attribute cannot be set to"
2119 " %d, allowed range is [%d, %d]\n",
2120 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2124 lpfc_vport_param_store(devloss_tmo)
2125 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2126 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2129 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2130 # deluged with LOTS of information.
2131 # You can set a bit mask to record specific types of verbose messages:
2132 # See lpfc_logmsh.h for definitions.
2134 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2135 "Verbose logging bit-mask");
2138 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2139 # objects that have been registered with the nameserver after login.
2141 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2142 "Deregister nameserver objects before LOGO");
2145 # lun_queue_depth: This parameter is used to limit the number of outstanding
2146 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2148 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2149 "Max number of FCP commands we can queue to a specific LUN");
2152 # hba_queue_depth: This parameter is used to limit the number of outstanding
2153 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2154 # value is greater than the maximum number of exchanges supported by the HBA,
2155 # then maximum number of exchanges supported by the HBA is used to determine
2156 # the hba_queue_depth.
2158 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2159 "Max number of FCP commands we can queue to a lpfc HBA");
2162 # peer_port_login: This parameter allows/prevents logins
2163 # between peer ports hosted on the same physical port.
2164 # When this parameter is set 0 peer ports of same physical port
2165 # are not allowed to login to each other.
2166 # When this parameter is set 1 peer ports of same physical port
2167 # are allowed to login to each other.
2168 # Default value of this parameter is 0.
2170 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2171 "Allow peer ports on the same physical port to login to each "
2175 # restrict_login: This parameter allows/prevents logins
2176 # between Virtual Ports and remote initiators.
2177 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2178 # other initiators and will attempt to PLOGI all remote ports.
2179 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2180 # remote ports and will not attempt to PLOGI to other initiators.
2181 # This parameter does not restrict to the physical port.
2182 # This parameter does not restrict logins to Fabric resident remote ports.
2183 # Default value of this parameter is 1.
2185 static int lpfc_restrict_login = 1;
2186 module_param(lpfc_restrict_login, int, 0);
2187 MODULE_PARM_DESC(lpfc_restrict_login,
2188 "Restrict virtual ports login to remote initiators.");
2189 lpfc_vport_param_show(restrict_login);
2192 * lpfc_restrict_login_init - Set the vport restrict login flag
2193 * @vport: lpfc vport structure pointer.
2194 * @val: contains the restrict login value.
2197 * If val is not in a valid range then log a kernel error message and set
2198 * the vport restrict login to one.
2199 * If the port type is physical clear the restrict login flag and return.
2200 * Else set the restrict login flag to val.
2203 * zero if val is in range
2204 * -EINVAL val out of range
2207 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2209 if (val < 0 || val > 1) {
2210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2211 "0422 lpfc_restrict_login attribute cannot "
2212 "be set to %d, allowed range is [0, 1]\n",
2214 vport->cfg_restrict_login = 1;
2217 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2218 vport->cfg_restrict_login = 0;
2221 vport->cfg_restrict_login = val;
2226 * lpfc_restrict_login_set - Set the vport restrict login flag
2227 * @vport: lpfc vport structure pointer.
2228 * @val: contains the restrict login value.
2231 * If val is not in a valid range then log a kernel error message and set
2232 * the vport restrict login to one.
2233 * If the port type is physical and the val is not zero log a kernel
2234 * error message, clear the restrict login flag and return zero.
2235 * Else set the restrict login flag to val.
2238 * zero if val is in range
2239 * -EINVAL val out of range
2242 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2244 if (val < 0 || val > 1) {
2245 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2246 "0425 lpfc_restrict_login attribute cannot "
2247 "be set to %d, allowed range is [0, 1]\n",
2249 vport->cfg_restrict_login = 1;
2252 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2253 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2254 "0468 lpfc_restrict_login must be 0 for "
2255 "Physical ports.\n");
2256 vport->cfg_restrict_login = 0;
2259 vport->cfg_restrict_login = val;
2262 lpfc_vport_param_store(restrict_login);
2263 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2264 lpfc_restrict_login_show, lpfc_restrict_login_store);
2267 # Some disk devices have a "select ID" or "select Target" capability.
2268 # From a protocol standpoint "select ID" usually means select the
2269 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2270 # annex" which contains a table that maps a "select ID" (a number
2271 # between 0 and 7F) to an ALPA. By default, for compatibility with
2272 # older drivers, the lpfc driver scans this table from low ALPA to high
2275 # Turning on the scan-down variable (on = 1, off = 0) will
2276 # cause the lpfc driver to use an inverted table, effectively
2277 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2279 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2280 # and will not work across a fabric. Also this parameter will take
2281 # effect only in the case when ALPA map is not available.)
2283 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2284 "Start scanning for devices from highest ALPA to lowest");
2287 # lpfc_topology: link topology for init link
2288 # 0x0 = attempt loop mode then point-to-point
2289 # 0x01 = internal loopback mode
2290 # 0x02 = attempt point-to-point mode only
2291 # 0x04 = attempt loop mode only
2292 # 0x06 = attempt point-to-point mode then loop
2293 # Set point-to-point mode if you want to run as an N_Port.
2294 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2295 # Default value is 0.
2299 * lpfc_topology_set - Set the adapters topology field
2300 * @phba: lpfc_hba pointer.
2301 * @val: topology value.
2304 * If val is in a valid range then set the adapter's topology field and
2305 * issue a lip; if the lip fails reset the topology to the old value.
2307 * If the value is not in range log a kernel error message and return an error.
2310 * zero if val is in range and lip okay
2311 * non-zero return value from lpfc_issue_lip()
2312 * -EINVAL val out of range
2315 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2316 const char *buf, size_t count)
2318 struct Scsi_Host *shost = class_to_shost(dev);
2319 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2320 struct lpfc_hba *phba = vport->phba;
2323 const char *val_buf = buf;
2327 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2329 val_buf = &buf[strlen("nolip ")];
2332 if (!isdigit(val_buf[0]))
2334 if (sscanf(val_buf, "%i", &val) != 1)
2337 if (val >= 0 && val <= 6) {
2338 prev_val = phba->cfg_topology;
2339 phba->cfg_topology = val;
2343 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2345 phba->cfg_topology = prev_val;
2350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2351 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2352 "allowed range is [0, 6]\n",
2356 static int lpfc_topology = 0;
2357 module_param(lpfc_topology, int, 0);
2358 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2359 lpfc_param_show(topology)
2360 lpfc_param_init(topology, 0, 0, 6)
2361 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2362 lpfc_topology_show, lpfc_topology_store);
2365 * lpfc_static_vport_show: Read callback function for
2366 * lpfc_static_vport sysfs file.
2367 * @dev: Pointer to class device object.
2368 * @attr: device attribute structure.
2369 * @buf: Data buffer.
2371 * This function is the read call back function for
2372 * lpfc_static_vport sysfs file. The lpfc_static_vport
2373 * sysfs file report the mageability of the vport.
2376 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2379 struct Scsi_Host *shost = class_to_shost(dev);
2380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2381 if (vport->vport_flag & STATIC_VPORT)
2382 sprintf(buf, "1\n");
2384 sprintf(buf, "0\n");
2390 * Sysfs attribute to control the statistical data collection.
2392 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2393 lpfc_static_vport_show, NULL);
2396 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2397 * @dev: Pointer to class device.
2398 * @buf: Data buffer.
2399 * @count: Size of the data buffer.
2401 * This function get called when an user write to the lpfc_stat_data_ctrl
2402 * sysfs file. This function parse the command written to the sysfs file
2403 * and take appropriate action. These commands are used for controlling
2404 * driver statistical data collection.
2405 * Following are the command this function handles.
2407 * setbucket <bucket_type> <base> <step>
2408 * = Set the latency buckets.
2409 * destroybucket = destroy all the buckets.
2410 * start = start data collection
2411 * stop = stop data collection
2412 * reset = reset the collected data
2415 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2416 const char *buf, size_t count)
2418 struct Scsi_Host *shost = class_to_shost(dev);
2419 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2420 struct lpfc_hba *phba = vport->phba;
2421 #define LPFC_MAX_DATA_CTRL_LEN 1024
2422 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2424 char *str_ptr, *token;
2425 struct lpfc_vport **vports;
2426 struct Scsi_Host *v_shost;
2427 char *bucket_type_str, *base_str, *step_str;
2428 unsigned long base, step, bucket_type;
2430 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2431 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2434 strcpy(bucket_data, buf);
2435 str_ptr = &bucket_data[0];
2436 /* Ignore this token - this is command token */
2437 token = strsep(&str_ptr, "\t ");
2441 bucket_type_str = strsep(&str_ptr, "\t ");
2442 if (!bucket_type_str)
2445 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2446 bucket_type = LPFC_LINEAR_BUCKET;
2447 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2448 bucket_type = LPFC_POWER2_BUCKET;
2452 base_str = strsep(&str_ptr, "\t ");
2455 base = simple_strtoul(base_str, NULL, 0);
2457 step_str = strsep(&str_ptr, "\t ");
2460 step = simple_strtoul(step_str, NULL, 0);
2464 /* Block the data collection for every vport */
2465 vports = lpfc_create_vport_work_array(phba);
2469 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2470 v_shost = lpfc_shost_from_vport(vports[i]);
2471 spin_lock_irq(v_shost->host_lock);
2472 /* Block and reset data collection */
2473 vports[i]->stat_data_blocked = 1;
2474 if (vports[i]->stat_data_enabled)
2475 lpfc_vport_reset_stat_data(vports[i]);
2476 spin_unlock_irq(v_shost->host_lock);
2479 /* Set the bucket attributes */
2480 phba->bucket_type = bucket_type;
2481 phba->bucket_base = base;
2482 phba->bucket_step = step;
2484 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2485 v_shost = lpfc_shost_from_vport(vports[i]);
2487 /* Unblock data collection */
2488 spin_lock_irq(v_shost->host_lock);
2489 vports[i]->stat_data_blocked = 0;
2490 spin_unlock_irq(v_shost->host_lock);
2492 lpfc_destroy_vport_work_array(phba, vports);
2496 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2497 vports = lpfc_create_vport_work_array(phba);
2501 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2502 v_shost = lpfc_shost_from_vport(vports[i]);
2503 spin_lock_irq(shost->host_lock);
2504 vports[i]->stat_data_blocked = 1;
2505 lpfc_free_bucket(vport);
2506 vport->stat_data_enabled = 0;
2507 vports[i]->stat_data_blocked = 0;
2508 spin_unlock_irq(shost->host_lock);
2510 lpfc_destroy_vport_work_array(phba, vports);
2511 phba->bucket_type = LPFC_NO_BUCKET;
2512 phba->bucket_base = 0;
2513 phba->bucket_step = 0;
2517 if (!strncmp(buf, "start", strlen("start"))) {
2518 /* If no buckets configured return error */
2519 if (phba->bucket_type == LPFC_NO_BUCKET)
2521 spin_lock_irq(shost->host_lock);
2522 if (vport->stat_data_enabled) {
2523 spin_unlock_irq(shost->host_lock);
2526 lpfc_alloc_bucket(vport);
2527 vport->stat_data_enabled = 1;
2528 spin_unlock_irq(shost->host_lock);
2532 if (!strncmp(buf, "stop", strlen("stop"))) {
2533 spin_lock_irq(shost->host_lock);
2534 if (vport->stat_data_enabled == 0) {
2535 spin_unlock_irq(shost->host_lock);
2538 lpfc_free_bucket(vport);
2539 vport->stat_data_enabled = 0;
2540 spin_unlock_irq(shost->host_lock);
2544 if (!strncmp(buf, "reset", strlen("reset"))) {
2545 if ((phba->bucket_type == LPFC_NO_BUCKET)
2546 || !vport->stat_data_enabled)
2548 spin_lock_irq(shost->host_lock);
2549 vport->stat_data_blocked = 1;
2550 lpfc_vport_reset_stat_data(vport);
2551 vport->stat_data_blocked = 0;
2552 spin_unlock_irq(shost->host_lock);
2560 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2561 * @dev: Pointer to class device object.
2562 * @buf: Data buffer.
2564 * This function is the read call back function for
2565 * lpfc_stat_data_ctrl sysfs file. This function report the
2566 * current statistical data collection state.
2569 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2572 struct Scsi_Host *shost = class_to_shost(dev);
2573 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2574 struct lpfc_hba *phba = vport->phba;
2578 unsigned long bucket_value;
2580 switch (phba->bucket_type) {
2581 case LPFC_LINEAR_BUCKET:
2582 bucket_type = "linear";
2584 case LPFC_POWER2_BUCKET:
2585 bucket_type = "power2";
2588 bucket_type = "No Bucket";
2592 sprintf(&buf[index], "Statistical Data enabled :%d, "
2593 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2594 " Bucket step :%d\nLatency Ranges :",
2595 vport->stat_data_enabled, vport->stat_data_blocked,
2596 bucket_type, phba->bucket_base, phba->bucket_step);
2597 index = strlen(buf);
2598 if (phba->bucket_type != LPFC_NO_BUCKET) {
2599 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2600 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2601 bucket_value = phba->bucket_base +
2602 phba->bucket_step * i;
2604 bucket_value = phba->bucket_base +
2605 (1 << i) * phba->bucket_step;
2607 if (index + 10 > PAGE_SIZE)
2609 sprintf(&buf[index], "%08ld ", bucket_value);
2610 index = strlen(buf);
2613 sprintf(&buf[index], "\n");
2618 * Sysfs attribute to control the statistical data collection.
2620 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2621 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2624 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2628 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2631 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2632 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2633 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2637 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2638 * @kobj: Pointer to the kernel object
2639 * @bin_attr: Attribute object
2640 * @buff: Buffer pointer
2642 * @count: Buffer size
2644 * This function is the read call back function for lpfc_drvr_stat_data
2645 * sysfs file. This function export the statistical data to user
2649 sysfs_drvr_stat_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
2650 char *buf, loff_t off, size_t count)
2652 struct device *dev = container_of(kobj, struct device,
2654 struct Scsi_Host *shost = class_to_shost(dev);
2655 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2656 struct lpfc_hba *phba = vport->phba;
2657 int i = 0, index = 0;
2658 unsigned long nport_index;
2659 struct lpfc_nodelist *ndlp = NULL;
2660 nport_index = (unsigned long)off /
2661 MAX_STAT_DATA_SIZE_PER_TARGET;
2663 if (!vport->stat_data_enabled || vport->stat_data_blocked
2664 || (phba->bucket_type == LPFC_NO_BUCKET))
2667 spin_lock_irq(shost->host_lock);
2668 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2669 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2672 if (nport_index > 0) {
2677 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2681 if (!ndlp->lat_data)
2685 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2686 ndlp->nlp_portname.u.wwn[0],
2687 ndlp->nlp_portname.u.wwn[1],
2688 ndlp->nlp_portname.u.wwn[2],
2689 ndlp->nlp_portname.u.wwn[3],
2690 ndlp->nlp_portname.u.wwn[4],
2691 ndlp->nlp_portname.u.wwn[5],
2692 ndlp->nlp_portname.u.wwn[6],
2693 ndlp->nlp_portname.u.wwn[7]);
2695 index = strlen(buf);
2697 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2698 sprintf(&buf[index], "%010u,",
2699 ndlp->lat_data[i].cmd_count);
2700 index = strlen(buf);
2702 sprintf(&buf[index], "\n");
2703 index = strlen(buf);
2705 spin_unlock_irq(shost->host_lock);
2709 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2711 .name = "lpfc_drvr_stat_data",
2713 .owner = THIS_MODULE,
2715 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2716 .read = sysfs_drvr_stat_data_read,
2721 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2723 # 0 = auto select (default)
2728 # Value range is [0,8]. Default value is 0.
2732 * lpfc_link_speed_set - Set the adapters link speed
2733 * @phba: lpfc_hba pointer.
2734 * @val: link speed value.
2737 * If val is in a valid range then set the adapter's link speed field and
2738 * issue a lip; if the lip fails reset the link speed to the old value.
2741 * If the value is not in range log a kernel error message and return an error.
2744 * zero if val is in range and lip okay.
2745 * non-zero return value from lpfc_issue_lip()
2746 * -EINVAL val out of range
2749 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2750 const char *buf, size_t count)
2752 struct Scsi_Host *shost = class_to_shost(dev);
2753 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2754 struct lpfc_hba *phba = vport->phba;
2757 const char *val_buf = buf;
2761 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2763 val_buf = &buf[strlen("nolip ")];
2766 if (!isdigit(val_buf[0]))
2768 if (sscanf(val_buf, "%i", &val) != 1)
2771 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2772 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2773 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2774 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2775 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2778 if ((val >= 0 && val <= 8)
2779 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2780 prev_val = phba->cfg_link_speed;
2781 phba->cfg_link_speed = val;
2785 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2787 phba->cfg_link_speed = prev_val;
2793 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2794 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2795 "allowed range is [0, 8]\n",
2800 static int lpfc_link_speed = 0;
2801 module_param(lpfc_link_speed, int, 0);
2802 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2803 lpfc_param_show(link_speed)
2806 * lpfc_link_speed_init - Set the adapters link speed
2807 * @phba: lpfc_hba pointer.
2808 * @val: link speed value.
2811 * If val is in a valid range then set the adapter's link speed field.
2814 * If the value is not in range log a kernel error message, clear the link
2815 * speed and return an error.
2818 * zero if val saved.
2819 * -EINVAL val out of range
2822 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2824 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2825 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2826 phba->cfg_link_speed = val;
2829 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2830 "0405 lpfc_link_speed attribute cannot "
2831 "be set to %d, allowed values are "
2832 "["LPFC_LINK_SPEED_STRING"]\n", val);
2833 phba->cfg_link_speed = 0;
2837 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2838 lpfc_link_speed_show, lpfc_link_speed_store);
2841 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2842 # 0 = aer disabled or not supported
2843 # 1 = aer supported and enabled (default)
2844 # Value range is [0,1]. Default value is 1.
2848 * lpfc_aer_support_store - Set the adapter for aer support
2850 * @dev: class device that is converted into a Scsi_host.
2851 * @attr: device attribute, not used.
2852 * @buf: containing the string "selective".
2853 * @count: unused variable.
2856 * If the val is 1 and currently the device's AER capability was not
2857 * enabled, invoke the kernel's enable AER helper routine, trying to
2858 * enable the device's AER capability. If the helper routine enabling
2859 * AER returns success, update the device's cfg_aer_support flag to
2860 * indicate AER is supported by the device; otherwise, if the device
2861 * AER capability is already enabled to support AER, then do nothing.
2863 * If the val is 0 and currently the device's AER support was enabled,
2864 * invoke the kernel's disable AER helper routine. After that, update
2865 * the device's cfg_aer_support flag to indicate AER is not supported
2866 * by the device; otherwise, if the device AER capability is already
2867 * disabled from supporting AER, then do nothing.
2870 * length of the buf on success if val is in range the intended mode
2872 * -EINVAL if val out of range or intended mode is not supported.
2875 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2876 const char *buf, size_t count)
2878 struct Scsi_Host *shost = class_to_shost(dev);
2879 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2880 struct lpfc_hba *phba = vport->phba;
2881 int val = 0, rc = -EINVAL;
2883 /* AER not supported on OC devices yet */
2884 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
2886 if (!isdigit(buf[0]))
2888 if (sscanf(buf, "%i", &val) != 1)
2893 if (phba->hba_flag & HBA_AER_ENABLED) {
2894 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2896 spin_lock_irq(&phba->hbalock);
2897 phba->hba_flag &= ~HBA_AER_ENABLED;
2898 spin_unlock_irq(&phba->hbalock);
2899 phba->cfg_aer_support = 0;
2904 phba->cfg_aer_support = 0;
2909 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2910 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2912 spin_lock_irq(&phba->hbalock);
2913 phba->hba_flag |= HBA_AER_ENABLED;
2914 spin_unlock_irq(&phba->hbalock);
2915 phba->cfg_aer_support = 1;
2920 phba->cfg_aer_support = 1;
2931 static int lpfc_aer_support = 1;
2932 module_param(lpfc_aer_support, int, 1);
2933 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2934 lpfc_param_show(aer_support)
2937 * lpfc_aer_support_init - Set the initial adapters aer support flag
2938 * @phba: lpfc_hba pointer.
2939 * @val: link speed value.
2942 * If val is in a valid range [0,1], then set the adapter's initial
2943 * cfg_aer_support field. It will be up to the driver's probe_one
2944 * routine to determine whether the device's AER support can be set
2948 * If the value is not in range log a kernel error message, and
2949 * choose the default value of setting AER support and return.
2952 * zero if val saved.
2953 * -EINVAL val out of range
2956 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
2958 /* AER not supported on OC devices yet */
2959 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
2960 phba->cfg_aer_support = 0;
2964 if (val == 0 || val == 1) {
2965 phba->cfg_aer_support = val;
2968 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2969 "2712 lpfc_aer_support attribute value %d out "
2970 "of range, allowed values are 0|1, setting it "
2971 "to default value of 1\n", val);
2972 /* By default, try to enable AER on a device */
2973 phba->cfg_aer_support = 1;
2977 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
2978 lpfc_aer_support_show, lpfc_aer_support_store);
2981 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
2982 * @dev: class device that is converted into a Scsi_host.
2983 * @attr: device attribute, not used.
2984 * @buf: containing the string "selective".
2985 * @count: unused variable.
2988 * If the @buf contains 1 and the device currently has the AER support
2989 * enabled, then invokes the kernel AER helper routine
2990 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
2991 * error status register.
2996 * -EINVAL if the buf does not contain the 1 or the device is not currently
2997 * enabled with the AER support.
3000 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3001 const char *buf, size_t count)
3003 struct Scsi_Host *shost = class_to_shost(dev);
3004 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3005 struct lpfc_hba *phba = vport->phba;
3008 /* AER not supported on OC devices yet */
3009 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
3011 if (!isdigit(buf[0]))
3013 if (sscanf(buf, "%i", &val) != 1)
3018 if (phba->hba_flag & HBA_AER_ENABLED)
3019 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3027 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3028 lpfc_aer_cleanup_state);
3031 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3032 # Value range is [2,3]. Default value is 3.
3034 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3035 "Select Fibre Channel class of service for FCP sequences");
3038 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3039 # is [0,1]. Default value is 0.
3041 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3042 "Use ADISC on rediscovery to authenticate FCP devices");
3045 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3046 # depth. Default value is 0. When the value of this parameter is zero the
3047 # SCSI command completion time is not used for controlling I/O queue depth. When
3048 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3049 # to limit the I/O completion time to the parameter value.
3050 # The value is set in milliseconds.
3052 static int lpfc_max_scsicmpl_time;
3053 module_param(lpfc_max_scsicmpl_time, int, 0);
3054 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3055 "Use command completion time to control queue depth");
3056 lpfc_vport_param_show(max_scsicmpl_time);
3057 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3059 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3061 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3062 struct lpfc_nodelist *ndlp, *next_ndlp;
3064 if (val == vport->cfg_max_scsicmpl_time)
3066 if ((val < 0) || (val > 60000))
3068 vport->cfg_max_scsicmpl_time = val;
3070 spin_lock_irq(shost->host_lock);
3071 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3072 if (!NLP_CHK_NODE_ACT(ndlp))
3074 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3076 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
3078 spin_unlock_irq(shost->host_lock);
3081 lpfc_vport_param_store(max_scsicmpl_time);
3082 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3083 lpfc_max_scsicmpl_time_show,
3084 lpfc_max_scsicmpl_time_store);
3087 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3088 # range is [0,1]. Default value is 0.
3090 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3093 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3094 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3095 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3096 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3097 # cr_delay is set to 0.
3099 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3100 "interrupt response is generated");
3102 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3103 "interrupt response is generated");
3106 # lpfc_multi_ring_support: Determines how many rings to spread available
3107 # cmd/rsp IOCB entries across.
3108 # Value range is [1,2]. Default value is 1.
3110 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3111 "SLI rings to spread IOCB entries across");
3114 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3115 # identifies what rctl value to configure the additional ring for.
3116 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3118 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3119 255, "Identifies RCTL for additional ring configuration");
3122 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3123 # identifies what type value to configure the additional ring for.
3124 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3126 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3127 255, "Identifies TYPE for additional ring configuration");
3130 # lpfc_fdmi_on: controls FDMI support.
3131 # 0 = no FDMI support
3132 # 1 = support FDMI without attribute of hostname
3133 # 2 = support FDMI with attribute of hostname
3134 # Value range [0,2]. Default value is 0.
3136 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3139 # Specifies the maximum number of ELS cmds we can have outstanding (for
3140 # discovery). Value range is [1,64]. Default value = 32.
3142 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3143 "during discovery");
3146 # lpfc_max_luns: maximum allowed LUN.
3147 # Value range is [0,65535]. Default value is 255.
3148 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3150 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3153 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3154 # Value range is [1,255], default value is 10.
3156 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3157 "Milliseconds driver will wait between polling FCP ring");
3160 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3161 # support this feature
3164 # 2 = MSI-X enabled (default)
3165 # Value range is [0,2]. Default value is 2.
3167 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3168 "MSI-X (2), if possible");
3171 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3173 # Value range is [636,651042]. Default value is 10000.
3175 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3176 "Set the maximum number of fast-path FCP interrupts per second");
3179 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3181 # Value range is [1,31]. Default value is 4.
3183 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3184 "Set the number of fast-path FCP work queues, if possible");
3187 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3189 # Value range is [1,7]. Default value is 1.
3191 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3192 "Set the number of fast-path FCP event queues, if possible");
3195 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3196 # 0 = HBA resets disabled
3197 # 1 = HBA resets enabled (default)
3198 # Value range is [0,1]. Default value is 1.
3200 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3203 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3204 # 0 = HBA Heartbeat disabled
3205 # 1 = HBA Heartbeat enabled (default)
3206 # Value range is [0,1]. Default value is 1.
3208 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
3211 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3212 # 0 = BlockGuard disabled (default)
3213 # 1 = BlockGuard enabled
3214 # Value range is [0,1]. Default value is 0.
3216 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3220 # - Bit mask of host protection capabilities used to register with the
3222 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3223 # - Allows you to ultimately specify which profiles to use
3224 # - Default will result in registering capabilities for all profiles.
3227 unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3229 module_param(lpfc_prot_mask, uint, 0);
3230 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3233 # lpfc_prot_guard: i
3234 # - Bit mask of protection guard types to register with the SCSI mid-layer
3235 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3236 # - Allows you to ultimately specify which profiles to use
3237 # - Default will result in registering capabilities for all guard types
3240 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3241 module_param(lpfc_prot_guard, byte, 0);
3242 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3246 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3247 * This value can be set to values between 64 and 256. The default value is
3248 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3249 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3251 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3252 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3254 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3255 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3256 "Max Protection Scatter Gather Segment Count");
3258 struct device_attribute *lpfc_hba_attrs[] = {
3260 &dev_attr_bg_guard_err,
3261 &dev_attr_bg_apptag_err,
3262 &dev_attr_bg_reftag_err,
3264 &dev_attr_serialnum,
3265 &dev_attr_modeldesc,
3266 &dev_attr_modelname,
3267 &dev_attr_programtype,
3271 &dev_attr_option_rom_version,
3272 &dev_attr_link_state,
3273 &dev_attr_num_discovered_ports,
3274 &dev_attr_menlo_mgmt_mode,
3275 &dev_attr_lpfc_drvr_version,
3276 &dev_attr_lpfc_enable_fip,
3277 &dev_attr_lpfc_temp_sensor,
3278 &dev_attr_lpfc_log_verbose,
3279 &dev_attr_lpfc_lun_queue_depth,
3280 &dev_attr_lpfc_hba_queue_depth,
3281 &dev_attr_lpfc_peer_port_login,
3282 &dev_attr_lpfc_nodev_tmo,
3283 &dev_attr_lpfc_devloss_tmo,
3284 &dev_attr_lpfc_fcp_class,
3285 &dev_attr_lpfc_use_adisc,
3286 &dev_attr_lpfc_ack0,
3287 &dev_attr_lpfc_topology,
3288 &dev_attr_lpfc_scan_down,
3289 &dev_attr_lpfc_link_speed,
3290 &dev_attr_lpfc_cr_delay,
3291 &dev_attr_lpfc_cr_count,
3292 &dev_attr_lpfc_multi_ring_support,
3293 &dev_attr_lpfc_multi_ring_rctl,
3294 &dev_attr_lpfc_multi_ring_type,
3295 &dev_attr_lpfc_fdmi_on,
3296 &dev_attr_lpfc_max_luns,
3297 &dev_attr_lpfc_enable_npiv,
3298 &dev_attr_nport_evt_cnt,
3299 &dev_attr_board_mode,
3306 &dev_attr_npiv_info,
3307 &dev_attr_issue_reset,
3308 &dev_attr_lpfc_poll,
3309 &dev_attr_lpfc_poll_tmo,
3310 &dev_attr_lpfc_use_msi,
3311 &dev_attr_lpfc_fcp_imax,
3312 &dev_attr_lpfc_fcp_wq_count,
3313 &dev_attr_lpfc_fcp_eq_count,
3314 &dev_attr_lpfc_enable_bg,
3315 &dev_attr_lpfc_soft_wwnn,
3316 &dev_attr_lpfc_soft_wwpn,
3317 &dev_attr_lpfc_soft_wwn_enable,
3318 &dev_attr_lpfc_enable_hba_reset,
3319 &dev_attr_lpfc_enable_hba_heartbeat,
3320 &dev_attr_lpfc_sg_seg_cnt,
3321 &dev_attr_lpfc_max_scsicmpl_time,
3322 &dev_attr_lpfc_stat_data_ctrl,
3323 &dev_attr_lpfc_prot_sg_seg_cnt,
3324 &dev_attr_lpfc_aer_support,
3325 &dev_attr_lpfc_aer_state_cleanup,
3326 &dev_attr_lpfc_suppress_link_up,
3330 struct device_attribute *lpfc_vport_attrs[] = {
3332 &dev_attr_link_state,
3333 &dev_attr_num_discovered_ports,
3334 &dev_attr_lpfc_drvr_version,
3335 &dev_attr_lpfc_log_verbose,
3336 &dev_attr_lpfc_lun_queue_depth,
3337 &dev_attr_lpfc_nodev_tmo,
3338 &dev_attr_lpfc_devloss_tmo,
3339 &dev_attr_lpfc_hba_queue_depth,
3340 &dev_attr_lpfc_peer_port_login,
3341 &dev_attr_lpfc_restrict_login,
3342 &dev_attr_lpfc_fcp_class,
3343 &dev_attr_lpfc_use_adisc,
3344 &dev_attr_lpfc_fdmi_on,
3345 &dev_attr_lpfc_max_luns,
3346 &dev_attr_nport_evt_cnt,
3347 &dev_attr_npiv_info,
3348 &dev_attr_lpfc_enable_da_id,
3349 &dev_attr_lpfc_max_scsicmpl_time,
3350 &dev_attr_lpfc_stat_data_ctrl,
3351 &dev_attr_lpfc_static_vport,
3356 * sysfs_ctlreg_write - Write method for writing to ctlreg
3357 * @kobj: kernel kobject that contains the kernel class device.
3358 * @bin_attr: kernel attributes passed to us.
3359 * @buf: contains the data to be written to the adapter IOREG space.
3360 * @off: offset into buffer to beginning of data.
3361 * @count: bytes to transfer.
3364 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3365 * Uses the adapter io control registers to send buf contents to the adapter.
3368 * -ERANGE off and count combo out of range
3369 * -EINVAL off, count or buff address invalid
3370 * -EPERM adapter is offline
3371 * value of count, buf contents written
3374 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3375 char *buf, loff_t off, size_t count)
3378 struct device *dev = container_of(kobj, struct device, kobj);
3379 struct Scsi_Host *shost = class_to_shost(dev);
3380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3381 struct lpfc_hba *phba = vport->phba;
3383 if (phba->sli_rev >= LPFC_SLI_REV4)
3386 if ((off + count) > FF_REG_AREA_SIZE)
3389 if (count == 0) return 0;
3391 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3394 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3398 spin_lock_irq(&phba->hbalock);
3399 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3400 writel(*((uint32_t *)(buf + buf_off)),
3401 phba->ctrl_regs_memmap_p + off + buf_off);
3403 spin_unlock_irq(&phba->hbalock);
3409 * sysfs_ctlreg_read - Read method for reading from ctlreg
3410 * @kobj: kernel kobject that contains the kernel class device.
3411 * @bin_attr: kernel attributes passed to us.
3412 * @buf: if successful contains the data from the adapter IOREG space.
3413 * @off: offset into buffer to beginning of data.
3414 * @count: bytes to transfer.
3417 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3418 * Uses the adapter io control registers to read data into buf.
3421 * -ERANGE off and count combo out of range
3422 * -EINVAL off, count or buff address invalid
3423 * value of count, buf contents read
3426 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3427 char *buf, loff_t off, size_t count)
3431 struct device *dev = container_of(kobj, struct device, kobj);
3432 struct Scsi_Host *shost = class_to_shost(dev);
3433 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3434 struct lpfc_hba *phba = vport->phba;
3436 if (phba->sli_rev >= LPFC_SLI_REV4)
3439 if (off > FF_REG_AREA_SIZE)
3442 if ((off + count) > FF_REG_AREA_SIZE)
3443 count = FF_REG_AREA_SIZE - off;
3445 if (count == 0) return 0;
3447 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3450 spin_lock_irq(&phba->hbalock);
3452 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3453 tmp_ptr = (uint32_t *)(buf + buf_off);
3454 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3457 spin_unlock_irq(&phba->hbalock);
3462 static struct bin_attribute sysfs_ctlreg_attr = {
3465 .mode = S_IRUSR | S_IWUSR,
3468 .read = sysfs_ctlreg_read,
3469 .write = sysfs_ctlreg_write,
3473 * sysfs_mbox_idle - frees the sysfs mailbox
3474 * @phba: lpfc_hba pointer
3477 sysfs_mbox_idle(struct lpfc_hba *phba)
3479 phba->sysfs_mbox.state = SMBOX_IDLE;
3480 phba->sysfs_mbox.offset = 0;
3482 if (phba->sysfs_mbox.mbox) {
3483 mempool_free(phba->sysfs_mbox.mbox,
3484 phba->mbox_mem_pool);
3485 phba->sysfs_mbox.mbox = NULL;
3490 * sysfs_mbox_write - Write method for writing information via mbox
3491 * @kobj: kernel kobject that contains the kernel class device.
3492 * @bin_attr: kernel attributes passed to us.
3493 * @buf: contains the data to be written to sysfs mbox.
3494 * @off: offset into buffer to beginning of data.
3495 * @count: bytes to transfer.
3498 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3499 * Uses the sysfs mbox to send buf contents to the adapter.
3502 * -ERANGE off and count combo out of range
3503 * -EINVAL off, count or buff address invalid
3504 * zero if count is zero
3505 * -EPERM adapter is offline
3506 * -ENOMEM failed to allocate memory for the mail box
3507 * -EAGAIN offset, state or mbox is NULL
3508 * count number of bytes transferred
3511 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
3512 char *buf, loff_t off, size_t count)
3514 struct device *dev = container_of(kobj, struct device, kobj);
3515 struct Scsi_Host *shost = class_to_shost(dev);
3516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3517 struct lpfc_hba *phba = vport->phba;
3518 struct lpfcMboxq *mbox = NULL;
3520 if ((count + off) > MAILBOX_CMD_SIZE)
3523 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3530 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3533 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3536 spin_lock_irq(&phba->hbalock);
3539 if (phba->sysfs_mbox.mbox)
3540 mempool_free(mbox, phba->mbox_mem_pool);
3542 phba->sysfs_mbox.mbox = mbox;
3543 phba->sysfs_mbox.state = SMBOX_WRITING;
3545 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3546 phba->sysfs_mbox.offset != off ||
3547 phba->sysfs_mbox.mbox == NULL) {
3548 sysfs_mbox_idle(phba);
3549 spin_unlock_irq(&phba->hbalock);
3554 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3557 phba->sysfs_mbox.offset = off + count;
3559 spin_unlock_irq(&phba->hbalock);
3565 * sysfs_mbox_read - Read method for reading information via mbox
3566 * @kobj: kernel kobject that contains the kernel class device.
3567 * @bin_attr: kernel attributes passed to us.
3568 * @buf: contains the data to be read from sysfs mbox.
3569 * @off: offset into buffer to beginning of data.
3570 * @count: bytes to transfer.
3573 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3574 * Uses the sysfs mbox to receive data from to the adapter.
3577 * -ERANGE off greater than mailbox command size
3578 * -EINVAL off, count or buff address invalid
3579 * zero if off and count are zero
3580 * -EACCES adapter over temp
3581 * -EPERM garbage can value to catch a multitude of errors
3582 * -EAGAIN management IO not permitted, state or off error
3583 * -ETIME mailbox timeout
3584 * -ENODEV mailbox error
3585 * count number of bytes transferred
3588 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
3589 char *buf, loff_t off, size_t count)
3591 struct device *dev = container_of(kobj, struct device, kobj);
3592 struct Scsi_Host *shost = class_to_shost(dev);
3593 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3594 struct lpfc_hba *phba = vport->phba;
3598 if (off > MAILBOX_CMD_SIZE)
3601 if ((count + off) > MAILBOX_CMD_SIZE)
3602 count = MAILBOX_CMD_SIZE - off;
3604 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3607 if (off && count == 0)
3610 spin_lock_irq(&phba->hbalock);
3612 if (phba->over_temp_state == HBA_OVER_TEMP) {
3613 sysfs_mbox_idle(phba);
3614 spin_unlock_irq(&phba->hbalock);
3619 phba->sysfs_mbox.state == SMBOX_WRITING &&
3620 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3621 pmb = &phba->sysfs_mbox.mbox->u.mb;
3622 switch (pmb->mbxCommand) {
3626 case MBX_CONFIG_LINK:
3627 case MBX_CONFIG_RING:
3628 case MBX_RESET_RING:
3629 case MBX_UNREG_LOGIN:
3631 case MBX_DUMP_CONTEXT:
3636 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3637 printk(KERN_WARNING "mbox_read:Command 0x%x "
3638 "is illegal in on-line state\n",
3640 sysfs_mbox_idle(phba);
3641 spin_unlock_irq(&phba->hbalock);
3645 case MBX_WRITE_VPARMS:
3648 case MBX_READ_CONFIG:
3649 case MBX_READ_RCONFIG:
3650 case MBX_READ_STATUS:
3653 case MBX_READ_LNK_STAT:
3654 case MBX_DUMP_MEMORY:
3656 case MBX_UPDATE_CFG:
3657 case MBX_KILL_BOARD:
3659 case MBX_LOAD_EXP_ROM:
3661 case MBX_DEL_LD_ENTRY:
3662 case MBX_SET_VARIABLE:
3664 case MBX_PORT_CAPABILITIES:
3665 case MBX_PORT_IOV_CONTROL:
3667 case MBX_READ_SPARM64:
3671 case MBX_REG_LOGIN64:
3672 case MBX_CONFIG_PORT:
3673 case MBX_RUN_BIU_DIAG:
3674 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3676 sysfs_mbox_idle(phba);
3677 spin_unlock_irq(&phba->hbalock);
3680 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3682 sysfs_mbox_idle(phba);
3683 spin_unlock_irq(&phba->hbalock);
3687 /* If HBA encountered an error attention, allow only DUMP
3688 * or RESTART mailbox commands until the HBA is restarted.
3690 if (phba->pport->stopped &&
3691 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3692 pmb->mbxCommand != MBX_RESTART &&
3693 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3694 pmb->mbxCommand != MBX_WRITE_WWN)
3695 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3696 "1259 mbox: Issued mailbox cmd "
3697 "0x%x while in stopped state.\n",
3700 phba->sysfs_mbox.mbox->vport = vport;
3702 /* Don't allow mailbox commands to be sent when blocked
3703 * or when in the middle of discovery
3705 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3706 sysfs_mbox_idle(phba);
3707 spin_unlock_irq(&phba->hbalock);
3711 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3712 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3714 spin_unlock_irq(&phba->hbalock);
3715 rc = lpfc_sli_issue_mbox (phba,
3716 phba->sysfs_mbox.mbox,
3718 spin_lock_irq(&phba->hbalock);
3721 spin_unlock_irq(&phba->hbalock);
3722 rc = lpfc_sli_issue_mbox_wait (phba,
3723 phba->sysfs_mbox.mbox,
3724 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3725 spin_lock_irq(&phba->hbalock);
3728 if (rc != MBX_SUCCESS) {
3729 if (rc == MBX_TIMEOUT) {
3730 phba->sysfs_mbox.mbox = NULL;
3732 sysfs_mbox_idle(phba);
3733 spin_unlock_irq(&phba->hbalock);
3734 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3736 phba->sysfs_mbox.state = SMBOX_READING;
3738 else if (phba->sysfs_mbox.offset != off ||
3739 phba->sysfs_mbox.state != SMBOX_READING) {
3740 printk(KERN_WARNING "mbox_read: Bad State\n");
3741 sysfs_mbox_idle(phba);
3742 spin_unlock_irq(&phba->hbalock);
3746 memcpy(buf, (uint8_t *) &pmb + off, count);
3748 phba->sysfs_mbox.offset = off + count;
3750 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3751 sysfs_mbox_idle(phba);
3753 spin_unlock_irq(&phba->hbalock);
3758 static struct bin_attribute sysfs_mbox_attr = {
3761 .mode = S_IRUSR | S_IWUSR,
3763 .size = MAILBOX_CMD_SIZE,
3764 .read = sysfs_mbox_read,
3765 .write = sysfs_mbox_write,
3769 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3770 * @vport: address of lpfc vport structure.
3774 * error return code from sysfs_create_bin_file()
3777 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3779 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3782 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3783 &sysfs_drvr_stat_data_attr);
3785 /* Virtual ports do not need ctrl_reg and mbox */
3786 if (error || vport->port_type == LPFC_NPIV_PORT)
3789 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3790 &sysfs_ctlreg_attr);
3792 goto out_remove_stat_attr;
3794 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3797 goto out_remove_ctlreg_attr;
3800 out_remove_ctlreg_attr:
3801 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3802 out_remove_stat_attr:
3803 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3804 &sysfs_drvr_stat_data_attr);
3810 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
3811 * @vport: address of lpfc vport structure.
3814 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
3816 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3817 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3818 &sysfs_drvr_stat_data_attr);
3819 /* Virtual ports do not need ctrl_reg and mbox */
3820 if (vport->port_type == LPFC_NPIV_PORT)
3822 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3823 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3828 * Dynamic FC Host Attributes Support
3832 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
3833 * @shost: kernel scsi host pointer.
3836 lpfc_get_host_port_id(struct Scsi_Host *shost)
3838 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3840 /* note: fc_myDID already in cpu endianness */
3841 fc_host_port_id(shost) = vport->fc_myDID;
3845 * lpfc_get_host_port_type - Set the value of the scsi host port type
3846 * @shost: kernel scsi host pointer.
3849 lpfc_get_host_port_type(struct Scsi_Host *shost)
3851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3852 struct lpfc_hba *phba = vport->phba;
3854 spin_lock_irq(shost->host_lock);
3856 if (vport->port_type == LPFC_NPIV_PORT) {
3857 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3858 } else if (lpfc_is_link_up(phba)) {
3859 if (phba->fc_topology == TOPOLOGY_LOOP) {
3860 if (vport->fc_flag & FC_PUBLIC_LOOP)
3861 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3863 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3865 if (vport->fc_flag & FC_FABRIC)
3866 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3868 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3871 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3873 spin_unlock_irq(shost->host_lock);
3877 * lpfc_get_host_port_state - Set the value of the scsi host port state
3878 * @shost: kernel scsi host pointer.
3881 lpfc_get_host_port_state(struct Scsi_Host *shost)
3883 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3884 struct lpfc_hba *phba = vport->phba;
3886 spin_lock_irq(shost->host_lock);
3888 if (vport->fc_flag & FC_OFFLINE_MODE)
3889 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3891 switch (phba->link_state) {
3892 case LPFC_LINK_UNKNOWN:
3893 case LPFC_LINK_DOWN:
3894 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3898 case LPFC_HBA_READY:
3899 /* Links up, beyond this port_type reports state */
3900 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3902 case LPFC_HBA_ERROR:
3903 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3906 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3911 spin_unlock_irq(shost->host_lock);
3915 * lpfc_get_host_speed - Set the value of the scsi host speed
3916 * @shost: kernel scsi host pointer.
3919 lpfc_get_host_speed(struct Scsi_Host *shost)
3921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3922 struct lpfc_hba *phba = vport->phba;
3924 spin_lock_irq(shost->host_lock);
3926 if (lpfc_is_link_up(phba)) {
3927 switch(phba->fc_linkspeed) {
3929 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
3932 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
3935 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
3938 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
3941 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
3944 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3948 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
3950 spin_unlock_irq(shost->host_lock);
3954 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
3955 * @shost: kernel scsi host pointer.
3958 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
3960 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3961 struct lpfc_hba *phba = vport->phba;
3964 spin_lock_irq(shost->host_lock);
3966 if ((vport->fc_flag & FC_FABRIC) ||
3967 ((phba->fc_topology == TOPOLOGY_LOOP) &&
3968 (vport->fc_flag & FC_PUBLIC_LOOP)))
3969 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
3971 /* fabric is local port if there is no F/FL_Port */
3974 spin_unlock_irq(shost->host_lock);
3976 fc_host_fabric_name(shost) = node_name;
3980 * lpfc_get_stats - Return statistical information about the adapter
3981 * @shost: kernel scsi host pointer.
3984 * NULL on error for link down, no mbox pool, sli2 active,
3985 * management not allowed, memory allocation error, or mbox error.
3989 * address of the adapter host statistics
3991 static struct fc_host_statistics *
3992 lpfc_get_stats(struct Scsi_Host *shost)
3994 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3995 struct lpfc_hba *phba = vport->phba;
3996 struct lpfc_sli *psli = &phba->sli;
3997 struct fc_host_statistics *hs = &phba->link_stats;
3998 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
3999 LPFC_MBOXQ_t *pmboxq;
4001 unsigned long seconds;
4005 * prevent udev from issuing mailbox commands until the port is
4008 if (phba->link_state < LPFC_LINK_DOWN ||
4009 !phba->mbox_mem_pool ||
4010 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4013 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4016 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4019 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4021 pmb = &pmboxq->u.mb;
4022 pmb->mbxCommand = MBX_READ_STATUS;
4023 pmb->mbxOwner = OWN_HOST;
4024 pmboxq->context1 = NULL;
4025 pmboxq->vport = vport;
4027 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4028 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4029 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4031 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4033 if (rc != MBX_SUCCESS) {
4034 if (rc != MBX_TIMEOUT)
4035 mempool_free(pmboxq, phba->mbox_mem_pool);
4039 memset(hs, 0, sizeof (struct fc_host_statistics));
4041 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4042 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4043 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4044 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4046 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4047 pmb->mbxCommand = MBX_READ_LNK_STAT;
4048 pmb->mbxOwner = OWN_HOST;
4049 pmboxq->context1 = NULL;
4050 pmboxq->vport = vport;
4052 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4053 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4054 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4056 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4058 if (rc != MBX_SUCCESS) {
4059 if (rc != MBX_TIMEOUT)
4060 mempool_free(pmboxq, phba->mbox_mem_pool);
4064 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4065 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4066 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4067 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4068 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4069 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4070 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4072 hs->link_failure_count -= lso->link_failure_count;
4073 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4074 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4075 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4076 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4077 hs->invalid_crc_count -= lso->invalid_crc_count;
4078 hs->error_frames -= lso->error_frames;
4080 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4082 hs->nos_count = (phba->link_events >> 1);
4083 hs->nos_count -= lso->link_events;
4084 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
4085 hs->lip_count = (phba->fc_eventTag >> 1);
4086 hs->lip_count -= lso->link_events;
4090 hs->nos_count = (phba->fc_eventTag >> 1);
4091 hs->nos_count -= lso->link_events;
4094 hs->dumped_frames = -1;
4096 seconds = get_seconds();
4097 if (seconds < psli->stats_start)
4098 hs->seconds_since_last_reset = seconds +
4099 ((unsigned long)-1 - psli->stats_start);
4101 hs->seconds_since_last_reset = seconds - psli->stats_start;
4103 mempool_free(pmboxq, phba->mbox_mem_pool);
4109 * lpfc_reset_stats - Copy the adapter link stats information
4110 * @shost: kernel scsi host pointer.
4113 lpfc_reset_stats(struct Scsi_Host *shost)
4115 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4116 struct lpfc_hba *phba = vport->phba;
4117 struct lpfc_sli *psli = &phba->sli;
4118 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4119 LPFC_MBOXQ_t *pmboxq;
4123 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4126 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4129 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4131 pmb = &pmboxq->u.mb;
4132 pmb->mbxCommand = MBX_READ_STATUS;
4133 pmb->mbxOwner = OWN_HOST;
4134 pmb->un.varWords[0] = 0x1; /* reset request */
4135 pmboxq->context1 = NULL;
4136 pmboxq->vport = vport;
4138 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4139 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4140 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4142 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4144 if (rc != MBX_SUCCESS) {
4145 if (rc != MBX_TIMEOUT)
4146 mempool_free(pmboxq, phba->mbox_mem_pool);
4150 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4151 pmb->mbxCommand = MBX_READ_LNK_STAT;
4152 pmb->mbxOwner = OWN_HOST;
4153 pmboxq->context1 = NULL;
4154 pmboxq->vport = vport;
4156 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4157 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4158 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4160 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4162 if (rc != MBX_SUCCESS) {
4163 if (rc != MBX_TIMEOUT)
4164 mempool_free( pmboxq, phba->mbox_mem_pool);
4168 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4169 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4170 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4171 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4172 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4173 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4174 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4175 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4176 lso->link_events = (phba->link_events >> 1);
4178 lso->link_events = (phba->fc_eventTag >> 1);
4180 psli->stats_start = get_seconds();
4182 mempool_free(pmboxq, phba->mbox_mem_pool);
4188 * The LPFC driver treats linkdown handling as target loss events so there
4189 * are no sysfs handlers for link_down_tmo.
4193 * lpfc_get_node_by_target - Return the nodelist for a target
4194 * @starget: kernel scsi target pointer.
4197 * address of the node list if found
4198 * NULL target not found
4200 static struct lpfc_nodelist *
4201 lpfc_get_node_by_target(struct scsi_target *starget)
4203 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4204 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4205 struct lpfc_nodelist *ndlp;
4207 spin_lock_irq(shost->host_lock);
4208 /* Search for this, mapped, target ID */
4209 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4210 if (NLP_CHK_NODE_ACT(ndlp) &&
4211 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4212 starget->id == ndlp->nlp_sid) {
4213 spin_unlock_irq(shost->host_lock);
4217 spin_unlock_irq(shost->host_lock);
4222 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4223 * @starget: kernel scsi target pointer.
4226 lpfc_get_starget_port_id(struct scsi_target *starget)
4228 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4230 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4234 * lpfc_get_starget_node_name - Set the target node name
4235 * @starget: kernel scsi target pointer.
4237 * Description: Set the target node name to the ndlp node name wwn or zero.
4240 lpfc_get_starget_node_name(struct scsi_target *starget)
4242 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4244 fc_starget_node_name(starget) =
4245 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4249 * lpfc_get_starget_port_name - Set the target port name
4250 * @starget: kernel scsi target pointer.
4252 * Description: set the target port name to the ndlp port name wwn or zero.
4255 lpfc_get_starget_port_name(struct scsi_target *starget)
4257 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4259 fc_starget_port_name(starget) =
4260 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4264 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4265 * @rport: fc rport address.
4266 * @timeout: new value for dev loss tmo.
4269 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4270 * dev_loss_tmo to one.
4273 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4276 rport->dev_loss_tmo = timeout;
4278 rport->dev_loss_tmo = 1;
4282 * lpfc_rport_show_function - Return rport target information
4285 * Macro that uses field to generate a function with the name lpfc_show_rport_
4287 * lpfc_show_rport_##field: returns the bytes formatted in buf
4288 * @cdev: class converted to an fc_rport.
4289 * @buf: on return contains the target_field or zero.
4291 * Returns: size of formatted string.
4293 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4295 lpfc_show_rport_##field (struct device *dev, \
4296 struct device_attribute *attr, \
4299 struct fc_rport *rport = transport_class_to_rport(dev); \
4300 struct lpfc_rport_data *rdata = rport->hostdata; \
4301 return snprintf(buf, sz, format_string, \
4302 (rdata->target) ? cast rdata->target->field : 0); \
4305 #define lpfc_rport_rd_attr(field, format_string, sz) \
4306 lpfc_rport_show_function(field, format_string, sz, ) \
4307 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4310 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4311 * @fc_vport: The fc_vport who's symbolic name has been changed.
4314 * This function is called by the transport after the @fc_vport's symbolic name
4315 * has been changed. This function re-registers the symbolic name with the
4316 * switch to propogate the change into the fabric if the vport is active.
4319 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4321 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4323 if (vport->port_state == LPFC_VPORT_READY)
4324 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4328 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4329 * @phba: Pointer to lpfc_hba struct.
4331 * This function is called by the lpfc_get_cfgparam() routine to set the
4332 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4333 * log messsage according to the module's lpfc_log_verbose parameter setting
4334 * before hba port or vport created.
4337 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4339 phba->cfg_log_verbose = verbose;
4342 struct fc_function_template lpfc_transport_functions = {
4343 /* fixed attributes the driver supports */
4344 .show_host_node_name = 1,
4345 .show_host_port_name = 1,
4346 .show_host_supported_classes = 1,
4347 .show_host_supported_fc4s = 1,
4348 .show_host_supported_speeds = 1,
4349 .show_host_maxframe_size = 1,
4350 .show_host_symbolic_name = 1,
4352 /* dynamic attributes the driver supports */
4353 .get_host_port_id = lpfc_get_host_port_id,
4354 .show_host_port_id = 1,
4356 .get_host_port_type = lpfc_get_host_port_type,
4357 .show_host_port_type = 1,
4359 .get_host_port_state = lpfc_get_host_port_state,
4360 .show_host_port_state = 1,
4362 /* active_fc4s is shown but doesn't change (thus no get function) */
4363 .show_host_active_fc4s = 1,
4365 .get_host_speed = lpfc_get_host_speed,
4366 .show_host_speed = 1,
4368 .get_host_fabric_name = lpfc_get_host_fabric_name,
4369 .show_host_fabric_name = 1,
4372 * The LPFC driver treats linkdown handling as target loss events
4373 * so there are no sysfs handlers for link_down_tmo.
4376 .get_fc_host_stats = lpfc_get_stats,
4377 .reset_fc_host_stats = lpfc_reset_stats,
4379 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4380 .show_rport_maxframe_size = 1,
4381 .show_rport_supported_classes = 1,
4383 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4384 .show_rport_dev_loss_tmo = 1,
4386 .get_starget_port_id = lpfc_get_starget_port_id,
4387 .show_starget_port_id = 1,
4389 .get_starget_node_name = lpfc_get_starget_node_name,
4390 .show_starget_node_name = 1,
4392 .get_starget_port_name = lpfc_get_starget_port_name,
4393 .show_starget_port_name = 1,
4395 .issue_fc_host_lip = lpfc_issue_lip,
4396 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4397 .terminate_rport_io = lpfc_terminate_rport_io,
4399 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4401 .vport_disable = lpfc_vport_disable,
4403 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4405 .bsg_request = lpfc_bsg_request,
4406 .bsg_timeout = lpfc_bsg_timeout,
4409 struct fc_function_template lpfc_vport_transport_functions = {
4410 /* fixed attributes the driver supports */
4411 .show_host_node_name = 1,
4412 .show_host_port_name = 1,
4413 .show_host_supported_classes = 1,
4414 .show_host_supported_fc4s = 1,
4415 .show_host_supported_speeds = 1,
4416 .show_host_maxframe_size = 1,
4417 .show_host_symbolic_name = 1,
4419 /* dynamic attributes the driver supports */
4420 .get_host_port_id = lpfc_get_host_port_id,
4421 .show_host_port_id = 1,
4423 .get_host_port_type = lpfc_get_host_port_type,
4424 .show_host_port_type = 1,
4426 .get_host_port_state = lpfc_get_host_port_state,
4427 .show_host_port_state = 1,
4429 /* active_fc4s is shown but doesn't change (thus no get function) */
4430 .show_host_active_fc4s = 1,
4432 .get_host_speed = lpfc_get_host_speed,
4433 .show_host_speed = 1,
4435 .get_host_fabric_name = lpfc_get_host_fabric_name,
4436 .show_host_fabric_name = 1,
4439 * The LPFC driver treats linkdown handling as target loss events
4440 * so there are no sysfs handlers for link_down_tmo.
4443 .get_fc_host_stats = lpfc_get_stats,
4444 .reset_fc_host_stats = lpfc_reset_stats,
4446 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4447 .show_rport_maxframe_size = 1,
4448 .show_rport_supported_classes = 1,
4450 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4451 .show_rport_dev_loss_tmo = 1,
4453 .get_starget_port_id = lpfc_get_starget_port_id,
4454 .show_starget_port_id = 1,
4456 .get_starget_node_name = lpfc_get_starget_node_name,
4457 .show_starget_node_name = 1,
4459 .get_starget_port_name = lpfc_get_starget_port_name,
4460 .show_starget_port_name = 1,
4462 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4463 .terminate_rport_io = lpfc_terminate_rport_io,
4465 .vport_disable = lpfc_vport_disable,
4467 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4471 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4472 * @phba: lpfc_hba pointer.
4475 lpfc_get_cfgparam(struct lpfc_hba *phba)
4477 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4478 lpfc_cr_count_init(phba, lpfc_cr_count);
4479 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4480 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4481 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4482 lpfc_ack0_init(phba, lpfc_ack0);
4483 lpfc_topology_init(phba, lpfc_topology);
4484 lpfc_link_speed_init(phba, lpfc_link_speed);
4485 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4486 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4487 lpfc_use_msi_init(phba, lpfc_use_msi);
4488 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4489 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4490 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4491 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4492 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4493 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4494 if (phba->sli_rev == LPFC_SLI_REV4)
4497 phba->cfg_poll = lpfc_poll;
4498 phba->cfg_soft_wwnn = 0L;
4499 phba->cfg_soft_wwpn = 0L;
4500 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4501 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4502 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4503 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4504 lpfc_aer_support_init(phba, lpfc_aer_support);
4505 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4510 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4511 * @vport: lpfc_vport pointer.
4514 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4516 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4517 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4518 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4519 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4520 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4521 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4522 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4523 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4524 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4525 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4526 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4527 lpfc_max_luns_init(vport, lpfc_max_luns);
4528 lpfc_scan_down_init(vport, lpfc_scan_down);
4529 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);