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>
27 #include <linux/gfp.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_tcq.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <scsi/fc/fc_fs.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_version.h"
46 #include "lpfc_compat.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
50 #define LPFC_DEF_DEVLOSS_TMO 30
51 #define LPFC_MIN_DEVLOSS_TMO 1
52 #define LPFC_MAX_DEVLOSS_TMO 255
54 #define LPFC_MAX_LINK_SPEED 8
55 #define LPFC_LINK_SPEED_BITMAP 0x00000117
56 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
59 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
60 * @incr: integer to convert.
61 * @hdw: ascii string holding converted integer plus a string terminator.
64 * JEDEC Joint Electron Device Engineering Council.
65 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
66 * character string. The string is then terminated with a NULL in byte 9.
67 * Hex 0-9 becomes ascii '0' to '9'.
68 * Hex a-f becomes ascii '=' to 'B' capital B.
71 * Coded for 32 bit integers only.
74 lpfc_jedec_to_ascii(int incr, char hdw[])
77 for (i = 0; i < 8; i++) {
80 hdw[7 - i] = 0x30 + j;
82 hdw[7 - i] = 0x61 + j - 10;
90 * lpfc_drvr_version_show - Return the Emulex driver string with version number
91 * @dev: class unused variable.
92 * @attr: device attribute, not used.
93 * @buf: on return contains the module description text.
95 * Returns: size of formatted string.
98 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
101 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
105 * lpfc_enable_fip_show - Return the fip mode of the HBA
106 * @dev: class unused variable.
107 * @attr: device attribute, not used.
108 * @buf: on return contains the module description text.
110 * Returns: size of formatted string.
113 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
116 struct Scsi_Host *shost = class_to_shost(dev);
117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
118 struct lpfc_hba *phba = vport->phba;
120 if (phba->hba_flag & HBA_FIP_SUPPORT)
121 return snprintf(buf, PAGE_SIZE, "1\n");
123 return snprintf(buf, PAGE_SIZE, "0\n");
127 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
130 struct Scsi_Host *shost = class_to_shost(dev);
131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
132 struct lpfc_hba *phba = vport->phba;
134 if (phba->cfg_enable_bg)
135 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
136 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Not Supported\n");
141 return snprintf(buf, PAGE_SIZE,
142 "BlockGuard Disabled\n");
146 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
149 struct Scsi_Host *shost = class_to_shost(dev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
153 return snprintf(buf, PAGE_SIZE, "%llu\n",
154 (unsigned long long)phba->bg_guard_err_cnt);
158 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
161 struct Scsi_Host *shost = class_to_shost(dev);
162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
163 struct lpfc_hba *phba = vport->phba;
165 return snprintf(buf, PAGE_SIZE, "%llu\n",
166 (unsigned long long)phba->bg_apptag_err_cnt);
170 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
173 struct Scsi_Host *shost = class_to_shost(dev);
174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
175 struct lpfc_hba *phba = vport->phba;
177 return snprintf(buf, PAGE_SIZE, "%llu\n",
178 (unsigned long long)phba->bg_reftag_err_cnt);
182 * lpfc_info_show - Return some pci info about the host in ascii
183 * @dev: class converted to a Scsi_host structure.
184 * @attr: device attribute, not used.
185 * @buf: on return contains the formatted text from lpfc_info().
187 * Returns: size of formatted string.
190 lpfc_info_show(struct device *dev, struct device_attribute *attr,
193 struct Scsi_Host *host = class_to_shost(dev);
195 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
199 * lpfc_serialnum_show - Return the hba serial number in ascii
200 * @dev: class converted to a Scsi_host structure.
201 * @attr: device attribute, not used.
202 * @buf: on return contains the formatted text serial number.
204 * Returns: size of formatted string.
207 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
210 struct Scsi_Host *shost = class_to_shost(dev);
211 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
212 struct lpfc_hba *phba = vport->phba;
214 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
218 * lpfc_temp_sensor_show - Return the temperature sensor level
219 * @dev: class converted to a Scsi_host structure.
220 * @attr: device attribute, not used.
221 * @buf: on return contains the formatted support level.
224 * Returns a number indicating the temperature sensor level currently
225 * supported, zero or one in ascii.
227 * Returns: size of formatted string.
230 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
233 struct Scsi_Host *shost = class_to_shost(dev);
234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
235 struct lpfc_hba *phba = vport->phba;
236 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
240 * lpfc_modeldesc_show - Return the model description of the hba
241 * @dev: class converted to a Scsi_host structure.
242 * @attr: device attribute, not used.
243 * @buf: on return contains the scsi vpd model description.
245 * Returns: size of formatted string.
248 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
251 struct Scsi_Host *shost = class_to_shost(dev);
252 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
253 struct lpfc_hba *phba = vport->phba;
255 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
259 * lpfc_modelname_show - Return the model name of the hba
260 * @dev: class converted to a Scsi_host structure.
261 * @attr: device attribute, not used.
262 * @buf: on return contains the scsi vpd model name.
264 * Returns: size of formatted string.
267 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
270 struct Scsi_Host *shost = class_to_shost(dev);
271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
272 struct lpfc_hba *phba = vport->phba;
274 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
278 * lpfc_programtype_show - Return the program type of the hba
279 * @dev: class converted to a Scsi_host structure.
280 * @attr: device attribute, not used.
281 * @buf: on return contains the scsi vpd program type.
283 * Returns: size of formatted string.
286 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
289 struct Scsi_Host *shost = class_to_shost(dev);
290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
291 struct lpfc_hba *phba = vport->phba;
293 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
297 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
298 * @dev: class converted to a Scsi_host structure.
299 * @attr: device attribute, not used.
300 * @buf: on return contains the Menlo Maintenance sli flag.
302 * Returns: size of formatted string.
305 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
307 struct Scsi_Host *shost = class_to_shost(dev);
308 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
309 struct lpfc_hba *phba = vport->phba;
311 return snprintf(buf, PAGE_SIZE, "%d\n",
312 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
316 * lpfc_vportnum_show - Return the port number in ascii of the hba
317 * @dev: class converted to a Scsi_host structure.
318 * @attr: device attribute, not used.
319 * @buf: on return contains scsi vpd program type.
321 * Returns: size of formatted string.
324 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
327 struct Scsi_Host *shost = class_to_shost(dev);
328 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
329 struct lpfc_hba *phba = vport->phba;
331 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
335 * lpfc_fwrev_show - Return the firmware rev running in the hba
336 * @dev: class converted to a Scsi_host structure.
337 * @attr: device attribute, not used.
338 * @buf: on return contains the scsi vpd program type.
340 * Returns: size of formatted string.
343 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
346 struct Scsi_Host *shost = class_to_shost(dev);
347 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
348 struct lpfc_hba *phba = vport->phba;
351 lpfc_decode_firmware_rev(phba, fwrev, 1);
352 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
356 * lpfc_hdw_show - Return the jedec information about the hba
357 * @dev: class converted to a Scsi_host structure.
358 * @attr: device attribute, not used.
359 * @buf: on return contains the scsi vpd program type.
361 * Returns: size of formatted string.
364 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
367 struct Scsi_Host *shost = class_to_shost(dev);
368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
369 struct lpfc_hba *phba = vport->phba;
370 lpfc_vpd_t *vp = &phba->vpd;
372 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
373 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
377 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
378 * @dev: class converted to a Scsi_host structure.
379 * @attr: device attribute, not used.
380 * @buf: on return contains the ROM and FCode ascii strings.
382 * Returns: size of formatted string.
385 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
388 struct Scsi_Host *shost = class_to_shost(dev);
389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
390 struct lpfc_hba *phba = vport->phba;
392 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
396 * lpfc_state_show - Return the link state of the port
397 * @dev: class converted to a Scsi_host structure.
398 * @attr: device attribute, not used.
399 * @buf: on return contains text describing the state of the link.
402 * The switch statement has no default so zero will be returned.
404 * Returns: size of formatted string.
407 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
410 struct Scsi_Host *shost = class_to_shost(dev);
411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
412 struct lpfc_hba *phba = vport->phba;
415 switch (phba->link_state) {
416 case LPFC_LINK_UNKNOWN:
417 case LPFC_WARM_START:
418 case LPFC_INIT_START:
419 case LPFC_INIT_MBX_CMDS:
422 if (phba->hba_flag & LINK_DISABLED)
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down - User disabled\n");
426 len += snprintf(buf + len, PAGE_SIZE-len,
432 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
434 switch (vport->port_state) {
435 case LPFC_LOCAL_CFG_LINK:
436 len += snprintf(buf + len, PAGE_SIZE-len,
437 "Configuring Link\n");
441 case LPFC_FABRIC_CFG_LINK:
444 case LPFC_BUILD_DISC_LIST:
446 len += snprintf(buf + len, PAGE_SIZE - len,
449 case LPFC_VPORT_READY:
450 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
453 case LPFC_VPORT_FAILED:
454 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
457 case LPFC_VPORT_UNKNOWN:
458 len += snprintf(buf + len, PAGE_SIZE - len,
462 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
463 len += snprintf(buf + len, PAGE_SIZE-len,
464 " Menlo Maint Mode\n");
465 else if (phba->fc_topology == TOPOLOGY_LOOP) {
466 if (vport->fc_flag & FC_PUBLIC_LOOP)
467 len += snprintf(buf + len, PAGE_SIZE-len,
470 len += snprintf(buf + len, PAGE_SIZE-len,
473 if (vport->fc_flag & FC_FABRIC)
474 len += snprintf(buf + len, PAGE_SIZE-len,
477 len += snprintf(buf + len, PAGE_SIZE-len,
486 * lpfc_link_state_store - Transition the link_state on an HBA port
487 * @dev: class device that is converted into a Scsi_host.
488 * @attr: device attribute, not used.
489 * @buf: one or more lpfc_polling_flags values.
493 * -EINVAL if the buffer is not "up" or "down"
494 * return from link state change function if non-zero
495 * length of the buf on success
498 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
499 const char *buf, size_t count)
501 struct Scsi_Host *shost = class_to_shost(dev);
502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
503 struct lpfc_hba *phba = vport->phba;
505 int status = -EINVAL;
507 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
508 (phba->link_state == LPFC_LINK_DOWN))
509 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
510 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
511 (phba->link_state >= LPFC_LINK_UP))
512 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
521 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
522 * @dev: class device that is converted into a Scsi_host.
523 * @attr: device attribute, not used.
524 * @buf: on return contains the sum of fc mapped and unmapped.
527 * Returns the ascii text number of the sum of the fc mapped and unmapped
530 * Returns: size of formatted string.
533 lpfc_num_discovered_ports_show(struct device *dev,
534 struct device_attribute *attr, char *buf)
536 struct Scsi_Host *shost = class_to_shost(dev);
537 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
539 return snprintf(buf, PAGE_SIZE, "%d\n",
540 vport->fc_map_cnt + vport->fc_unmap_cnt);
544 * lpfc_issue_lip - Misnomer, name carried over from long ago
545 * @shost: Scsi_Host pointer.
548 * Bring the link down gracefully then re-init the link. The firmware will
549 * re-init the fiber channel interface as required. Does not issue a LIP.
552 * -EPERM port offline or management commands are being blocked
553 * -ENOMEM cannot allocate memory for the mailbox command
554 * -EIO error sending the mailbox command
558 lpfc_issue_lip(struct Scsi_Host *shost)
560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
561 struct lpfc_hba *phba = vport->phba;
562 LPFC_MBOXQ_t *pmboxq;
563 int mbxstatus = MBXERR_ERROR;
565 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
566 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
569 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
574 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
575 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
576 pmboxq->u.mb.mbxOwner = OWN_HOST;
578 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
580 if ((mbxstatus == MBX_SUCCESS) &&
581 (pmboxq->u.mb.mbxStatus == 0 ||
582 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
583 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
584 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
585 phba->cfg_link_speed);
586 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
590 lpfc_set_loopback_flag(phba);
591 if (mbxstatus != MBX_TIMEOUT)
592 mempool_free(pmboxq, phba->mbox_mem_pool);
594 if (mbxstatus == MBXERR_ERROR)
601 * lpfc_do_offline - Issues a mailbox command to bring the link down
602 * @phba: lpfc_hba pointer.
603 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
606 * Assumes any error from lpfc_do_offline() will be negative.
607 * Can wait up to 5 seconds for the port ring buffers count
608 * to reach zero, prints a warning if it is not zero and continues.
609 * lpfc_workq_post_event() returns a non-zero return code if call fails.
612 * -EIO error posting the event
616 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
618 struct completion online_compl;
619 struct lpfc_sli_ring *pring;
620 struct lpfc_sli *psli;
625 init_completion(&online_compl);
626 lpfc_workq_post_event(phba, &status, &online_compl,
627 LPFC_EVT_OFFLINE_PREP);
628 wait_for_completion(&online_compl);
635 /* Wait a little for things to settle down, but not
636 * long enough for dev loss timeout to expire.
638 for (i = 0; i < psli->num_rings; i++) {
639 pring = &psli->ring[i];
640 while (pring->txcmplq_cnt) {
642 if (cnt++ > 500) { /* 5 secs */
643 lpfc_printf_log(phba,
644 KERN_WARNING, LOG_INIT,
645 "0466 Outstanding IO when "
646 "bringing Adapter offline\n");
652 init_completion(&online_compl);
653 lpfc_workq_post_event(phba, &status, &online_compl, type);
654 wait_for_completion(&online_compl);
663 * lpfc_selective_reset - Offline then onlines the port
664 * @phba: lpfc_hba pointer.
667 * If the port is configured to allow a reset then the hba is brought
668 * offline then online.
671 * Assumes any error from lpfc_do_offline() will be negative.
674 * lpfc_do_offline() return code if not zero
675 * -EIO reset not configured or error posting the event
679 lpfc_selective_reset(struct lpfc_hba *phba)
681 struct completion online_compl;
684 if (!phba->cfg_enable_hba_reset)
687 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
692 init_completion(&online_compl);
693 lpfc_workq_post_event(phba, &status, &online_compl,
695 wait_for_completion(&online_compl);
704 * lpfc_issue_reset - Selectively resets an adapter
705 * @dev: class device that is converted into a Scsi_host.
706 * @attr: device attribute, not used.
707 * @buf: containing the string "selective".
708 * @count: unused variable.
711 * If the buf contains the string "selective" then lpfc_selective_reset()
712 * is called to perform the reset.
715 * Assumes any error from lpfc_selective_reset() will be negative.
716 * If lpfc_selective_reset() returns zero then the length of the buffer
717 * is returned which indicates success
720 * -EINVAL if the buffer does not contain the string "selective"
721 * length of buf if lpfc-selective_reset() if the call succeeds
722 * return value of lpfc_selective_reset() if the call fails
725 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
726 const char *buf, size_t count)
728 struct Scsi_Host *shost = class_to_shost(dev);
729 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
730 struct lpfc_hba *phba = vport->phba;
732 int status = -EINVAL;
734 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
735 status = lpfc_selective_reset(phba);
744 * lpfc_nport_evt_cnt_show - Return the number of nport events
745 * @dev: class device that is converted into a Scsi_host.
746 * @attr: device attribute, not used.
747 * @buf: on return contains the ascii number of nport events.
749 * Returns: size of formatted string.
752 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
755 struct Scsi_Host *shost = class_to_shost(dev);
756 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
757 struct lpfc_hba *phba = vport->phba;
759 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
763 * lpfc_board_mode_show - Return the state of the board
764 * @dev: class device that is converted into a Scsi_host.
765 * @attr: device attribute, not used.
766 * @buf: on return contains the state of the adapter.
768 * Returns: size of formatted string.
771 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
774 struct Scsi_Host *shost = class_to_shost(dev);
775 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
776 struct lpfc_hba *phba = vport->phba;
779 if (phba->link_state == LPFC_HBA_ERROR)
781 else if (phba->link_state == LPFC_WARM_START)
782 state = "warm start";
783 else if (phba->link_state == LPFC_INIT_START)
788 return snprintf(buf, PAGE_SIZE, "%s\n", state);
792 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
793 * @dev: class device that is converted into a Scsi_host.
794 * @attr: device attribute, not used.
795 * @buf: containing one of the strings "online", "offline", "warm" or "error".
796 * @count: unused variable.
799 * -EACCES if enable hba reset not enabled
800 * -EINVAL if the buffer does not contain a valid string (see above)
801 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
802 * buf length greater than zero indicates success
805 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
806 const char *buf, size_t count)
808 struct Scsi_Host *shost = class_to_shost(dev);
809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
810 struct lpfc_hba *phba = vport->phba;
811 struct completion online_compl;
814 if (!phba->cfg_enable_hba_reset)
816 init_completion(&online_compl);
818 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
819 lpfc_workq_post_event(phba, &status, &online_compl,
821 wait_for_completion(&online_compl);
822 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
823 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
824 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
825 if (phba->sli_rev == LPFC_SLI_REV4)
828 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
829 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
830 if (phba->sli_rev == LPFC_SLI_REV4)
833 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
844 * lpfc_get_hba_info - Return various bits of informaton about the adapter
845 * @phba: pointer to the adapter structure.
846 * @mxri: max xri count.
847 * @axri: available xri count.
848 * @mrpi: max rpi count.
849 * @arpi: available rpi count.
850 * @mvpi: max vpi count.
851 * @avpi: available vpi count.
854 * If an integer pointer for an count is not null then the value for the
862 lpfc_get_hba_info(struct lpfc_hba *phba,
863 uint32_t *mxri, uint32_t *axri,
864 uint32_t *mrpi, uint32_t *arpi,
865 uint32_t *mvpi, uint32_t *avpi)
867 struct lpfc_mbx_read_config *rd_config;
868 LPFC_MBOXQ_t *pmboxq;
874 * prevent udev from issuing mailbox commands until the port is
877 if (phba->link_state < LPFC_LINK_DOWN ||
878 !phba->mbox_mem_pool ||
879 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
882 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
885 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
888 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
891 pmb->mbxCommand = MBX_READ_CONFIG;
892 pmb->mbxOwner = OWN_HOST;
893 pmboxq->context1 = NULL;
895 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
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 /* Account for differences with SLI-3. Get vpi count from
920 * mailbox data and subtract one for max vpi value.
922 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
923 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
928 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
931 *mrpi = pmb->un.varRdConfig.max_rpi;
933 *arpi = pmb->un.varRdConfig.avail_rpi;
935 *mxri = pmb->un.varRdConfig.max_xri;
937 *axri = pmb->un.varRdConfig.avail_xri;
939 *mvpi = pmb->un.varRdConfig.max_vpi;
941 *avpi = pmb->un.varRdConfig.avail_vpi;
944 mempool_free(pmboxq, phba->mbox_mem_pool);
949 * lpfc_max_rpi_show - Return maximum rpi
950 * @dev: class device that is converted into a Scsi_host.
951 * @attr: device attribute, not used.
952 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
955 * Calls lpfc_get_hba_info() asking for just the mrpi count.
956 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
957 * to "Unknown" and the buffer length is returned, therefore the caller
958 * must check for "Unknown" in the buffer to detect a failure.
960 * Returns: size of formatted string.
963 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
966 struct Scsi_Host *shost = class_to_shost(dev);
967 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
968 struct lpfc_hba *phba = vport->phba;
971 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
972 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
973 return snprintf(buf, PAGE_SIZE, "Unknown\n");
977 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
978 * @dev: class device that is converted into a Scsi_host.
979 * @attr: device attribute, not used.
980 * @buf: containing the used rpi count in decimal or "Unknown".
983 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
984 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
985 * to "Unknown" and the buffer length is returned, therefore the caller
986 * must check for "Unknown" in the buffer to detect a failure.
988 * Returns: size of formatted string.
991 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
994 struct Scsi_Host *shost = class_to_shost(dev);
995 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
996 struct lpfc_hba *phba = vport->phba;
999 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1000 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1001 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1005 * lpfc_max_xri_show - Return maximum xri
1006 * @dev: class device that is converted into a Scsi_host.
1007 * @attr: device attribute, not used.
1008 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1011 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1012 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1013 * to "Unknown" and the buffer length is returned, therefore the caller
1014 * must check for "Unknown" in the buffer to detect a failure.
1016 * Returns: size of formatted string.
1019 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1022 struct Scsi_Host *shost = class_to_shost(dev);
1023 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1024 struct lpfc_hba *phba = vport->phba;
1027 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1028 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1029 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1033 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1034 * @dev: class device that is converted into a Scsi_host.
1035 * @attr: device attribute, not used.
1036 * @buf: on return contains the used xri count in decimal or "Unknown".
1039 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1040 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1041 * to "Unknown" and the buffer length is returned, therefore the caller
1042 * must check for "Unknown" in the buffer to detect a failure.
1044 * Returns: size of formatted string.
1047 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1050 struct Scsi_Host *shost = class_to_shost(dev);
1051 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1052 struct lpfc_hba *phba = vport->phba;
1055 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1056 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1057 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1061 * lpfc_max_vpi_show - Return maximum vpi
1062 * @dev: class device that is converted into a Scsi_host.
1063 * @attr: device attribute, not used.
1064 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1067 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1068 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1069 * to "Unknown" and the buffer length is returned, therefore the caller
1070 * must check for "Unknown" in the buffer to detect a failure.
1072 * Returns: size of formatted string.
1075 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1078 struct Scsi_Host *shost = class_to_shost(dev);
1079 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1080 struct lpfc_hba *phba = vport->phba;
1083 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1084 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1085 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1089 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1090 * @dev: class device that is converted into a Scsi_host.
1091 * @attr: device attribute, not used.
1092 * @buf: on return contains the used vpi count in decimal or "Unknown".
1095 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1096 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1097 * to "Unknown" and the buffer length is returned, therefore the caller
1098 * must check for "Unknown" in the buffer to detect a failure.
1100 * Returns: size of formatted string.
1103 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1106 struct Scsi_Host *shost = class_to_shost(dev);
1107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1108 struct lpfc_hba *phba = vport->phba;
1111 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1112 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1113 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1117 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1118 * @dev: class device that is converted into a Scsi_host.
1119 * @attr: device attribute, not used.
1120 * @buf: text that must be interpreted to determine if npiv is supported.
1123 * Buffer will contain text indicating npiv is not suppoerted on the port,
1124 * the port is an NPIV physical port, or it is an npiv virtual port with
1125 * the id of the vport.
1127 * Returns: size of formatted string.
1130 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1133 struct Scsi_Host *shost = class_to_shost(dev);
1134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1135 struct lpfc_hba *phba = vport->phba;
1137 if (!(phba->max_vpi))
1138 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1139 if (vport->port_type == LPFC_PHYSICAL_PORT)
1140 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1141 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1145 * lpfc_poll_show - Return text about poll support for the adapter
1146 * @dev: class device that is converted into a Scsi_host.
1147 * @attr: device attribute, not used.
1148 * @buf: on return contains the cfg_poll in hex.
1151 * cfg_poll should be a lpfc_polling_flags type.
1153 * Returns: size of formatted string.
1156 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1159 struct Scsi_Host *shost = class_to_shost(dev);
1160 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1161 struct lpfc_hba *phba = vport->phba;
1163 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1167 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1168 * @dev: class device that is converted into a Scsi_host.
1169 * @attr: device attribute, not used.
1170 * @buf: one or more lpfc_polling_flags values.
1174 * buf contents converted to integer and checked for a valid value.
1177 * -EINVAL if the buffer connot be converted or is out of range
1178 * length of the buf on success
1181 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1182 const char *buf, size_t count)
1184 struct Scsi_Host *shost = class_to_shost(dev);
1185 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1186 struct lpfc_hba *phba = vport->phba;
1191 if (!isdigit(buf[0]))
1194 if (sscanf(buf, "%i", &val) != 1)
1197 if ((val & 0x3) != val)
1200 if (phba->sli_rev == LPFC_SLI_REV4)
1203 spin_lock_irq(&phba->hbalock);
1205 old_val = phba->cfg_poll;
1207 if (val & ENABLE_FCP_RING_POLLING) {
1208 if ((val & DISABLE_FCP_RING_INT) &&
1209 !(old_val & DISABLE_FCP_RING_INT)) {
1210 creg_val = readl(phba->HCregaddr);
1211 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1212 writel(creg_val, phba->HCregaddr);
1213 readl(phba->HCregaddr); /* flush */
1215 lpfc_poll_start_timer(phba);
1217 } else if (val != 0x0) {
1218 spin_unlock_irq(&phba->hbalock);
1222 if (!(val & DISABLE_FCP_RING_INT) &&
1223 (old_val & DISABLE_FCP_RING_INT))
1225 spin_unlock_irq(&phba->hbalock);
1226 del_timer(&phba->fcp_poll_timer);
1227 spin_lock_irq(&phba->hbalock);
1228 creg_val = readl(phba->HCregaddr);
1229 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1230 writel(creg_val, phba->HCregaddr);
1231 readl(phba->HCregaddr); /* flush */
1234 phba->cfg_poll = val;
1236 spin_unlock_irq(&phba->hbalock);
1242 * lpfc_param_show - Return a cfg attribute value in decimal
1245 * Macro that given an attr e.g. hba_queue_depth expands
1246 * into a function with the name lpfc_hba_queue_depth_show.
1248 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1249 * @dev: class device that is converted into a Scsi_host.
1250 * @attr: device attribute, not used.
1251 * @buf: on return contains the attribute value in decimal.
1253 * Returns: size of formatted string.
1255 #define lpfc_param_show(attr) \
1257 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1260 struct Scsi_Host *shost = class_to_shost(dev);\
1261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1262 struct lpfc_hba *phba = vport->phba;\
1264 val = phba->cfg_##attr;\
1265 return snprintf(buf, PAGE_SIZE, "%d\n",\
1270 * lpfc_param_hex_show - Return a cfg attribute value in hex
1273 * Macro that given an attr e.g. hba_queue_depth expands
1274 * into a function with the name lpfc_hba_queue_depth_show
1276 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1277 * @dev: class device that is converted into a Scsi_host.
1278 * @attr: device attribute, not used.
1279 * @buf: on return contains the attribute value in hexadecimal.
1281 * Returns: size of formatted string.
1283 #define lpfc_param_hex_show(attr) \
1285 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1288 struct Scsi_Host *shost = class_to_shost(dev);\
1289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1290 struct lpfc_hba *phba = vport->phba;\
1292 val = phba->cfg_##attr;\
1293 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1298 * lpfc_param_init - Intializes a cfg attribute
1301 * Macro that given an attr e.g. hba_queue_depth expands
1302 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1303 * takes a default argument, a minimum and maximum argument.
1305 * lpfc_##attr##_init: Initializes an attribute.
1306 * @phba: pointer the the adapter structure.
1307 * @val: integer attribute value.
1309 * Validates the min and max values then sets the adapter config field
1310 * accordingly, or uses the default if out of range and prints an error message.
1314 * -EINVAL if default used
1316 #define lpfc_param_init(attr, default, minval, maxval) \
1318 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1320 if (val >= minval && val <= maxval) {\
1321 phba->cfg_##attr = val;\
1324 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1325 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1326 "allowed range is ["#minval", "#maxval"]\n", val); \
1327 phba->cfg_##attr = default;\
1332 * lpfc_param_set - Set a cfg attribute value
1335 * Macro that given an attr e.g. hba_queue_depth expands
1336 * into a function with the name lpfc_hba_queue_depth_set
1338 * lpfc_##attr##_set: Sets an attribute value.
1339 * @phba: pointer the the adapter structure.
1340 * @val: integer attribute value.
1343 * Validates the min and max values then sets the
1344 * adapter config field if in the valid range. prints error message
1345 * and does not set the parameter if invalid.
1349 * -EINVAL if val is invalid
1351 #define lpfc_param_set(attr, default, minval, maxval) \
1353 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1355 if (val >= minval && val <= maxval) {\
1356 phba->cfg_##attr = val;\
1359 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1360 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1361 "allowed range is ["#minval", "#maxval"]\n", val); \
1366 * lpfc_param_store - Set a vport attribute value
1369 * Macro that given an attr e.g. hba_queue_depth expands
1370 * into a function with the name lpfc_hba_queue_depth_store.
1372 * lpfc_##attr##_store: Set an sttribute value.
1373 * @dev: class device that is converted into a Scsi_host.
1374 * @attr: device attribute, not used.
1375 * @buf: contains the attribute value in ascii.
1379 * Convert the ascii text number to an integer, then
1380 * use the lpfc_##attr##_set function to set the value.
1383 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1384 * length of buffer upon success.
1386 #define lpfc_param_store(attr) \
1388 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1389 const char *buf, size_t count) \
1391 struct Scsi_Host *shost = class_to_shost(dev);\
1392 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1393 struct lpfc_hba *phba = vport->phba;\
1395 if (!isdigit(buf[0]))\
1397 if (sscanf(buf, "%i", &val) != 1)\
1399 if (lpfc_##attr##_set(phba, val) == 0) \
1400 return strlen(buf);\
1406 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1409 * Macro that given an attr e.g. hba_queue_depth expands
1410 * into a function with the name lpfc_hba_queue_depth_show
1412 * lpfc_##attr##_show: prints the attribute value in decimal.
1413 * @dev: class device that is converted into a Scsi_host.
1414 * @attr: device attribute, not used.
1415 * @buf: on return contains the attribute value in decimal.
1417 * Returns: length of formatted string.
1419 #define lpfc_vport_param_show(attr) \
1421 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1424 struct Scsi_Host *shost = class_to_shost(dev);\
1425 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1427 val = vport->cfg_##attr;\
1428 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1432 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1435 * Macro that given an attr e.g.
1436 * hba_queue_depth expands into a function with the name
1437 * lpfc_hba_queue_depth_show
1439 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1440 * @dev: class device that is converted into a Scsi_host.
1441 * @attr: device attribute, not used.
1442 * @buf: on return contains the attribute value in hexadecimal.
1444 * Returns: length of formatted string.
1446 #define lpfc_vport_param_hex_show(attr) \
1448 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1451 struct Scsi_Host *shost = class_to_shost(dev);\
1452 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1454 val = vport->cfg_##attr;\
1455 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1459 * lpfc_vport_param_init - Initialize a vport cfg attribute
1462 * Macro that given an attr e.g. hba_queue_depth expands
1463 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1464 * takes a default argument, a minimum and maximum argument.
1466 * lpfc_##attr##_init: validates the min and max values then sets the
1467 * adapter config field accordingly, or uses the default if out of range
1468 * and prints an error message.
1469 * @phba: pointer the the adapter structure.
1470 * @val: integer attribute value.
1474 * -EINVAL if default used
1476 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1478 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1480 if (val >= minval && val <= maxval) {\
1481 vport->cfg_##attr = val;\
1484 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1485 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1486 "allowed range is ["#minval", "#maxval"]\n", val); \
1487 vport->cfg_##attr = default;\
1492 * lpfc_vport_param_set - Set a vport cfg attribute
1495 * Macro that given an attr e.g. hba_queue_depth expands
1496 * into a function with the name lpfc_hba_queue_depth_set
1498 * lpfc_##attr##_set: validates the min and max values then sets the
1499 * adapter config field if in the valid range. prints error message
1500 * and does not set the parameter if invalid.
1501 * @phba: pointer the the adapter structure.
1502 * @val: integer attribute value.
1506 * -EINVAL if val is invalid
1508 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1510 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1512 if (val >= minval && val <= maxval) {\
1513 vport->cfg_##attr = val;\
1516 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1517 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1518 "allowed range is ["#minval", "#maxval"]\n", val); \
1523 * lpfc_vport_param_store - Set a vport attribute
1526 * Macro that given an attr e.g. hba_queue_depth
1527 * expands into a function with the name lpfc_hba_queue_depth_store
1529 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1530 * use the lpfc_##attr##_set function to set the value.
1531 * @cdev: class device that is converted into a Scsi_host.
1532 * @buf: contains the attribute value in decimal.
1536 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1537 * length of buffer upon success.
1539 #define lpfc_vport_param_store(attr) \
1541 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1542 const char *buf, size_t count) \
1544 struct Scsi_Host *shost = class_to_shost(dev);\
1545 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1547 if (!isdigit(buf[0]))\
1549 if (sscanf(buf, "%i", &val) != 1)\
1551 if (lpfc_##attr##_set(vport, val) == 0) \
1552 return strlen(buf);\
1558 #define LPFC_ATTR(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_init(name, defval, minval, maxval)
1564 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1565 static uint lpfc_##name = defval;\
1566 module_param(lpfc_##name, uint, 0);\
1567 MODULE_PARM_DESC(lpfc_##name, desc);\
1568 lpfc_param_show(name)\
1569 lpfc_param_init(name, defval, minval, maxval)\
1570 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1572 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1573 static uint lpfc_##name = defval;\
1574 module_param(lpfc_##name, uint, 0);\
1575 MODULE_PARM_DESC(lpfc_##name, desc);\
1576 lpfc_param_show(name)\
1577 lpfc_param_init(name, defval, minval, maxval)\
1578 lpfc_param_set(name, defval, minval, maxval)\
1579 lpfc_param_store(name)\
1580 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1581 lpfc_##name##_show, lpfc_##name##_store)
1583 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1584 static uint lpfc_##name = defval;\
1585 module_param(lpfc_##name, uint, 0);\
1586 MODULE_PARM_DESC(lpfc_##name, desc);\
1587 lpfc_param_hex_show(name)\
1588 lpfc_param_init(name, defval, minval, maxval)\
1589 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1591 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1592 static uint lpfc_##name = defval;\
1593 module_param(lpfc_##name, uint, 0);\
1594 MODULE_PARM_DESC(lpfc_##name, desc);\
1595 lpfc_param_hex_show(name)\
1596 lpfc_param_init(name, defval, minval, maxval)\
1597 lpfc_param_set(name, defval, minval, maxval)\
1598 lpfc_param_store(name)\
1599 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1600 lpfc_##name##_show, lpfc_##name##_store)
1602 #define LPFC_VPORT_ATTR(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_init(name, defval, minval, maxval)
1608 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1609 static uint lpfc_##name = defval;\
1610 module_param(lpfc_##name, uint, 0);\
1611 MODULE_PARM_DESC(lpfc_##name, desc);\
1612 lpfc_vport_param_show(name)\
1613 lpfc_vport_param_init(name, defval, minval, maxval)\
1614 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1616 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1617 static uint lpfc_##name = defval;\
1618 module_param(lpfc_##name, uint, 0);\
1619 MODULE_PARM_DESC(lpfc_##name, desc);\
1620 lpfc_vport_param_show(name)\
1621 lpfc_vport_param_init(name, defval, minval, maxval)\
1622 lpfc_vport_param_set(name, defval, minval, maxval)\
1623 lpfc_vport_param_store(name)\
1624 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1625 lpfc_##name##_show, lpfc_##name##_store)
1627 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1628 static uint lpfc_##name = defval;\
1629 module_param(lpfc_##name, uint, 0);\
1630 MODULE_PARM_DESC(lpfc_##name, desc);\
1631 lpfc_vport_param_hex_show(name)\
1632 lpfc_vport_param_init(name, defval, minval, maxval)\
1633 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1635 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1636 static uint lpfc_##name = defval;\
1637 module_param(lpfc_##name, uint, 0);\
1638 MODULE_PARM_DESC(lpfc_##name, desc);\
1639 lpfc_vport_param_hex_show(name)\
1640 lpfc_vport_param_init(name, defval, minval, maxval)\
1641 lpfc_vport_param_set(name, defval, minval, maxval)\
1642 lpfc_vport_param_store(name)\
1643 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1644 lpfc_##name##_show, lpfc_##name##_store)
1646 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1647 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1648 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1649 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1650 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1651 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1652 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1653 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1654 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1655 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1656 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1657 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1658 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1659 lpfc_link_state_store);
1660 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1661 lpfc_option_rom_version_show, NULL);
1662 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1663 lpfc_num_discovered_ports_show, NULL);
1664 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1665 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1666 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1667 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1668 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1669 lpfc_board_mode_show, lpfc_board_mode_store);
1670 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1671 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1672 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1673 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1674 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1675 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1676 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1677 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1678 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1681 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1684 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1685 * @dev: class device that is converted into a Scsi_host.
1686 * @attr: device attribute, not used.
1687 * @buf: containing the string lpfc_soft_wwn_key.
1688 * @count: must be size of lpfc_soft_wwn_key.
1691 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1692 * length of buf indicates success
1695 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1696 const char *buf, size_t count)
1698 struct Scsi_Host *shost = class_to_shost(dev);
1699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1700 struct lpfc_hba *phba = vport->phba;
1701 unsigned int cnt = count;
1704 * We're doing a simple sanity check for soft_wwpn setting.
1705 * We require that the user write a specific key to enable
1706 * the soft_wwpn attribute to be settable. Once the attribute
1707 * is written, the enable key resets. If further updates are
1708 * desired, the key must be written again to re-enable the
1711 * The "key" is not secret - it is a hardcoded string shown
1712 * here. The intent is to protect against the random user or
1713 * application that is just writing attributes.
1716 /* count may include a LF at end of string */
1717 if (buf[cnt-1] == '\n')
1720 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1721 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1724 phba->soft_wwn_enable = 1;
1727 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1728 lpfc_soft_wwn_enable_store);
1731 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1732 * @dev: class device that is converted into a Scsi_host.
1733 * @attr: device attribute, not used.
1734 * @buf: on return contains the wwpn in hexadecimal.
1736 * Returns: size of formatted string.
1739 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1742 struct Scsi_Host *shost = class_to_shost(dev);
1743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1744 struct lpfc_hba *phba = vport->phba;
1746 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1747 (unsigned long long)phba->cfg_soft_wwpn);
1751 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1752 * @dev class device that is converted into a Scsi_host.
1753 * @attr: device attribute, not used.
1754 * @buf: contains the wwpn in hexadecimal.
1755 * @count: number of wwpn bytes in buf
1758 * -EACCES hba reset not enabled, adapter over temp
1759 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1760 * -EIO error taking adapter offline or online
1761 * value of count on success
1764 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1765 const char *buf, size_t count)
1767 struct Scsi_Host *shost = class_to_shost(dev);
1768 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1769 struct lpfc_hba *phba = vport->phba;
1770 struct completion online_compl;
1771 int stat1=0, stat2=0;
1772 unsigned int i, j, cnt=count;
1775 if (!phba->cfg_enable_hba_reset)
1777 spin_lock_irq(&phba->hbalock);
1778 if (phba->over_temp_state == HBA_OVER_TEMP) {
1779 spin_unlock_irq(&phba->hbalock);
1782 spin_unlock_irq(&phba->hbalock);
1783 /* count may include a LF at end of string */
1784 if (buf[cnt-1] == '\n')
1787 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1788 ((cnt == 17) && (*buf++ != 'x')) ||
1789 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1792 phba->soft_wwn_enable = 0;
1794 memset(wwpn, 0, sizeof(wwpn));
1796 /* Validate and store the new name */
1797 for (i=0, j=0; i < 16; i++) {
1798 if ((*buf >= 'a') && (*buf <= 'f'))
1799 j = ((j << 4) | ((*buf++ -'a') + 10));
1800 else if ((*buf >= 'A') && (*buf <= 'F'))
1801 j = ((j << 4) | ((*buf++ -'A') + 10));
1802 else if ((*buf >= '0') && (*buf <= '9'))
1803 j = ((j << 4) | (*buf++ -'0'));
1807 wwpn[i/2] = j & 0xff;
1811 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1812 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1813 if (phba->cfg_soft_wwnn)
1814 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1816 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1817 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1819 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1822 "0463 lpfc_soft_wwpn attribute set failed to "
1823 "reinit adapter - %d\n", stat1);
1824 init_completion(&online_compl);
1825 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1826 wait_for_completion(&online_compl);
1828 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1829 "0464 lpfc_soft_wwpn attribute set failed to "
1830 "reinit adapter - %d\n", stat2);
1831 return (stat1 || stat2) ? -EIO : count;
1833 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1834 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1837 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1838 * @dev: class device that is converted into a Scsi_host.
1839 * @attr: device attribute, not used.
1840 * @buf: on return contains the wwnn in hexadecimal.
1842 * Returns: size of formatted string.
1845 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1848 struct Scsi_Host *shost = class_to_shost(dev);
1849 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1850 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1851 (unsigned long long)phba->cfg_soft_wwnn);
1855 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1856 * @cdev: class device that is converted into a Scsi_host.
1857 * @buf: contains the ww node name in hexadecimal.
1858 * @count: number of wwnn bytes in buf.
1861 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1862 * value of count on success
1865 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1866 const char *buf, size_t count)
1868 struct Scsi_Host *shost = class_to_shost(dev);
1869 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1870 unsigned int i, j, cnt=count;
1873 /* count may include a LF at end of string */
1874 if (buf[cnt-1] == '\n')
1877 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1878 ((cnt == 17) && (*buf++ != 'x')) ||
1879 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1883 * Allow wwnn to be set many times, as long as the enable is set.
1884 * However, once the wwpn is set, everything locks.
1887 memset(wwnn, 0, sizeof(wwnn));
1889 /* Validate and store the new name */
1890 for (i=0, j=0; i < 16; i++) {
1891 if ((*buf >= 'a') && (*buf <= 'f'))
1892 j = ((j << 4) | ((*buf++ -'a') + 10));
1893 else if ((*buf >= 'A') && (*buf <= 'F'))
1894 j = ((j << 4) | ((*buf++ -'A') + 10));
1895 else if ((*buf >= '0') && (*buf <= '9'))
1896 j = ((j << 4) | (*buf++ -'0'));
1900 wwnn[i/2] = j & 0xff;
1904 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1906 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1907 "lpfc%d: soft_wwnn set. Value will take effect upon "
1908 "setting of the soft_wwpn\n", phba->brd_no);
1912 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1913 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1916 static int lpfc_poll = 0;
1917 module_param(lpfc_poll, int, 0);
1918 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1920 " 1 - poll with interrupts enabled"
1921 " 3 - poll and disable FCP ring interrupts");
1923 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1924 lpfc_poll_show, lpfc_poll_store);
1926 int lpfc_sli_mode = 0;
1927 module_param(lpfc_sli_mode, int, 0);
1928 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1929 " 0 - auto (SLI-3 if supported),"
1930 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1931 " 3 - select SLI-3");
1933 int lpfc_enable_npiv = 1;
1934 module_param(lpfc_enable_npiv, int, 0);
1935 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1936 lpfc_param_show(enable_npiv);
1937 lpfc_param_init(enable_npiv, 1, 0, 1);
1938 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
1941 # lpfc_suppress_link_up: Bring link up at initialization
1942 # 0x0 = bring link up (issue MBX_INIT_LINK)
1943 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1944 # 0x2 = never bring up link
1945 # Default value is 0.
1947 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
1948 LPFC_DELAY_INIT_LINK_INDEFINITELY,
1949 "Suppress Link Up at initialization");
1951 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
1959 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1961 struct Scsi_Host *shost = class_to_shost(dev);
1962 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1964 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
1967 static DEVICE_ATTR(iocb_hw, S_IRUGO,
1968 lpfc_iocb_hw_show, NULL);
1970 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
1972 struct Scsi_Host *shost = class_to_shost(dev);
1973 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1975 return snprintf(buf, PAGE_SIZE, "%d\n",
1976 phba->sli.ring[LPFC_ELS_RING].txq_max);
1979 static DEVICE_ATTR(txq_hw, S_IRUGO,
1980 lpfc_txq_hw_show, NULL);
1982 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
1985 struct Scsi_Host *shost = class_to_shost(dev);
1986 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
1988 return snprintf(buf, PAGE_SIZE, "%d\n",
1989 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
1992 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
1993 lpfc_txcmplq_hw_show, NULL);
1995 int lpfc_iocb_cnt = 2;
1996 module_param(lpfc_iocb_cnt, int, 1);
1997 MODULE_PARM_DESC(lpfc_iocb_cnt,
1998 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
1999 lpfc_param_show(iocb_cnt);
2000 lpfc_param_init(iocb_cnt, 2, 1, 5);
2001 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2002 lpfc_iocb_cnt_show, NULL);
2005 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2006 # until the timer expires. Value range is [0,255]. Default value is 30.
2008 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2009 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2010 module_param(lpfc_nodev_tmo, int, 0);
2011 MODULE_PARM_DESC(lpfc_nodev_tmo,
2012 "Seconds driver will hold I/O waiting "
2013 "for a device to come back");
2016 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2017 * @dev: class converted to a Scsi_host structure.
2018 * @attr: device attribute, not used.
2019 * @buf: on return contains the dev loss timeout in decimal.
2021 * Returns: size of formatted string.
2024 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2027 struct Scsi_Host *shost = class_to_shost(dev);
2028 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2030 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2034 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2035 * @vport: lpfc vport structure pointer.
2036 * @val: contains the nodev timeout value.
2039 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2040 * a kernel error message is printed and zero is returned.
2041 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2042 * Otherwise nodev tmo is set to the default value.
2045 * zero if already set or if val is in range
2046 * -EINVAL val out of range
2049 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2051 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2052 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2053 if (val != LPFC_DEF_DEVLOSS_TMO)
2054 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2055 "0407 Ignoring nodev_tmo module "
2056 "parameter because devloss_tmo is "
2061 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2062 vport->cfg_nodev_tmo = val;
2063 vport->cfg_devloss_tmo = val;
2066 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2067 "0400 lpfc_nodev_tmo attribute cannot be set to"
2068 " %d, allowed range is [%d, %d]\n",
2069 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2070 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2075 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2076 * @vport: lpfc vport structure pointer.
2079 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2082 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2084 struct Scsi_Host *shost;
2085 struct lpfc_nodelist *ndlp;
2087 shost = lpfc_shost_from_vport(vport);
2088 spin_lock_irq(shost->host_lock);
2089 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2090 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2091 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2092 spin_unlock_irq(shost->host_lock);
2096 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2097 * @vport: lpfc vport structure pointer.
2098 * @val: contains the tmo value.
2101 * If the devloss tmo is already set or the vport dev loss tmo has changed
2102 * then a kernel error message is printed and zero is returned.
2103 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2104 * Otherwise nodev tmo is set to the default value.
2107 * zero if already set or if val is in range
2108 * -EINVAL val out of range
2111 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2113 if (vport->dev_loss_tmo_changed ||
2114 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2115 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2116 "0401 Ignoring change to nodev_tmo "
2117 "because devloss_tmo is set.\n");
2120 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2121 vport->cfg_nodev_tmo = val;
2122 vport->cfg_devloss_tmo = val;
2123 lpfc_update_rport_devloss_tmo(vport);
2126 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2127 "0403 lpfc_nodev_tmo attribute cannot be set to"
2128 "%d, allowed range is [%d, %d]\n",
2129 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2133 lpfc_vport_param_store(nodev_tmo)
2135 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2136 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2139 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2140 # disappear until the timer expires. Value range is [0,255]. Default
2143 module_param(lpfc_devloss_tmo, int, 0);
2144 MODULE_PARM_DESC(lpfc_devloss_tmo,
2145 "Seconds driver will hold I/O waiting "
2146 "for a device to come back");
2147 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2148 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2149 lpfc_vport_param_show(devloss_tmo)
2152 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2153 * @vport: lpfc vport structure pointer.
2154 * @val: contains the tmo value.
2157 * If val is in a valid range then set the vport nodev tmo,
2158 * devloss tmo, also set the vport dev loss tmo changed flag.
2159 * Else a kernel error message is printed.
2162 * zero if val is in range
2163 * -EINVAL val out of range
2166 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2168 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2169 vport->cfg_nodev_tmo = val;
2170 vport->cfg_devloss_tmo = val;
2171 vport->dev_loss_tmo_changed = 1;
2172 lpfc_update_rport_devloss_tmo(vport);
2176 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2177 "0404 lpfc_devloss_tmo attribute cannot be set to"
2178 " %d, allowed range is [%d, %d]\n",
2179 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2183 lpfc_vport_param_store(devloss_tmo)
2184 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2185 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2188 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2189 # deluged with LOTS of information.
2190 # You can set a bit mask to record specific types of verbose messages:
2191 # See lpfc_logmsh.h for definitions.
2193 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2194 "Verbose logging bit-mask");
2197 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2198 # objects that have been registered with the nameserver after login.
2200 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2201 "Deregister nameserver objects before LOGO");
2204 # lun_queue_depth: This parameter is used to limit the number of outstanding
2205 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2207 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2208 "Max number of FCP commands we can queue to a specific LUN");
2211 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2212 # commands per target port. Value range is [10,65535]. Default value is 65535.
2214 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2215 "Max number of FCP commands we can queue to a specific target port");
2218 # hba_queue_depth: This parameter is used to limit the number of outstanding
2219 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2220 # value is greater than the maximum number of exchanges supported by the HBA,
2221 # then maximum number of exchanges supported by the HBA is used to determine
2222 # the hba_queue_depth.
2224 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2225 "Max number of FCP commands we can queue to a lpfc HBA");
2228 # peer_port_login: This parameter allows/prevents logins
2229 # between peer ports hosted on the same physical port.
2230 # When this parameter is set 0 peer ports of same physical port
2231 # are not allowed to login to each other.
2232 # When this parameter is set 1 peer ports of same physical port
2233 # are allowed to login to each other.
2234 # Default value of this parameter is 0.
2236 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2237 "Allow peer ports on the same physical port to login to each "
2241 # restrict_login: This parameter allows/prevents logins
2242 # between Virtual Ports and remote initiators.
2243 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2244 # other initiators and will attempt to PLOGI all remote ports.
2245 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2246 # remote ports and will not attempt to PLOGI to other initiators.
2247 # This parameter does not restrict to the physical port.
2248 # This parameter does not restrict logins to Fabric resident remote ports.
2249 # Default value of this parameter is 1.
2251 static int lpfc_restrict_login = 1;
2252 module_param(lpfc_restrict_login, int, 0);
2253 MODULE_PARM_DESC(lpfc_restrict_login,
2254 "Restrict virtual ports login to remote initiators.");
2255 lpfc_vport_param_show(restrict_login);
2258 * lpfc_restrict_login_init - Set the vport restrict login flag
2259 * @vport: lpfc vport structure pointer.
2260 * @val: contains the restrict login value.
2263 * If val is not in a valid range then log a kernel error message and set
2264 * the vport restrict login to one.
2265 * If the port type is physical clear the restrict login flag and return.
2266 * Else set the restrict login flag to val.
2269 * zero if val is in range
2270 * -EINVAL val out of range
2273 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2275 if (val < 0 || val > 1) {
2276 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2277 "0422 lpfc_restrict_login attribute cannot "
2278 "be set to %d, allowed range is [0, 1]\n",
2280 vport->cfg_restrict_login = 1;
2283 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2284 vport->cfg_restrict_login = 0;
2287 vport->cfg_restrict_login = val;
2292 * lpfc_restrict_login_set - Set the vport restrict login flag
2293 * @vport: lpfc vport structure pointer.
2294 * @val: contains the restrict login value.
2297 * If val is not in a valid range then log a kernel error message and set
2298 * the vport restrict login to one.
2299 * If the port type is physical and the val is not zero log a kernel
2300 * error message, clear the restrict login flag and return zero.
2301 * Else set the restrict login flag to val.
2304 * zero if val is in range
2305 * -EINVAL val out of range
2308 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2310 if (val < 0 || val > 1) {
2311 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2312 "0425 lpfc_restrict_login attribute cannot "
2313 "be set to %d, allowed range is [0, 1]\n",
2315 vport->cfg_restrict_login = 1;
2318 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2319 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2320 "0468 lpfc_restrict_login must be 0 for "
2321 "Physical ports.\n");
2322 vport->cfg_restrict_login = 0;
2325 vport->cfg_restrict_login = val;
2328 lpfc_vport_param_store(restrict_login);
2329 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2330 lpfc_restrict_login_show, lpfc_restrict_login_store);
2333 # Some disk devices have a "select ID" or "select Target" capability.
2334 # From a protocol standpoint "select ID" usually means select the
2335 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2336 # annex" which contains a table that maps a "select ID" (a number
2337 # between 0 and 7F) to an ALPA. By default, for compatibility with
2338 # older drivers, the lpfc driver scans this table from low ALPA to high
2341 # Turning on the scan-down variable (on = 1, off = 0) will
2342 # cause the lpfc driver to use an inverted table, effectively
2343 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2345 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2346 # and will not work across a fabric. Also this parameter will take
2347 # effect only in the case when ALPA map is not available.)
2349 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2350 "Start scanning for devices from highest ALPA to lowest");
2353 # lpfc_topology: link topology for init link
2354 # 0x0 = attempt loop mode then point-to-point
2355 # 0x01 = internal loopback mode
2356 # 0x02 = attempt point-to-point mode only
2357 # 0x04 = attempt loop mode only
2358 # 0x06 = attempt point-to-point mode then loop
2359 # Set point-to-point mode if you want to run as an N_Port.
2360 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2361 # Default value is 0.
2365 * lpfc_topology_set - Set the adapters topology field
2366 * @phba: lpfc_hba pointer.
2367 * @val: topology value.
2370 * If val is in a valid range then set the adapter's topology field and
2371 * issue a lip; if the lip fails reset the topology to the old value.
2373 * If the value is not in range log a kernel error message and return an error.
2376 * zero if val is in range and lip okay
2377 * non-zero return value from lpfc_issue_lip()
2378 * -EINVAL val out of range
2381 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2382 const char *buf, size_t count)
2384 struct Scsi_Host *shost = class_to_shost(dev);
2385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2386 struct lpfc_hba *phba = vport->phba;
2389 const char *val_buf = buf;
2393 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2395 val_buf = &buf[strlen("nolip ")];
2398 if (!isdigit(val_buf[0]))
2400 if (sscanf(val_buf, "%i", &val) != 1)
2403 if (val >= 0 && val <= 6) {
2404 prev_val = phba->cfg_topology;
2405 phba->cfg_topology = val;
2409 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2411 phba->cfg_topology = prev_val;
2416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2417 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2418 "allowed range is [0, 6]\n",
2422 static int lpfc_topology = 0;
2423 module_param(lpfc_topology, int, 0);
2424 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2425 lpfc_param_show(topology)
2426 lpfc_param_init(topology, 0, 0, 6)
2427 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2428 lpfc_topology_show, lpfc_topology_store);
2431 * lpfc_static_vport_show: Read callback function for
2432 * lpfc_static_vport sysfs file.
2433 * @dev: Pointer to class device object.
2434 * @attr: device attribute structure.
2435 * @buf: Data buffer.
2437 * This function is the read call back function for
2438 * lpfc_static_vport sysfs file. The lpfc_static_vport
2439 * sysfs file report the mageability of the vport.
2442 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2445 struct Scsi_Host *shost = class_to_shost(dev);
2446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2447 if (vport->vport_flag & STATIC_VPORT)
2448 sprintf(buf, "1\n");
2450 sprintf(buf, "0\n");
2456 * Sysfs attribute to control the statistical data collection.
2458 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2459 lpfc_static_vport_show, NULL);
2462 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2463 * @dev: Pointer to class device.
2464 * @buf: Data buffer.
2465 * @count: Size of the data buffer.
2467 * This function get called when an user write to the lpfc_stat_data_ctrl
2468 * sysfs file. This function parse the command written to the sysfs file
2469 * and take appropriate action. These commands are used for controlling
2470 * driver statistical data collection.
2471 * Following are the command this function handles.
2473 * setbucket <bucket_type> <base> <step>
2474 * = Set the latency buckets.
2475 * destroybucket = destroy all the buckets.
2476 * start = start data collection
2477 * stop = stop data collection
2478 * reset = reset the collected data
2481 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2482 const char *buf, size_t count)
2484 struct Scsi_Host *shost = class_to_shost(dev);
2485 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2486 struct lpfc_hba *phba = vport->phba;
2487 #define LPFC_MAX_DATA_CTRL_LEN 1024
2488 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2490 char *str_ptr, *token;
2491 struct lpfc_vport **vports;
2492 struct Scsi_Host *v_shost;
2493 char *bucket_type_str, *base_str, *step_str;
2494 unsigned long base, step, bucket_type;
2496 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2497 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2500 strcpy(bucket_data, buf);
2501 str_ptr = &bucket_data[0];
2502 /* Ignore this token - this is command token */
2503 token = strsep(&str_ptr, "\t ");
2507 bucket_type_str = strsep(&str_ptr, "\t ");
2508 if (!bucket_type_str)
2511 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2512 bucket_type = LPFC_LINEAR_BUCKET;
2513 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2514 bucket_type = LPFC_POWER2_BUCKET;
2518 base_str = strsep(&str_ptr, "\t ");
2521 base = simple_strtoul(base_str, NULL, 0);
2523 step_str = strsep(&str_ptr, "\t ");
2526 step = simple_strtoul(step_str, NULL, 0);
2530 /* Block the data collection for every vport */
2531 vports = lpfc_create_vport_work_array(phba);
2535 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2536 v_shost = lpfc_shost_from_vport(vports[i]);
2537 spin_lock_irq(v_shost->host_lock);
2538 /* Block and reset data collection */
2539 vports[i]->stat_data_blocked = 1;
2540 if (vports[i]->stat_data_enabled)
2541 lpfc_vport_reset_stat_data(vports[i]);
2542 spin_unlock_irq(v_shost->host_lock);
2545 /* Set the bucket attributes */
2546 phba->bucket_type = bucket_type;
2547 phba->bucket_base = base;
2548 phba->bucket_step = step;
2550 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2551 v_shost = lpfc_shost_from_vport(vports[i]);
2553 /* Unblock data collection */
2554 spin_lock_irq(v_shost->host_lock);
2555 vports[i]->stat_data_blocked = 0;
2556 spin_unlock_irq(v_shost->host_lock);
2558 lpfc_destroy_vport_work_array(phba, vports);
2562 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2563 vports = lpfc_create_vport_work_array(phba);
2567 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2568 v_shost = lpfc_shost_from_vport(vports[i]);
2569 spin_lock_irq(shost->host_lock);
2570 vports[i]->stat_data_blocked = 1;
2571 lpfc_free_bucket(vport);
2572 vport->stat_data_enabled = 0;
2573 vports[i]->stat_data_blocked = 0;
2574 spin_unlock_irq(shost->host_lock);
2576 lpfc_destroy_vport_work_array(phba, vports);
2577 phba->bucket_type = LPFC_NO_BUCKET;
2578 phba->bucket_base = 0;
2579 phba->bucket_step = 0;
2583 if (!strncmp(buf, "start", strlen("start"))) {
2584 /* If no buckets configured return error */
2585 if (phba->bucket_type == LPFC_NO_BUCKET)
2587 spin_lock_irq(shost->host_lock);
2588 if (vport->stat_data_enabled) {
2589 spin_unlock_irq(shost->host_lock);
2592 lpfc_alloc_bucket(vport);
2593 vport->stat_data_enabled = 1;
2594 spin_unlock_irq(shost->host_lock);
2598 if (!strncmp(buf, "stop", strlen("stop"))) {
2599 spin_lock_irq(shost->host_lock);
2600 if (vport->stat_data_enabled == 0) {
2601 spin_unlock_irq(shost->host_lock);
2604 lpfc_free_bucket(vport);
2605 vport->stat_data_enabled = 0;
2606 spin_unlock_irq(shost->host_lock);
2610 if (!strncmp(buf, "reset", strlen("reset"))) {
2611 if ((phba->bucket_type == LPFC_NO_BUCKET)
2612 || !vport->stat_data_enabled)
2614 spin_lock_irq(shost->host_lock);
2615 vport->stat_data_blocked = 1;
2616 lpfc_vport_reset_stat_data(vport);
2617 vport->stat_data_blocked = 0;
2618 spin_unlock_irq(shost->host_lock);
2626 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2627 * @dev: Pointer to class device object.
2628 * @buf: Data buffer.
2630 * This function is the read call back function for
2631 * lpfc_stat_data_ctrl sysfs file. This function report the
2632 * current statistical data collection state.
2635 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2638 struct Scsi_Host *shost = class_to_shost(dev);
2639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2640 struct lpfc_hba *phba = vport->phba;
2644 unsigned long bucket_value;
2646 switch (phba->bucket_type) {
2647 case LPFC_LINEAR_BUCKET:
2648 bucket_type = "linear";
2650 case LPFC_POWER2_BUCKET:
2651 bucket_type = "power2";
2654 bucket_type = "No Bucket";
2658 sprintf(&buf[index], "Statistical Data enabled :%d, "
2659 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2660 " Bucket step :%d\nLatency Ranges :",
2661 vport->stat_data_enabled, vport->stat_data_blocked,
2662 bucket_type, phba->bucket_base, phba->bucket_step);
2663 index = strlen(buf);
2664 if (phba->bucket_type != LPFC_NO_BUCKET) {
2665 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2666 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2667 bucket_value = phba->bucket_base +
2668 phba->bucket_step * i;
2670 bucket_value = phba->bucket_base +
2671 (1 << i) * phba->bucket_step;
2673 if (index + 10 > PAGE_SIZE)
2675 sprintf(&buf[index], "%08ld ", bucket_value);
2676 index = strlen(buf);
2679 sprintf(&buf[index], "\n");
2684 * Sysfs attribute to control the statistical data collection.
2686 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2687 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2690 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2694 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2697 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2698 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2699 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2703 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2705 * @kobj: Pointer to the kernel object
2706 * @bin_attr: Attribute object
2707 * @buff: Buffer pointer
2709 * @count: Buffer size
2711 * This function is the read call back function for lpfc_drvr_stat_data
2712 * sysfs file. This function export the statistical data to user
2716 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2717 struct bin_attribute *bin_attr,
2718 char *buf, loff_t off, size_t count)
2720 struct device *dev = container_of(kobj, struct device,
2722 struct Scsi_Host *shost = class_to_shost(dev);
2723 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2724 struct lpfc_hba *phba = vport->phba;
2725 int i = 0, index = 0;
2726 unsigned long nport_index;
2727 struct lpfc_nodelist *ndlp = NULL;
2728 nport_index = (unsigned long)off /
2729 MAX_STAT_DATA_SIZE_PER_TARGET;
2731 if (!vport->stat_data_enabled || vport->stat_data_blocked
2732 || (phba->bucket_type == LPFC_NO_BUCKET))
2735 spin_lock_irq(shost->host_lock);
2736 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2737 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2740 if (nport_index > 0) {
2745 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2749 if (!ndlp->lat_data)
2753 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2754 ndlp->nlp_portname.u.wwn[0],
2755 ndlp->nlp_portname.u.wwn[1],
2756 ndlp->nlp_portname.u.wwn[2],
2757 ndlp->nlp_portname.u.wwn[3],
2758 ndlp->nlp_portname.u.wwn[4],
2759 ndlp->nlp_portname.u.wwn[5],
2760 ndlp->nlp_portname.u.wwn[6],
2761 ndlp->nlp_portname.u.wwn[7]);
2763 index = strlen(buf);
2765 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2766 sprintf(&buf[index], "%010u,",
2767 ndlp->lat_data[i].cmd_count);
2768 index = strlen(buf);
2770 sprintf(&buf[index], "\n");
2771 index = strlen(buf);
2773 spin_unlock_irq(shost->host_lock);
2777 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2779 .name = "lpfc_drvr_stat_data",
2781 .owner = THIS_MODULE,
2783 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2784 .read = sysfs_drvr_stat_data_read,
2789 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2791 # 0 = auto select (default)
2796 # Value range is [0,8]. Default value is 0.
2800 * lpfc_link_speed_set - Set the adapters link speed
2801 * @phba: lpfc_hba pointer.
2802 * @val: link speed value.
2805 * If val is in a valid range then set the adapter's link speed field and
2806 * issue a lip; if the lip fails reset the link speed to the old value.
2809 * If the value is not in range log a kernel error message and return an error.
2812 * zero if val is in range and lip okay.
2813 * non-zero return value from lpfc_issue_lip()
2814 * -EINVAL val out of range
2817 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2818 const char *buf, size_t count)
2820 struct Scsi_Host *shost = class_to_shost(dev);
2821 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2822 struct lpfc_hba *phba = vport->phba;
2825 const char *val_buf = buf;
2829 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2831 val_buf = &buf[strlen("nolip ")];
2834 if (!isdigit(val_buf[0]))
2836 if (sscanf(val_buf, "%i", &val) != 1)
2839 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2840 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2841 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2842 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2843 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
2846 if ((val >= 0 && val <= 8)
2847 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2848 prev_val = phba->cfg_link_speed;
2849 phba->cfg_link_speed = val;
2853 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2855 phba->cfg_link_speed = prev_val;
2861 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2862 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2863 "allowed range is [0, 8]\n",
2868 static int lpfc_link_speed = 0;
2869 module_param(lpfc_link_speed, int, 0);
2870 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2871 lpfc_param_show(link_speed)
2874 * lpfc_link_speed_init - Set the adapters link speed
2875 * @phba: lpfc_hba pointer.
2876 * @val: link speed value.
2879 * If val is in a valid range then set the adapter's link speed field.
2882 * If the value is not in range log a kernel error message, clear the link
2883 * speed and return an error.
2886 * zero if val saved.
2887 * -EINVAL val out of range
2890 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2892 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
2893 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
2894 phba->cfg_link_speed = val;
2897 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2898 "0405 lpfc_link_speed attribute cannot "
2899 "be set to %d, allowed values are "
2900 "["LPFC_LINK_SPEED_STRING"]\n", val);
2901 phba->cfg_link_speed = 0;
2905 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2906 lpfc_link_speed_show, lpfc_link_speed_store);
2909 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
2910 # 0 = aer disabled or not supported
2911 # 1 = aer supported and enabled (default)
2912 # Value range is [0,1]. Default value is 1.
2916 * lpfc_aer_support_store - Set the adapter for aer support
2918 * @dev: class device that is converted into a Scsi_host.
2919 * @attr: device attribute, not used.
2920 * @buf: containing the string "selective".
2921 * @count: unused variable.
2924 * If the val is 1 and currently the device's AER capability was not
2925 * enabled, invoke the kernel's enable AER helper routine, trying to
2926 * enable the device's AER capability. If the helper routine enabling
2927 * AER returns success, update the device's cfg_aer_support flag to
2928 * indicate AER is supported by the device; otherwise, if the device
2929 * AER capability is already enabled to support AER, then do nothing.
2931 * If the val is 0 and currently the device's AER support was enabled,
2932 * invoke the kernel's disable AER helper routine. After that, update
2933 * the device's cfg_aer_support flag to indicate AER is not supported
2934 * by the device; otherwise, if the device AER capability is already
2935 * disabled from supporting AER, then do nothing.
2938 * length of the buf on success if val is in range the intended mode
2940 * -EINVAL if val out of range or intended mode is not supported.
2943 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
2944 const char *buf, size_t count)
2946 struct Scsi_Host *shost = class_to_shost(dev);
2947 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
2948 struct lpfc_hba *phba = vport->phba;
2949 int val = 0, rc = -EINVAL;
2951 if (!isdigit(buf[0]))
2953 if (sscanf(buf, "%i", &val) != 1)
2958 if (phba->hba_flag & HBA_AER_ENABLED) {
2959 rc = pci_disable_pcie_error_reporting(phba->pcidev);
2961 spin_lock_irq(&phba->hbalock);
2962 phba->hba_flag &= ~HBA_AER_ENABLED;
2963 spin_unlock_irq(&phba->hbalock);
2964 phba->cfg_aer_support = 0;
2969 phba->cfg_aer_support = 0;
2974 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
2975 rc = pci_enable_pcie_error_reporting(phba->pcidev);
2977 spin_lock_irq(&phba->hbalock);
2978 phba->hba_flag |= HBA_AER_ENABLED;
2979 spin_unlock_irq(&phba->hbalock);
2980 phba->cfg_aer_support = 1;
2985 phba->cfg_aer_support = 1;
2996 static int lpfc_aer_support = 1;
2997 module_param(lpfc_aer_support, int, 1);
2998 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
2999 lpfc_param_show(aer_support)
3002 * lpfc_aer_support_init - Set the initial adapters aer support flag
3003 * @phba: lpfc_hba pointer.
3004 * @val: link speed value.
3007 * If val is in a valid range [0,1], then set the adapter's initial
3008 * cfg_aer_support field. It will be up to the driver's probe_one
3009 * routine to determine whether the device's AER support can be set
3013 * If the value is not in range log a kernel error message, and
3014 * choose the default value of setting AER support and return.
3017 * zero if val saved.
3018 * -EINVAL val out of range
3021 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3023 if (val == 0 || val == 1) {
3024 phba->cfg_aer_support = val;
3027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3028 "2712 lpfc_aer_support attribute value %d out "
3029 "of range, allowed values are 0|1, setting it "
3030 "to default value of 1\n", val);
3031 /* By default, try to enable AER on a device */
3032 phba->cfg_aer_support = 1;
3036 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3037 lpfc_aer_support_show, lpfc_aer_support_store);
3040 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3041 * @dev: class device that is converted into a Scsi_host.
3042 * @attr: device attribute, not used.
3043 * @buf: containing the string "selective".
3044 * @count: unused variable.
3047 * If the @buf contains 1 and the device currently has the AER support
3048 * enabled, then invokes the kernel AER helper routine
3049 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3050 * error status register.
3055 * -EINVAL if the buf does not contain the 1 or the device is not currently
3056 * enabled with the AER support.
3059 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3060 const char *buf, size_t count)
3062 struct Scsi_Host *shost = class_to_shost(dev);
3063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3064 struct lpfc_hba *phba = vport->phba;
3067 if (!isdigit(buf[0]))
3069 if (sscanf(buf, "%i", &val) != 1)
3074 if (phba->hba_flag & HBA_AER_ENABLED)
3075 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3083 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3084 lpfc_aer_cleanup_state);
3087 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3088 # Value range is [2,3]. Default value is 3.
3090 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3091 "Select Fibre Channel class of service for FCP sequences");
3094 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3095 # is [0,1]. Default value is 0.
3097 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3098 "Use ADISC on rediscovery to authenticate FCP devices");
3101 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3102 # depth. Default value is 0. When the value of this parameter is zero the
3103 # SCSI command completion time is not used for controlling I/O queue depth. When
3104 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3105 # to limit the I/O completion time to the parameter value.
3106 # The value is set in milliseconds.
3108 static int lpfc_max_scsicmpl_time;
3109 module_param(lpfc_max_scsicmpl_time, int, 0);
3110 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3111 "Use command completion time to control queue depth");
3112 lpfc_vport_param_show(max_scsicmpl_time);
3113 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3115 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3117 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3118 struct lpfc_nodelist *ndlp, *next_ndlp;
3120 if (val == vport->cfg_max_scsicmpl_time)
3122 if ((val < 0) || (val > 60000))
3124 vport->cfg_max_scsicmpl_time = val;
3126 spin_lock_irq(shost->host_lock);
3127 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3128 if (!NLP_CHK_NODE_ACT(ndlp))
3130 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3132 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3134 spin_unlock_irq(shost->host_lock);
3137 lpfc_vport_param_store(max_scsicmpl_time);
3138 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3139 lpfc_max_scsicmpl_time_show,
3140 lpfc_max_scsicmpl_time_store);
3143 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3144 # range is [0,1]. Default value is 0.
3146 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3149 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3150 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3151 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3152 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3153 # cr_delay is set to 0.
3155 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3156 "interrupt response is generated");
3158 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3159 "interrupt response is generated");
3162 # lpfc_multi_ring_support: Determines how many rings to spread available
3163 # cmd/rsp IOCB entries across.
3164 # Value range is [1,2]. Default value is 1.
3166 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3167 "SLI rings to spread IOCB entries across");
3170 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3171 # identifies what rctl value to configure the additional ring for.
3172 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3174 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3175 255, "Identifies RCTL for additional ring configuration");
3178 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3179 # identifies what type value to configure the additional ring for.
3180 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3182 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3183 255, "Identifies TYPE for additional ring configuration");
3186 # lpfc_fdmi_on: controls FDMI support.
3187 # 0 = no FDMI support
3188 # 1 = support FDMI without attribute of hostname
3189 # 2 = support FDMI with attribute of hostname
3190 # Value range [0,2]. Default value is 0.
3192 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3195 # Specifies the maximum number of ELS cmds we can have outstanding (for
3196 # discovery). Value range is [1,64]. Default value = 32.
3198 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3199 "during discovery");
3202 # lpfc_max_luns: maximum allowed LUN.
3203 # Value range is [0,65535]. Default value is 255.
3204 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3206 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3209 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3210 # Value range is [1,255], default value is 10.
3212 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3213 "Milliseconds driver will wait between polling FCP ring");
3216 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3217 # support this feature
3220 # 2 = MSI-X enabled (default)
3221 # Value range is [0,2]. Default value is 2.
3223 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3224 "MSI-X (2), if possible");
3227 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3229 # Value range is [636,651042]. Default value is 10000.
3231 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3232 "Set the maximum number of fast-path FCP interrupts per second");
3235 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3237 # Value range is [1,31]. Default value is 4.
3239 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3240 "Set the number of fast-path FCP work queues, if possible");
3243 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3245 # Value range is [1,7]. Default value is 1.
3247 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3248 "Set the number of fast-path FCP event queues, if possible");
3251 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3252 # 0 = HBA resets disabled
3253 # 1 = HBA resets enabled (default)
3254 # Value range is [0,1]. Default value is 1.
3256 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3259 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
3260 # 0 = HBA Heartbeat disabled
3261 # 1 = HBA Heartbeat enabled (default)
3262 # Value range is [0,1]. Default value is 1.
3264 LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
3267 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3268 # 0 = BlockGuard disabled (default)
3269 # 1 = BlockGuard enabled
3270 # Value range is [0,1]. Default value is 0.
3272 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3276 # - Bit mask of host protection capabilities used to register with the
3278 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3279 # - Allows you to ultimately specify which profiles to use
3280 # - Default will result in registering capabilities for all profiles.
3283 unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION;
3285 module_param(lpfc_prot_mask, uint, 0);
3286 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3289 # lpfc_prot_guard: i
3290 # - Bit mask of protection guard types to register with the SCSI mid-layer
3291 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3292 # - Allows you to ultimately specify which profiles to use
3293 # - Default will result in registering capabilities for all guard types
3296 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3297 module_param(lpfc_prot_guard, byte, 0);
3298 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3302 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3303 * This value can be set to values between 64 and 256. The default value is
3304 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3305 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3307 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3308 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3310 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3311 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3312 "Max Protection Scatter Gather Segment Count");
3314 struct device_attribute *lpfc_hba_attrs[] = {
3316 &dev_attr_bg_guard_err,
3317 &dev_attr_bg_apptag_err,
3318 &dev_attr_bg_reftag_err,
3320 &dev_attr_serialnum,
3321 &dev_attr_modeldesc,
3322 &dev_attr_modelname,
3323 &dev_attr_programtype,
3327 &dev_attr_option_rom_version,
3328 &dev_attr_link_state,
3329 &dev_attr_num_discovered_ports,
3330 &dev_attr_menlo_mgmt_mode,
3331 &dev_attr_lpfc_drvr_version,
3332 &dev_attr_lpfc_enable_fip,
3333 &dev_attr_lpfc_temp_sensor,
3334 &dev_attr_lpfc_log_verbose,
3335 &dev_attr_lpfc_lun_queue_depth,
3336 &dev_attr_lpfc_tgt_queue_depth,
3337 &dev_attr_lpfc_hba_queue_depth,
3338 &dev_attr_lpfc_peer_port_login,
3339 &dev_attr_lpfc_nodev_tmo,
3340 &dev_attr_lpfc_devloss_tmo,
3341 &dev_attr_lpfc_fcp_class,
3342 &dev_attr_lpfc_use_adisc,
3343 &dev_attr_lpfc_ack0,
3344 &dev_attr_lpfc_topology,
3345 &dev_attr_lpfc_scan_down,
3346 &dev_attr_lpfc_link_speed,
3347 &dev_attr_lpfc_cr_delay,
3348 &dev_attr_lpfc_cr_count,
3349 &dev_attr_lpfc_multi_ring_support,
3350 &dev_attr_lpfc_multi_ring_rctl,
3351 &dev_attr_lpfc_multi_ring_type,
3352 &dev_attr_lpfc_fdmi_on,
3353 &dev_attr_lpfc_max_luns,
3354 &dev_attr_lpfc_enable_npiv,
3355 &dev_attr_nport_evt_cnt,
3356 &dev_attr_board_mode,
3363 &dev_attr_npiv_info,
3364 &dev_attr_issue_reset,
3365 &dev_attr_lpfc_poll,
3366 &dev_attr_lpfc_poll_tmo,
3367 &dev_attr_lpfc_use_msi,
3368 &dev_attr_lpfc_fcp_imax,
3369 &dev_attr_lpfc_fcp_wq_count,
3370 &dev_attr_lpfc_fcp_eq_count,
3371 &dev_attr_lpfc_enable_bg,
3372 &dev_attr_lpfc_soft_wwnn,
3373 &dev_attr_lpfc_soft_wwpn,
3374 &dev_attr_lpfc_soft_wwn_enable,
3375 &dev_attr_lpfc_enable_hba_reset,
3376 &dev_attr_lpfc_enable_hba_heartbeat,
3377 &dev_attr_lpfc_sg_seg_cnt,
3378 &dev_attr_lpfc_max_scsicmpl_time,
3379 &dev_attr_lpfc_stat_data_ctrl,
3380 &dev_attr_lpfc_prot_sg_seg_cnt,
3381 &dev_attr_lpfc_aer_support,
3382 &dev_attr_lpfc_aer_state_cleanup,
3383 &dev_attr_lpfc_suppress_link_up,
3384 &dev_attr_lpfc_iocb_cnt,
3387 &dev_attr_txcmplq_hw,
3391 struct device_attribute *lpfc_vport_attrs[] = {
3393 &dev_attr_link_state,
3394 &dev_attr_num_discovered_ports,
3395 &dev_attr_lpfc_drvr_version,
3396 &dev_attr_lpfc_log_verbose,
3397 &dev_attr_lpfc_lun_queue_depth,
3398 &dev_attr_lpfc_tgt_queue_depth,
3399 &dev_attr_lpfc_nodev_tmo,
3400 &dev_attr_lpfc_devloss_tmo,
3401 &dev_attr_lpfc_hba_queue_depth,
3402 &dev_attr_lpfc_peer_port_login,
3403 &dev_attr_lpfc_restrict_login,
3404 &dev_attr_lpfc_fcp_class,
3405 &dev_attr_lpfc_use_adisc,
3406 &dev_attr_lpfc_fdmi_on,
3407 &dev_attr_lpfc_max_luns,
3408 &dev_attr_nport_evt_cnt,
3409 &dev_attr_npiv_info,
3410 &dev_attr_lpfc_enable_da_id,
3411 &dev_attr_lpfc_max_scsicmpl_time,
3412 &dev_attr_lpfc_stat_data_ctrl,
3413 &dev_attr_lpfc_static_vport,
3418 * sysfs_ctlreg_write - Write method for writing to ctlreg
3419 * @filp: open sysfs file
3420 * @kobj: kernel kobject that contains the kernel class device.
3421 * @bin_attr: kernel attributes passed to us.
3422 * @buf: contains the data to be written to the adapter IOREG space.
3423 * @off: offset into buffer to beginning of data.
3424 * @count: bytes to transfer.
3427 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3428 * Uses the adapter io control registers to send buf contents to the adapter.
3431 * -ERANGE off and count combo out of range
3432 * -EINVAL off, count or buff address invalid
3433 * -EPERM adapter is offline
3434 * value of count, buf contents written
3437 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3438 struct bin_attribute *bin_attr,
3439 char *buf, loff_t off, size_t count)
3442 struct device *dev = container_of(kobj, struct device, kobj);
3443 struct Scsi_Host *shost = class_to_shost(dev);
3444 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3445 struct lpfc_hba *phba = vport->phba;
3447 if (phba->sli_rev >= LPFC_SLI_REV4)
3450 if ((off + count) > FF_REG_AREA_SIZE)
3453 if (count == 0) return 0;
3455 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3458 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3462 spin_lock_irq(&phba->hbalock);
3463 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3464 writel(*((uint32_t *)(buf + buf_off)),
3465 phba->ctrl_regs_memmap_p + off + buf_off);
3467 spin_unlock_irq(&phba->hbalock);
3473 * sysfs_ctlreg_read - Read method for reading from ctlreg
3474 * @filp: open sysfs file
3475 * @kobj: kernel kobject that contains the kernel class device.
3476 * @bin_attr: kernel attributes passed to us.
3477 * @buf: if successful contains the data from the adapter IOREG space.
3478 * @off: offset into buffer to beginning of data.
3479 * @count: bytes to transfer.
3482 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3483 * Uses the adapter io control registers to read data into buf.
3486 * -ERANGE off and count combo out of range
3487 * -EINVAL off, count or buff address invalid
3488 * value of count, buf contents read
3491 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3492 struct bin_attribute *bin_attr,
3493 char *buf, loff_t off, size_t count)
3497 struct device *dev = container_of(kobj, struct device, kobj);
3498 struct Scsi_Host *shost = class_to_shost(dev);
3499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3500 struct lpfc_hba *phba = vport->phba;
3502 if (phba->sli_rev >= LPFC_SLI_REV4)
3505 if (off > FF_REG_AREA_SIZE)
3508 if ((off + count) > FF_REG_AREA_SIZE)
3509 count = FF_REG_AREA_SIZE - off;
3511 if (count == 0) return 0;
3513 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3516 spin_lock_irq(&phba->hbalock);
3518 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3519 tmp_ptr = (uint32_t *)(buf + buf_off);
3520 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3523 spin_unlock_irq(&phba->hbalock);
3528 static struct bin_attribute sysfs_ctlreg_attr = {
3531 .mode = S_IRUSR | S_IWUSR,
3534 .read = sysfs_ctlreg_read,
3535 .write = sysfs_ctlreg_write,
3539 * sysfs_mbox_idle - frees the sysfs mailbox
3540 * @phba: lpfc_hba pointer
3543 sysfs_mbox_idle(struct lpfc_hba *phba)
3545 phba->sysfs_mbox.state = SMBOX_IDLE;
3546 phba->sysfs_mbox.offset = 0;
3548 if (phba->sysfs_mbox.mbox) {
3549 mempool_free(phba->sysfs_mbox.mbox,
3550 phba->mbox_mem_pool);
3551 phba->sysfs_mbox.mbox = NULL;
3556 * sysfs_mbox_write - Write method for writing information via mbox
3557 * @filp: open sysfs file
3558 * @kobj: kernel kobject that contains the kernel class device.
3559 * @bin_attr: kernel attributes passed to us.
3560 * @buf: contains the data to be written to sysfs mbox.
3561 * @off: offset into buffer to beginning of data.
3562 * @count: bytes to transfer.
3565 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3566 * Uses the sysfs mbox to send buf contents to the adapter.
3569 * -ERANGE off and count combo out of range
3570 * -EINVAL off, count or buff address invalid
3571 * zero if count is zero
3572 * -EPERM adapter is offline
3573 * -ENOMEM failed to allocate memory for the mail box
3574 * -EAGAIN offset, state or mbox is NULL
3575 * count number of bytes transferred
3578 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3579 struct bin_attribute *bin_attr,
3580 char *buf, loff_t off, size_t count)
3582 struct device *dev = container_of(kobj, struct device, kobj);
3583 struct Scsi_Host *shost = class_to_shost(dev);
3584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3585 struct lpfc_hba *phba = vport->phba;
3586 struct lpfcMboxq *mbox = NULL;
3588 if ((count + off) > MAILBOX_CMD_SIZE)
3591 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3598 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3601 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3604 spin_lock_irq(&phba->hbalock);
3607 if (phba->sysfs_mbox.mbox)
3608 mempool_free(mbox, phba->mbox_mem_pool);
3610 phba->sysfs_mbox.mbox = mbox;
3611 phba->sysfs_mbox.state = SMBOX_WRITING;
3613 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3614 phba->sysfs_mbox.offset != off ||
3615 phba->sysfs_mbox.mbox == NULL) {
3616 sysfs_mbox_idle(phba);
3617 spin_unlock_irq(&phba->hbalock);
3622 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3625 phba->sysfs_mbox.offset = off + count;
3627 spin_unlock_irq(&phba->hbalock);
3633 * sysfs_mbox_read - Read method for reading information via mbox
3634 * @filp: open sysfs file
3635 * @kobj: kernel kobject that contains the kernel class device.
3636 * @bin_attr: kernel attributes passed to us.
3637 * @buf: contains the data to be read from sysfs mbox.
3638 * @off: offset into buffer to beginning of data.
3639 * @count: bytes to transfer.
3642 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3643 * Uses the sysfs mbox to receive data from to the adapter.
3646 * -ERANGE off greater than mailbox command size
3647 * -EINVAL off, count or buff address invalid
3648 * zero if off and count are zero
3649 * -EACCES adapter over temp
3650 * -EPERM garbage can value to catch a multitude of errors
3651 * -EAGAIN management IO not permitted, state or off error
3652 * -ETIME mailbox timeout
3653 * -ENODEV mailbox error
3654 * count number of bytes transferred
3657 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3658 struct bin_attribute *bin_attr,
3659 char *buf, loff_t off, size_t count)
3661 struct device *dev = container_of(kobj, struct device, kobj);
3662 struct Scsi_Host *shost = class_to_shost(dev);
3663 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3664 struct lpfc_hba *phba = vport->phba;
3668 if (off > MAILBOX_CMD_SIZE)
3671 if ((count + off) > MAILBOX_CMD_SIZE)
3672 count = MAILBOX_CMD_SIZE - off;
3674 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3677 if (off && count == 0)
3680 spin_lock_irq(&phba->hbalock);
3682 if (phba->over_temp_state == HBA_OVER_TEMP) {
3683 sysfs_mbox_idle(phba);
3684 spin_unlock_irq(&phba->hbalock);
3689 phba->sysfs_mbox.state == SMBOX_WRITING &&
3690 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3691 pmb = &phba->sysfs_mbox.mbox->u.mb;
3692 switch (pmb->mbxCommand) {
3696 case MBX_CONFIG_LINK:
3697 case MBX_CONFIG_RING:
3698 case MBX_RESET_RING:
3699 case MBX_UNREG_LOGIN:
3701 case MBX_DUMP_CONTEXT:
3706 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3707 printk(KERN_WARNING "mbox_read:Command 0x%x "
3708 "is illegal in on-line state\n",
3710 sysfs_mbox_idle(phba);
3711 spin_unlock_irq(&phba->hbalock);
3715 case MBX_WRITE_VPARMS:
3718 case MBX_READ_CONFIG:
3719 case MBX_READ_RCONFIG:
3720 case MBX_READ_STATUS:
3723 case MBX_READ_LNK_STAT:
3724 case MBX_DUMP_MEMORY:
3726 case MBX_UPDATE_CFG:
3727 case MBX_KILL_BOARD:
3729 case MBX_LOAD_EXP_ROM:
3731 case MBX_DEL_LD_ENTRY:
3732 case MBX_SET_VARIABLE:
3734 case MBX_PORT_CAPABILITIES:
3735 case MBX_PORT_IOV_CONTROL:
3737 case MBX_READ_SPARM64:
3741 case MBX_REG_LOGIN64:
3742 case MBX_CONFIG_PORT:
3743 case MBX_RUN_BIU_DIAG:
3744 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3746 sysfs_mbox_idle(phba);
3747 spin_unlock_irq(&phba->hbalock);
3750 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3752 sysfs_mbox_idle(phba);
3753 spin_unlock_irq(&phba->hbalock);
3757 /* If HBA encountered an error attention, allow only DUMP
3758 * or RESTART mailbox commands until the HBA is restarted.
3760 if (phba->pport->stopped &&
3761 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3762 pmb->mbxCommand != MBX_RESTART &&
3763 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3764 pmb->mbxCommand != MBX_WRITE_WWN)
3765 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3766 "1259 mbox: Issued mailbox cmd "
3767 "0x%x while in stopped state.\n",
3770 phba->sysfs_mbox.mbox->vport = vport;
3772 /* Don't allow mailbox commands to be sent when blocked
3773 * or when in the middle of discovery
3775 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3776 sysfs_mbox_idle(phba);
3777 spin_unlock_irq(&phba->hbalock);
3781 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3782 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3784 spin_unlock_irq(&phba->hbalock);
3785 rc = lpfc_sli_issue_mbox (phba,
3786 phba->sysfs_mbox.mbox,
3788 spin_lock_irq(&phba->hbalock);
3791 spin_unlock_irq(&phba->hbalock);
3792 rc = lpfc_sli_issue_mbox_wait (phba,
3793 phba->sysfs_mbox.mbox,
3794 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3795 spin_lock_irq(&phba->hbalock);
3798 if (rc != MBX_SUCCESS) {
3799 if (rc == MBX_TIMEOUT) {
3800 phba->sysfs_mbox.mbox = NULL;
3802 sysfs_mbox_idle(phba);
3803 spin_unlock_irq(&phba->hbalock);
3804 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3806 phba->sysfs_mbox.state = SMBOX_READING;
3808 else if (phba->sysfs_mbox.offset != off ||
3809 phba->sysfs_mbox.state != SMBOX_READING) {
3810 printk(KERN_WARNING "mbox_read: Bad State\n");
3811 sysfs_mbox_idle(phba);
3812 spin_unlock_irq(&phba->hbalock);
3816 memcpy(buf, (uint8_t *) &pmb + off, count);
3818 phba->sysfs_mbox.offset = off + count;
3820 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3821 sysfs_mbox_idle(phba);
3823 spin_unlock_irq(&phba->hbalock);
3828 static struct bin_attribute sysfs_mbox_attr = {
3831 .mode = S_IRUSR | S_IWUSR,
3833 .size = MAILBOX_CMD_SIZE,
3834 .read = sysfs_mbox_read,
3835 .write = sysfs_mbox_write,
3839 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3840 * @vport: address of lpfc vport structure.
3844 * error return code from sysfs_create_bin_file()
3847 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3852 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3853 &sysfs_drvr_stat_data_attr);
3855 /* Virtual ports do not need ctrl_reg and mbox */
3856 if (error || vport->port_type == LPFC_NPIV_PORT)
3859 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3860 &sysfs_ctlreg_attr);
3862 goto out_remove_stat_attr;
3864 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3867 goto out_remove_ctlreg_attr;
3870 out_remove_ctlreg_attr:
3871 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3872 out_remove_stat_attr:
3873 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3874 &sysfs_drvr_stat_data_attr);
3880 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
3881 * @vport: address of lpfc vport structure.
3884 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
3886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3887 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3888 &sysfs_drvr_stat_data_attr);
3889 /* Virtual ports do not need ctrl_reg and mbox */
3890 if (vport->port_type == LPFC_NPIV_PORT)
3892 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
3893 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3898 * Dynamic FC Host Attributes Support
3902 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
3903 * @shost: kernel scsi host pointer.
3906 lpfc_get_host_port_id(struct Scsi_Host *shost)
3908 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3910 /* note: fc_myDID already in cpu endianness */
3911 fc_host_port_id(shost) = vport->fc_myDID;
3915 * lpfc_get_host_port_type - Set the value of the scsi host port type
3916 * @shost: kernel scsi host pointer.
3919 lpfc_get_host_port_type(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 (vport->port_type == LPFC_NPIV_PORT) {
3927 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
3928 } else if (lpfc_is_link_up(phba)) {
3929 if (phba->fc_topology == TOPOLOGY_LOOP) {
3930 if (vport->fc_flag & FC_PUBLIC_LOOP)
3931 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
3933 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
3935 if (vport->fc_flag & FC_FABRIC)
3936 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
3938 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
3941 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
3943 spin_unlock_irq(shost->host_lock);
3947 * lpfc_get_host_port_state - Set the value of the scsi host port state
3948 * @shost: kernel scsi host pointer.
3951 lpfc_get_host_port_state(struct Scsi_Host *shost)
3953 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3954 struct lpfc_hba *phba = vport->phba;
3956 spin_lock_irq(shost->host_lock);
3958 if (vport->fc_flag & FC_OFFLINE_MODE)
3959 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
3961 switch (phba->link_state) {
3962 case LPFC_LINK_UNKNOWN:
3963 case LPFC_LINK_DOWN:
3964 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3968 case LPFC_HBA_READY:
3969 /* Links up, beyond this port_type reports state */
3970 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3972 case LPFC_HBA_ERROR:
3973 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
3976 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3981 spin_unlock_irq(shost->host_lock);
3985 * lpfc_get_host_speed - Set the value of the scsi host speed
3986 * @shost: kernel scsi host pointer.
3989 lpfc_get_host_speed(struct Scsi_Host *shost)
3991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3992 struct lpfc_hba *phba = vport->phba;
3994 spin_lock_irq(shost->host_lock);
3996 if (lpfc_is_link_up(phba)) {
3997 switch(phba->fc_linkspeed) {
3999 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4002 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4005 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4008 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4011 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4014 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4018 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4020 spin_unlock_irq(shost->host_lock);
4024 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4025 * @shost: kernel scsi host pointer.
4028 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4030 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4031 struct lpfc_hba *phba = vport->phba;
4034 spin_lock_irq(shost->host_lock);
4036 if ((vport->fc_flag & FC_FABRIC) ||
4037 ((phba->fc_topology == TOPOLOGY_LOOP) &&
4038 (vport->fc_flag & FC_PUBLIC_LOOP)))
4039 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4041 /* fabric is local port if there is no F/FL_Port */
4044 spin_unlock_irq(shost->host_lock);
4046 fc_host_fabric_name(shost) = node_name;
4050 * lpfc_get_stats - Return statistical information about the adapter
4051 * @shost: kernel scsi host pointer.
4054 * NULL on error for link down, no mbox pool, sli2 active,
4055 * management not allowed, memory allocation error, or mbox error.
4059 * address of the adapter host statistics
4061 static struct fc_host_statistics *
4062 lpfc_get_stats(struct Scsi_Host *shost)
4064 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4065 struct lpfc_hba *phba = vport->phba;
4066 struct lpfc_sli *psli = &phba->sli;
4067 struct fc_host_statistics *hs = &phba->link_stats;
4068 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4069 LPFC_MBOXQ_t *pmboxq;
4071 unsigned long seconds;
4075 * prevent udev from issuing mailbox commands until the port is
4078 if (phba->link_state < LPFC_LINK_DOWN ||
4079 !phba->mbox_mem_pool ||
4080 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4083 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4086 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4089 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4091 pmb = &pmboxq->u.mb;
4092 pmb->mbxCommand = MBX_READ_STATUS;
4093 pmb->mbxOwner = OWN_HOST;
4094 pmboxq->context1 = NULL;
4095 pmboxq->vport = vport;
4097 if (vport->fc_flag & FC_OFFLINE_MODE)
4098 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4100 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4102 if (rc != MBX_SUCCESS) {
4103 if (rc != MBX_TIMEOUT)
4104 mempool_free(pmboxq, phba->mbox_mem_pool);
4108 memset(hs, 0, sizeof (struct fc_host_statistics));
4110 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4111 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4112 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4113 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4115 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4116 pmb->mbxCommand = MBX_READ_LNK_STAT;
4117 pmb->mbxOwner = OWN_HOST;
4118 pmboxq->context1 = NULL;
4119 pmboxq->vport = vport;
4121 if (vport->fc_flag & FC_OFFLINE_MODE)
4122 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4124 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4126 if (rc != MBX_SUCCESS) {
4127 if (rc != MBX_TIMEOUT)
4128 mempool_free(pmboxq, phba->mbox_mem_pool);
4132 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4133 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4134 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4135 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4136 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4137 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4138 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4140 hs->link_failure_count -= lso->link_failure_count;
4141 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4142 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4143 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4144 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4145 hs->invalid_crc_count -= lso->invalid_crc_count;
4146 hs->error_frames -= lso->error_frames;
4148 if (phba->hba_flag & HBA_FCOE_SUPPORT) {
4150 hs->nos_count = (phba->link_events >> 1);
4151 hs->nos_count -= lso->link_events;
4152 } else if (phba->fc_topology == TOPOLOGY_LOOP) {
4153 hs->lip_count = (phba->fc_eventTag >> 1);
4154 hs->lip_count -= lso->link_events;
4158 hs->nos_count = (phba->fc_eventTag >> 1);
4159 hs->nos_count -= lso->link_events;
4162 hs->dumped_frames = -1;
4164 seconds = get_seconds();
4165 if (seconds < psli->stats_start)
4166 hs->seconds_since_last_reset = seconds +
4167 ((unsigned long)-1 - psli->stats_start);
4169 hs->seconds_since_last_reset = seconds - psli->stats_start;
4171 mempool_free(pmboxq, phba->mbox_mem_pool);
4177 * lpfc_reset_stats - Copy the adapter link stats information
4178 * @shost: kernel scsi host pointer.
4181 lpfc_reset_stats(struct Scsi_Host *shost)
4183 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4184 struct lpfc_hba *phba = vport->phba;
4185 struct lpfc_sli *psli = &phba->sli;
4186 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4187 LPFC_MBOXQ_t *pmboxq;
4191 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4194 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4197 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4199 pmb = &pmboxq->u.mb;
4200 pmb->mbxCommand = MBX_READ_STATUS;
4201 pmb->mbxOwner = OWN_HOST;
4202 pmb->un.varWords[0] = 0x1; /* reset request */
4203 pmboxq->context1 = NULL;
4204 pmboxq->vport = vport;
4206 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4207 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4208 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4210 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4212 if (rc != MBX_SUCCESS) {
4213 if (rc != MBX_TIMEOUT)
4214 mempool_free(pmboxq, phba->mbox_mem_pool);
4218 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4219 pmb->mbxCommand = MBX_READ_LNK_STAT;
4220 pmb->mbxOwner = OWN_HOST;
4221 pmboxq->context1 = NULL;
4222 pmboxq->vport = vport;
4224 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4225 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4226 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4228 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4230 if (rc != MBX_SUCCESS) {
4231 if (rc != MBX_TIMEOUT)
4232 mempool_free( pmboxq, phba->mbox_mem_pool);
4236 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4237 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4238 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4239 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4240 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4241 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4242 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4243 if (phba->hba_flag & HBA_FCOE_SUPPORT)
4244 lso->link_events = (phba->link_events >> 1);
4246 lso->link_events = (phba->fc_eventTag >> 1);
4248 psli->stats_start = get_seconds();
4250 mempool_free(pmboxq, phba->mbox_mem_pool);
4256 * The LPFC driver treats linkdown handling as target loss events so there
4257 * are no sysfs handlers for link_down_tmo.
4261 * lpfc_get_node_by_target - Return the nodelist for a target
4262 * @starget: kernel scsi target pointer.
4265 * address of the node list if found
4266 * NULL target not found
4268 static struct lpfc_nodelist *
4269 lpfc_get_node_by_target(struct scsi_target *starget)
4271 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4273 struct lpfc_nodelist *ndlp;
4275 spin_lock_irq(shost->host_lock);
4276 /* Search for this, mapped, target ID */
4277 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4278 if (NLP_CHK_NODE_ACT(ndlp) &&
4279 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4280 starget->id == ndlp->nlp_sid) {
4281 spin_unlock_irq(shost->host_lock);
4285 spin_unlock_irq(shost->host_lock);
4290 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4291 * @starget: kernel scsi target pointer.
4294 lpfc_get_starget_port_id(struct scsi_target *starget)
4296 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4298 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4302 * lpfc_get_starget_node_name - Set the target node name
4303 * @starget: kernel scsi target pointer.
4305 * Description: Set the target node name to the ndlp node name wwn or zero.
4308 lpfc_get_starget_node_name(struct scsi_target *starget)
4310 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4312 fc_starget_node_name(starget) =
4313 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4317 * lpfc_get_starget_port_name - Set the target port name
4318 * @starget: kernel scsi target pointer.
4320 * Description: set the target port name to the ndlp port name wwn or zero.
4323 lpfc_get_starget_port_name(struct scsi_target *starget)
4325 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4327 fc_starget_port_name(starget) =
4328 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4332 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4333 * @rport: fc rport address.
4334 * @timeout: new value for dev loss tmo.
4337 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4338 * dev_loss_tmo to one.
4341 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4344 rport->dev_loss_tmo = timeout;
4346 rport->dev_loss_tmo = 1;
4350 * lpfc_rport_show_function - Return rport target information
4353 * Macro that uses field to generate a function with the name lpfc_show_rport_
4355 * lpfc_show_rport_##field: returns the bytes formatted in buf
4356 * @cdev: class converted to an fc_rport.
4357 * @buf: on return contains the target_field or zero.
4359 * Returns: size of formatted string.
4361 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4363 lpfc_show_rport_##field (struct device *dev, \
4364 struct device_attribute *attr, \
4367 struct fc_rport *rport = transport_class_to_rport(dev); \
4368 struct lpfc_rport_data *rdata = rport->hostdata; \
4369 return snprintf(buf, sz, format_string, \
4370 (rdata->target) ? cast rdata->target->field : 0); \
4373 #define lpfc_rport_rd_attr(field, format_string, sz) \
4374 lpfc_rport_show_function(field, format_string, sz, ) \
4375 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4378 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4379 * @fc_vport: The fc_vport who's symbolic name has been changed.
4382 * This function is called by the transport after the @fc_vport's symbolic name
4383 * has been changed. This function re-registers the symbolic name with the
4384 * switch to propogate the change into the fabric if the vport is active.
4387 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4389 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4391 if (vport->port_state == LPFC_VPORT_READY)
4392 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4396 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4397 * @phba: Pointer to lpfc_hba struct.
4399 * This function is called by the lpfc_get_cfgparam() routine to set the
4400 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4401 * log messsage according to the module's lpfc_log_verbose parameter setting
4402 * before hba port or vport created.
4405 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4407 phba->cfg_log_verbose = verbose;
4410 struct fc_function_template lpfc_transport_functions = {
4411 /* fixed attributes the driver supports */
4412 .show_host_node_name = 1,
4413 .show_host_port_name = 1,
4414 .show_host_supported_classes = 1,
4415 .show_host_supported_fc4s = 1,
4416 .show_host_supported_speeds = 1,
4417 .show_host_maxframe_size = 1,
4418 .show_host_symbolic_name = 1,
4420 /* dynamic attributes the driver supports */
4421 .get_host_port_id = lpfc_get_host_port_id,
4422 .show_host_port_id = 1,
4424 .get_host_port_type = lpfc_get_host_port_type,
4425 .show_host_port_type = 1,
4427 .get_host_port_state = lpfc_get_host_port_state,
4428 .show_host_port_state = 1,
4430 /* active_fc4s is shown but doesn't change (thus no get function) */
4431 .show_host_active_fc4s = 1,
4433 .get_host_speed = lpfc_get_host_speed,
4434 .show_host_speed = 1,
4436 .get_host_fabric_name = lpfc_get_host_fabric_name,
4437 .show_host_fabric_name = 1,
4440 * The LPFC driver treats linkdown handling as target loss events
4441 * so there are no sysfs handlers for link_down_tmo.
4444 .get_fc_host_stats = lpfc_get_stats,
4445 .reset_fc_host_stats = lpfc_reset_stats,
4447 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4448 .show_rport_maxframe_size = 1,
4449 .show_rport_supported_classes = 1,
4451 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4452 .show_rport_dev_loss_tmo = 1,
4454 .get_starget_port_id = lpfc_get_starget_port_id,
4455 .show_starget_port_id = 1,
4457 .get_starget_node_name = lpfc_get_starget_node_name,
4458 .show_starget_node_name = 1,
4460 .get_starget_port_name = lpfc_get_starget_port_name,
4461 .show_starget_port_name = 1,
4463 .issue_fc_host_lip = lpfc_issue_lip,
4464 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4465 .terminate_rport_io = lpfc_terminate_rport_io,
4467 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4469 .vport_disable = lpfc_vport_disable,
4471 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4473 .bsg_request = lpfc_bsg_request,
4474 .bsg_timeout = lpfc_bsg_timeout,
4477 struct fc_function_template lpfc_vport_transport_functions = {
4478 /* fixed attributes the driver supports */
4479 .show_host_node_name = 1,
4480 .show_host_port_name = 1,
4481 .show_host_supported_classes = 1,
4482 .show_host_supported_fc4s = 1,
4483 .show_host_supported_speeds = 1,
4484 .show_host_maxframe_size = 1,
4485 .show_host_symbolic_name = 1,
4487 /* dynamic attributes the driver supports */
4488 .get_host_port_id = lpfc_get_host_port_id,
4489 .show_host_port_id = 1,
4491 .get_host_port_type = lpfc_get_host_port_type,
4492 .show_host_port_type = 1,
4494 .get_host_port_state = lpfc_get_host_port_state,
4495 .show_host_port_state = 1,
4497 /* active_fc4s is shown but doesn't change (thus no get function) */
4498 .show_host_active_fc4s = 1,
4500 .get_host_speed = lpfc_get_host_speed,
4501 .show_host_speed = 1,
4503 .get_host_fabric_name = lpfc_get_host_fabric_name,
4504 .show_host_fabric_name = 1,
4507 * The LPFC driver treats linkdown handling as target loss events
4508 * so there are no sysfs handlers for link_down_tmo.
4511 .get_fc_host_stats = lpfc_get_stats,
4512 .reset_fc_host_stats = lpfc_reset_stats,
4514 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4515 .show_rport_maxframe_size = 1,
4516 .show_rport_supported_classes = 1,
4518 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4519 .show_rport_dev_loss_tmo = 1,
4521 .get_starget_port_id = lpfc_get_starget_port_id,
4522 .show_starget_port_id = 1,
4524 .get_starget_node_name = lpfc_get_starget_node_name,
4525 .show_starget_node_name = 1,
4527 .get_starget_port_name = lpfc_get_starget_port_name,
4528 .show_starget_port_name = 1,
4530 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4531 .terminate_rport_io = lpfc_terminate_rport_io,
4533 .vport_disable = lpfc_vport_disable,
4535 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4539 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4540 * @phba: lpfc_hba pointer.
4543 lpfc_get_cfgparam(struct lpfc_hba *phba)
4545 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4546 lpfc_cr_count_init(phba, lpfc_cr_count);
4547 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4548 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4549 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4550 lpfc_ack0_init(phba, lpfc_ack0);
4551 lpfc_topology_init(phba, lpfc_topology);
4552 lpfc_link_speed_init(phba, lpfc_link_speed);
4553 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4554 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4555 lpfc_use_msi_init(phba, lpfc_use_msi);
4556 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4557 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4558 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4559 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4560 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4561 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4562 if (phba->sli_rev == LPFC_SLI_REV4)
4565 phba->cfg_poll = lpfc_poll;
4566 phba->cfg_soft_wwnn = 0L;
4567 phba->cfg_soft_wwpn = 0L;
4568 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4569 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4570 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4571 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4572 lpfc_aer_support_init(phba, lpfc_aer_support);
4573 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4574 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
4579 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4580 * @vport: lpfc_vport pointer.
4583 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4585 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4586 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4587 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
4588 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4589 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4590 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4591 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4592 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4593 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4594 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4595 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4596 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4597 lpfc_max_luns_init(vport, lpfc_max_luns);
4598 lpfc_scan_down_init(vport, lpfc_scan_down);
4599 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);