1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
27 #include <linux/aer.h>
28 #include <linux/gfp.h>
29 #include <linux/kernel.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
41 #include "lpfc_sli4.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_version.h"
48 #include "lpfc_compat.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
52 #define LPFC_DEF_DEVLOSS_TMO 30
53 #define LPFC_MIN_DEVLOSS_TMO 1
54 #define LPFC_MAX_DEVLOSS_TMO 255
57 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
58 * @incr: integer to convert.
59 * @hdw: ascii string holding converted integer plus a string terminator.
62 * JEDEC Joint Electron Device Engineering Council.
63 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
64 * character string. The string is then terminated with a NULL in byte 9.
65 * Hex 0-9 becomes ascii '0' to '9'.
66 * Hex a-f becomes ascii '=' to 'B' capital B.
69 * Coded for 32 bit integers only.
72 lpfc_jedec_to_ascii(int incr
, char hdw
[])
75 for (i
= 0; i
< 8; i
++) {
78 hdw
[7 - i
] = 0x30 + j
;
80 hdw
[7 - i
] = 0x61 + j
- 10;
88 * lpfc_drvr_version_show - Return the Emulex driver string with version number
89 * @dev: class unused variable.
90 * @attr: device attribute, not used.
91 * @buf: on return contains the module description text.
93 * Returns: size of formatted string.
96 lpfc_drvr_version_show(struct device
*dev
, struct device_attribute
*attr
,
99 return snprintf(buf
, PAGE_SIZE
, LPFC_MODULE_DESC
"\n");
103 * lpfc_enable_fip_show - Return the fip mode of the HBA
104 * @dev: class unused variable.
105 * @attr: device attribute, not used.
106 * @buf: on return contains the module description text.
108 * Returns: size of formatted string.
111 lpfc_enable_fip_show(struct device
*dev
, struct device_attribute
*attr
,
114 struct Scsi_Host
*shost
= class_to_shost(dev
);
115 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
116 struct lpfc_hba
*phba
= vport
->phba
;
118 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
119 return snprintf(buf
, PAGE_SIZE
, "1\n");
121 return snprintf(buf
, PAGE_SIZE
, "0\n");
125 lpfc_bg_info_show(struct device
*dev
, struct device_attribute
*attr
,
128 struct Scsi_Host
*shost
= class_to_shost(dev
);
129 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
130 struct lpfc_hba
*phba
= vport
->phba
;
132 if (phba
->cfg_enable_bg
)
133 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
134 return snprintf(buf
, PAGE_SIZE
, "BlockGuard Enabled\n");
136 return snprintf(buf
, PAGE_SIZE
,
137 "BlockGuard Not Supported\n");
139 return snprintf(buf
, PAGE_SIZE
,
140 "BlockGuard Disabled\n");
144 lpfc_bg_guard_err_show(struct device
*dev
, struct device_attribute
*attr
,
147 struct Scsi_Host
*shost
= class_to_shost(dev
);
148 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
149 struct lpfc_hba
*phba
= vport
->phba
;
151 return snprintf(buf
, PAGE_SIZE
, "%llu\n",
152 (unsigned long long)phba
->bg_guard_err_cnt
);
156 lpfc_bg_apptag_err_show(struct device
*dev
, struct device_attribute
*attr
,
159 struct Scsi_Host
*shost
= class_to_shost(dev
);
160 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
161 struct lpfc_hba
*phba
= vport
->phba
;
163 return snprintf(buf
, PAGE_SIZE
, "%llu\n",
164 (unsigned long long)phba
->bg_apptag_err_cnt
);
168 lpfc_bg_reftag_err_show(struct device
*dev
, struct device_attribute
*attr
,
171 struct Scsi_Host
*shost
= class_to_shost(dev
);
172 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
173 struct lpfc_hba
*phba
= vport
->phba
;
175 return snprintf(buf
, PAGE_SIZE
, "%llu\n",
176 (unsigned long long)phba
->bg_reftag_err_cnt
);
180 * lpfc_info_show - Return some pci info about the host in ascii
181 * @dev: class converted to a Scsi_host structure.
182 * @attr: device attribute, not used.
183 * @buf: on return contains the formatted text from lpfc_info().
185 * Returns: size of formatted string.
188 lpfc_info_show(struct device
*dev
, struct device_attribute
*attr
,
191 struct Scsi_Host
*host
= class_to_shost(dev
);
193 return snprintf(buf
, PAGE_SIZE
, "%s\n",lpfc_info(host
));
197 * lpfc_serialnum_show - Return the hba serial number in ascii
198 * @dev: class converted to a Scsi_host structure.
199 * @attr: device attribute, not used.
200 * @buf: on return contains the formatted text serial number.
202 * Returns: size of formatted string.
205 lpfc_serialnum_show(struct device
*dev
, struct device_attribute
*attr
,
208 struct Scsi_Host
*shost
= class_to_shost(dev
);
209 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
210 struct lpfc_hba
*phba
= vport
->phba
;
212 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->SerialNumber
);
216 * lpfc_temp_sensor_show - Return the temperature sensor level
217 * @dev: class converted to a Scsi_host structure.
218 * @attr: device attribute, not used.
219 * @buf: on return contains the formatted support level.
222 * Returns a number indicating the temperature sensor level currently
223 * supported, zero or one in ascii.
225 * Returns: size of formatted string.
228 lpfc_temp_sensor_show(struct device
*dev
, struct device_attribute
*attr
,
231 struct Scsi_Host
*shost
= class_to_shost(dev
);
232 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
233 struct lpfc_hba
*phba
= vport
->phba
;
234 return snprintf(buf
, PAGE_SIZE
, "%d\n",phba
->temp_sensor_support
);
238 * lpfc_modeldesc_show - Return the model description of the hba
239 * @dev: class converted to a Scsi_host structure.
240 * @attr: device attribute, not used.
241 * @buf: on return contains the scsi vpd model description.
243 * Returns: size of formatted string.
246 lpfc_modeldesc_show(struct device
*dev
, struct device_attribute
*attr
,
249 struct Scsi_Host
*shost
= class_to_shost(dev
);
250 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
251 struct lpfc_hba
*phba
= vport
->phba
;
253 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelDesc
);
257 * lpfc_modelname_show - Return the model name of the hba
258 * @dev: class converted to a Scsi_host structure.
259 * @attr: device attribute, not used.
260 * @buf: on return contains the scsi vpd model name.
262 * Returns: size of formatted string.
265 lpfc_modelname_show(struct device
*dev
, struct device_attribute
*attr
,
268 struct Scsi_Host
*shost
= class_to_shost(dev
);
269 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
270 struct lpfc_hba
*phba
= vport
->phba
;
272 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelName
);
276 * lpfc_programtype_show - Return the program type of the hba
277 * @dev: class converted to a Scsi_host structure.
278 * @attr: device attribute, not used.
279 * @buf: on return contains the scsi vpd program type.
281 * Returns: size of formatted string.
284 lpfc_programtype_show(struct device
*dev
, struct device_attribute
*attr
,
287 struct Scsi_Host
*shost
= class_to_shost(dev
);
288 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
289 struct lpfc_hba
*phba
= vport
->phba
;
291 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ProgramType
);
295 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
296 * @dev: class converted to a Scsi_host structure.
297 * @attr: device attribute, not used.
298 * @buf: on return contains the Menlo Maintenance sli flag.
300 * Returns: size of formatted string.
303 lpfc_mlomgmt_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
305 struct Scsi_Host
*shost
= class_to_shost(dev
);
306 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
307 struct lpfc_hba
*phba
= vport
->phba
;
309 return snprintf(buf
, PAGE_SIZE
, "%d\n",
310 (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
));
314 * lpfc_vportnum_show - Return the port number in ascii of the hba
315 * @dev: class converted to a Scsi_host structure.
316 * @attr: device attribute, not used.
317 * @buf: on return contains scsi vpd program type.
319 * Returns: size of formatted string.
322 lpfc_vportnum_show(struct device
*dev
, struct device_attribute
*attr
,
325 struct Scsi_Host
*shost
= class_to_shost(dev
);
326 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
327 struct lpfc_hba
*phba
= vport
->phba
;
329 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->Port
);
333 * lpfc_fwrev_show - Return the firmware rev running in the hba
334 * @dev: class converted to a Scsi_host structure.
335 * @attr: device attribute, not used.
336 * @buf: on return contains the scsi vpd program type.
338 * Returns: size of formatted string.
341 lpfc_fwrev_show(struct device
*dev
, struct device_attribute
*attr
,
344 struct Scsi_Host
*shost
= class_to_shost(dev
);
345 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
346 struct lpfc_hba
*phba
= vport
->phba
;
349 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
350 return snprintf(buf
, PAGE_SIZE
, "%s, sli-%d\n", fwrev
, phba
->sli_rev
);
354 * lpfc_hdw_show - Return the jedec information about the hba
355 * @dev: class converted to a Scsi_host structure.
356 * @attr: device attribute, not used.
357 * @buf: on return contains the scsi vpd program type.
359 * Returns: size of formatted string.
362 lpfc_hdw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
365 struct Scsi_Host
*shost
= class_to_shost(dev
);
366 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
367 struct lpfc_hba
*phba
= vport
->phba
;
368 lpfc_vpd_t
*vp
= &phba
->vpd
;
370 lpfc_jedec_to_ascii(vp
->rev
.biuRev
, hdw
);
371 return snprintf(buf
, PAGE_SIZE
, "%s\n", hdw
);
375 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
376 * @dev: class converted to a Scsi_host structure.
377 * @attr: device attribute, not used.
378 * @buf: on return contains the ROM and FCode ascii strings.
380 * Returns: size of formatted string.
383 lpfc_option_rom_version_show(struct device
*dev
, struct device_attribute
*attr
,
386 struct Scsi_Host
*shost
= class_to_shost(dev
);
387 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
388 struct lpfc_hba
*phba
= vport
->phba
;
390 return snprintf(buf
, PAGE_SIZE
, "%s\n", phba
->OptionROMVersion
);
394 * lpfc_state_show - Return the link state of the port
395 * @dev: class converted to a Scsi_host structure.
396 * @attr: device attribute, not used.
397 * @buf: on return contains text describing the state of the link.
400 * The switch statement has no default so zero will be returned.
402 * Returns: size of formatted string.
405 lpfc_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
408 struct Scsi_Host
*shost
= class_to_shost(dev
);
409 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
410 struct lpfc_hba
*phba
= vport
->phba
;
413 switch (phba
->link_state
) {
414 case LPFC_LINK_UNKNOWN
:
415 case LPFC_WARM_START
:
416 case LPFC_INIT_START
:
417 case LPFC_INIT_MBX_CMDS
:
420 if (phba
->hba_flag
& LINK_DISABLED
)
421 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
422 "Link Down - User disabled\n");
424 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
430 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Up - ");
432 switch (vport
->port_state
) {
433 case LPFC_LOCAL_CFG_LINK
:
434 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
435 "Configuring Link\n");
439 case LPFC_FABRIC_CFG_LINK
:
442 case LPFC_BUILD_DISC_LIST
:
444 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
447 case LPFC_VPORT_READY
:
448 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Ready\n");
451 case LPFC_VPORT_FAILED
:
452 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Failed\n");
455 case LPFC_VPORT_UNKNOWN
:
456 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
460 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)
461 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
462 " Menlo Maint Mode\n");
463 else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
464 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
465 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
468 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
471 if (vport
->fc_flag
& FC_FABRIC
)
472 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
475 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
484 * lpfc_link_state_store - Transition the link_state on an HBA port
485 * @dev: class device that is converted into a Scsi_host.
486 * @attr: device attribute, not used.
487 * @buf: one or more lpfc_polling_flags values.
491 * -EINVAL if the buffer is not "up" or "down"
492 * return from link state change function if non-zero
493 * length of the buf on success
496 lpfc_link_state_store(struct device
*dev
, struct device_attribute
*attr
,
497 const char *buf
, size_t count
)
499 struct Scsi_Host
*shost
= class_to_shost(dev
);
500 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
501 struct lpfc_hba
*phba
= vport
->phba
;
503 int status
= -EINVAL
;
505 if ((strncmp(buf
, "up", sizeof("up") - 1) == 0) &&
506 (phba
->link_state
== LPFC_LINK_DOWN
))
507 status
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
508 else if ((strncmp(buf
, "down", sizeof("down") - 1) == 0) &&
509 (phba
->link_state
>= LPFC_LINK_UP
))
510 status
= phba
->lpfc_hba_down_link(phba
, MBX_NOWAIT
);
519 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
520 * @dev: class device that is converted into a Scsi_host.
521 * @attr: device attribute, not used.
522 * @buf: on return contains the sum of fc mapped and unmapped.
525 * Returns the ascii text number of the sum of the fc mapped and unmapped
528 * Returns: size of formatted string.
531 lpfc_num_discovered_ports_show(struct device
*dev
,
532 struct device_attribute
*attr
, char *buf
)
534 struct Scsi_Host
*shost
= class_to_shost(dev
);
535 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
537 return snprintf(buf
, PAGE_SIZE
, "%d\n",
538 vport
->fc_map_cnt
+ vport
->fc_unmap_cnt
);
542 * lpfc_issue_lip - Misnomer, name carried over from long ago
543 * @shost: Scsi_Host pointer.
546 * Bring the link down gracefully then re-init the link. The firmware will
547 * re-init the fiber channel interface as required. Does not issue a LIP.
550 * -EPERM port offline or management commands are being blocked
551 * -ENOMEM cannot allocate memory for the mailbox command
552 * -EIO error sending the mailbox command
556 lpfc_issue_lip(struct Scsi_Host
*shost
)
558 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
559 struct lpfc_hba
*phba
= vport
->phba
;
560 LPFC_MBOXQ_t
*pmboxq
;
561 int mbxstatus
= MBXERR_ERROR
;
563 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
564 (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
))
567 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
572 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
573 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
574 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
576 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
* 2);
578 if ((mbxstatus
== MBX_SUCCESS
) &&
579 (pmboxq
->u
.mb
.mbxStatus
== 0 ||
580 pmboxq
->u
.mb
.mbxStatus
== MBXERR_LINK_DOWN
)) {
581 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
582 lpfc_init_link(phba
, pmboxq
, phba
->cfg_topology
,
583 phba
->cfg_link_speed
);
584 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
586 if ((mbxstatus
== MBX_SUCCESS
) &&
587 (pmboxq
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
588 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
589 "2859 SLI authentication is required "
590 "for INIT_LINK but has not done yet\n");
593 lpfc_set_loopback_flag(phba
);
594 if (mbxstatus
!= MBX_TIMEOUT
)
595 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
597 if (mbxstatus
== MBXERR_ERROR
)
604 * lpfc_do_offline - Issues a mailbox command to bring the link down
605 * @phba: lpfc_hba pointer.
606 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
609 * Assumes any error from lpfc_do_offline() will be negative.
610 * Can wait up to 5 seconds for the port ring buffers count
611 * to reach zero, prints a warning if it is not zero and continues.
612 * lpfc_workq_post_event() returns a non-zero return code if call fails.
615 * -EIO error posting the event
619 lpfc_do_offline(struct lpfc_hba
*phba
, uint32_t type
)
621 struct completion online_compl
;
622 struct lpfc_sli_ring
*pring
;
623 struct lpfc_sli
*psli
;
629 init_completion(&online_compl
);
630 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
631 LPFC_EVT_OFFLINE_PREP
);
635 wait_for_completion(&online_compl
);
642 /* Wait a little for things to settle down, but not
643 * long enough for dev loss timeout to expire.
645 for (i
= 0; i
< psli
->num_rings
; i
++) {
646 pring
= &psli
->ring
[i
];
647 while (pring
->txcmplq_cnt
) {
649 if (cnt
++ > 500) { /* 5 secs */
650 lpfc_printf_log(phba
,
651 KERN_WARNING
, LOG_INIT
,
652 "0466 Outstanding IO when "
653 "bringing Adapter offline\n");
659 init_completion(&online_compl
);
660 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
, type
);
664 wait_for_completion(&online_compl
);
673 * lpfc_selective_reset - Offline then onlines the port
674 * @phba: lpfc_hba pointer.
677 * If the port is configured to allow a reset then the hba is brought
678 * offline then online.
681 * Assumes any error from lpfc_do_offline() will be negative.
682 * Do not make this function static.
685 * lpfc_do_offline() return code if not zero
686 * -EIO reset not configured or error posting the event
690 lpfc_selective_reset(struct lpfc_hba
*phba
)
692 struct completion online_compl
;
696 if (!phba
->cfg_enable_hba_reset
)
699 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
704 init_completion(&online_compl
);
705 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
710 wait_for_completion(&online_compl
);
719 * lpfc_issue_reset - Selectively resets an adapter
720 * @dev: class device that is converted into a Scsi_host.
721 * @attr: device attribute, not used.
722 * @buf: containing the string "selective".
723 * @count: unused variable.
726 * If the buf contains the string "selective" then lpfc_selective_reset()
727 * is called to perform the reset.
730 * Assumes any error from lpfc_selective_reset() will be negative.
731 * If lpfc_selective_reset() returns zero then the length of the buffer
732 * is returned which indicates success
735 * -EINVAL if the buffer does not contain the string "selective"
736 * length of buf if lpfc-selective_reset() if the call succeeds
737 * return value of lpfc_selective_reset() if the call fails
740 lpfc_issue_reset(struct device
*dev
, struct device_attribute
*attr
,
741 const char *buf
, size_t count
)
743 struct Scsi_Host
*shost
= class_to_shost(dev
);
744 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
745 struct lpfc_hba
*phba
= vport
->phba
;
747 int status
= -EINVAL
;
749 if (strncmp(buf
, "selective", sizeof("selective") - 1) == 0)
750 status
= phba
->lpfc_selective_reset(phba
);
759 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
760 * @phba: lpfc_hba pointer.
763 * SLI4 interface type-2 device to wait on the sliport status register for
764 * the readyness after performing a firmware reset.
770 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba
*phba
)
772 struct lpfc_register portstat_reg
;
776 lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
777 &portstat_reg
.word0
);
779 /* wait for the SLI port firmware ready after firmware reset */
780 for (i
= 0; i
< LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT
; i
++) {
782 lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
783 &portstat_reg
.word0
);
784 if (!bf_get(lpfc_sliport_status_err
, &portstat_reg
))
786 if (!bf_get(lpfc_sliport_status_rn
, &portstat_reg
))
788 if (!bf_get(lpfc_sliport_status_rdy
, &portstat_reg
))
793 if (i
< LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT
)
800 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
801 * @phba: lpfc_hba pointer.
804 * Request SLI4 interface type-2 device to perform a physical register set
811 lpfc_sli4_pdev_reg_request(struct lpfc_hba
*phba
, uint32_t opcode
)
813 struct completion online_compl
;
814 struct pci_dev
*pdev
= phba
->pcidev
;
819 if (!phba
->cfg_enable_hba_reset
)
822 if ((phba
->sli_rev
< LPFC_SLI_REV4
) ||
823 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
824 LPFC_SLI_INTF_IF_TYPE_2
))
827 if (!pdev
->is_physfn
)
830 /* Disable SR-IOV virtual functions if enabled */
831 if (phba
->cfg_sriov_nr_virtfn
) {
832 pci_disable_sriov(pdev
);
833 phba
->cfg_sriov_nr_virtfn
= 0;
835 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
840 /* wait for the device to be quiesced before firmware reset */
843 reg_val
= readl(phba
->sli4_hba
.conf_regs_memmap_p
+
844 LPFC_CTL_PDEV_CTL_OFFSET
);
846 if (opcode
== LPFC_FW_DUMP
)
847 reg_val
|= LPFC_FW_DUMP_REQUEST
;
848 else if (opcode
== LPFC_FW_RESET
)
849 reg_val
|= LPFC_CTL_PDEV_CTL_FRST
;
850 else if (opcode
== LPFC_DV_RESET
)
851 reg_val
|= LPFC_CTL_PDEV_CTL_DRST
;
853 writel(reg_val
, phba
->sli4_hba
.conf_regs_memmap_p
+
854 LPFC_CTL_PDEV_CTL_OFFSET
);
856 readl(phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_CTL_PDEV_CTL_OFFSET
);
858 /* delay driver action following IF_TYPE_2 reset */
859 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
864 init_completion(&online_compl
);
865 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
870 wait_for_completion(&online_compl
);
879 * lpfc_nport_evt_cnt_show - Return the number of nport events
880 * @dev: class device that is converted into a Scsi_host.
881 * @attr: device attribute, not used.
882 * @buf: on return contains the ascii number of nport events.
884 * Returns: size of formatted string.
887 lpfc_nport_evt_cnt_show(struct device
*dev
, struct device_attribute
*attr
,
890 struct Scsi_Host
*shost
= class_to_shost(dev
);
891 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
892 struct lpfc_hba
*phba
= vport
->phba
;
894 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->nport_event_cnt
);
898 * lpfc_board_mode_show - Return the state of the board
899 * @dev: class device that is converted into a Scsi_host.
900 * @attr: device attribute, not used.
901 * @buf: on return contains the state of the adapter.
903 * Returns: size of formatted string.
906 lpfc_board_mode_show(struct device
*dev
, struct device_attribute
*attr
,
909 struct Scsi_Host
*shost
= class_to_shost(dev
);
910 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
911 struct lpfc_hba
*phba
= vport
->phba
;
914 if (phba
->link_state
== LPFC_HBA_ERROR
)
916 else if (phba
->link_state
== LPFC_WARM_START
)
917 state
= "warm start";
918 else if (phba
->link_state
== LPFC_INIT_START
)
923 return snprintf(buf
, PAGE_SIZE
, "%s\n", state
);
927 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
928 * @dev: class device that is converted into a Scsi_host.
929 * @attr: device attribute, not used.
930 * @buf: containing one of the strings "online", "offline", "warm" or "error".
931 * @count: unused variable.
934 * -EACCES if enable hba reset not enabled
935 * -EINVAL if the buffer does not contain a valid string (see above)
936 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
937 * buf length greater than zero indicates success
940 lpfc_board_mode_store(struct device
*dev
, struct device_attribute
*attr
,
941 const char *buf
, size_t count
)
943 struct Scsi_Host
*shost
= class_to_shost(dev
);
944 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
945 struct lpfc_hba
*phba
= vport
->phba
;
946 struct completion online_compl
;
950 if (!phba
->cfg_enable_hba_reset
)
953 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
954 "3050 lpfc_board_mode set to %s\n", buf
);
956 init_completion(&online_compl
);
958 if(strncmp(buf
, "online", sizeof("online") - 1) == 0) {
959 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
963 wait_for_completion(&online_compl
);
964 } else if (strncmp(buf
, "offline", sizeof("offline") - 1) == 0)
965 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
966 else if (strncmp(buf
, "warm", sizeof("warm") - 1) == 0)
967 if (phba
->sli_rev
== LPFC_SLI_REV4
)
970 status
= lpfc_do_offline(phba
, LPFC_EVT_WARM_START
);
971 else if (strncmp(buf
, "error", sizeof("error") - 1) == 0)
972 if (phba
->sli_rev
== LPFC_SLI_REV4
)
975 status
= lpfc_do_offline(phba
, LPFC_EVT_KILL
);
976 else if (strncmp(buf
, "dump", sizeof("dump") - 1) == 0)
977 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_FW_DUMP
);
978 else if (strncmp(buf
, "fw_reset", sizeof("fw_reset") - 1) == 0)
979 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_FW_RESET
);
980 else if (strncmp(buf
, "dv_reset", sizeof("dv_reset") - 1) == 0)
981 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_DV_RESET
);
992 * lpfc_get_hba_info - Return various bits of informaton about the adapter
993 * @phba: pointer to the adapter structure.
994 * @mxri: max xri count.
995 * @axri: available xri count.
996 * @mrpi: max rpi count.
997 * @arpi: available rpi count.
998 * @mvpi: max vpi count.
999 * @avpi: available vpi count.
1002 * If an integer pointer for an count is not null then the value for the
1003 * count is returned.
1010 lpfc_get_hba_info(struct lpfc_hba
*phba
,
1011 uint32_t *mxri
, uint32_t *axri
,
1012 uint32_t *mrpi
, uint32_t *arpi
,
1013 uint32_t *mvpi
, uint32_t *avpi
)
1015 struct lpfc_mbx_read_config
*rd_config
;
1016 LPFC_MBOXQ_t
*pmboxq
;
1022 * prevent udev from issuing mailbox commands until the port is
1025 if (phba
->link_state
< LPFC_LINK_DOWN
||
1026 !phba
->mbox_mem_pool
||
1027 (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
) == 0)
1030 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
1033 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1036 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1038 pmb
= &pmboxq
->u
.mb
;
1039 pmb
->mbxCommand
= MBX_READ_CONFIG
;
1040 pmb
->mbxOwner
= OWN_HOST
;
1041 pmboxq
->context1
= NULL
;
1043 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
1044 rc
= MBX_NOT_FINISHED
;
1046 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
1048 if (rc
!= MBX_SUCCESS
) {
1049 if (rc
!= MBX_TIMEOUT
)
1050 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1054 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1055 rd_config
= &pmboxq
->u
.mqe
.un
.rd_config
;
1057 *mrpi
= bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
1059 *arpi
= bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
) -
1060 phba
->sli4_hba
.max_cfg_param
.rpi_used
;
1062 *mxri
= bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
1064 *axri
= bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
) -
1065 phba
->sli4_hba
.max_cfg_param
.xri_used
;
1067 /* Account for differences with SLI-3. Get vpi count from
1068 * mailbox data and subtract one for max vpi value.
1070 max_vpi
= (bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
) > 0) ?
1071 (bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
) - 1) : 0;
1076 *avpi
= max_vpi
- phba
->sli4_hba
.max_cfg_param
.vpi_used
;
1079 *mrpi
= pmb
->un
.varRdConfig
.max_rpi
;
1081 *arpi
= pmb
->un
.varRdConfig
.avail_rpi
;
1083 *mxri
= pmb
->un
.varRdConfig
.max_xri
;
1085 *axri
= pmb
->un
.varRdConfig
.avail_xri
;
1087 *mvpi
= pmb
->un
.varRdConfig
.max_vpi
;
1089 *avpi
= pmb
->un
.varRdConfig
.avail_vpi
;
1092 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1097 * lpfc_max_rpi_show - Return maximum rpi
1098 * @dev: class device that is converted into a Scsi_host.
1099 * @attr: device attribute, not used.
1100 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1103 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1104 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1105 * to "Unknown" and the buffer length is returned, therefore the caller
1106 * must check for "Unknown" in the buffer to detect a failure.
1108 * Returns: size of formatted string.
1111 lpfc_max_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
1114 struct Scsi_Host
*shost
= class_to_shost(dev
);
1115 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1116 struct lpfc_hba
*phba
= vport
->phba
;
1119 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, NULL
, NULL
, NULL
))
1120 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
1121 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1125 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1126 * @dev: class device that is converted into a Scsi_host.
1127 * @attr: device attribute, not used.
1128 * @buf: containing the used rpi count in decimal or "Unknown".
1131 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1132 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1133 * to "Unknown" and the buffer length is returned, therefore the caller
1134 * must check for "Unknown" in the buffer to detect a failure.
1136 * Returns: size of formatted string.
1139 lpfc_used_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
1142 struct Scsi_Host
*shost
= class_to_shost(dev
);
1143 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1144 struct lpfc_hba
*phba
= vport
->phba
;
1147 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, &acnt
, NULL
, NULL
))
1148 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
1149 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1153 * lpfc_max_xri_show - Return maximum xri
1154 * @dev: class device that is converted into a Scsi_host.
1155 * @attr: device attribute, not used.
1156 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1159 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1160 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1161 * to "Unknown" and the buffer length is returned, therefore the caller
1162 * must check for "Unknown" in the buffer to detect a failure.
1164 * Returns: size of formatted string.
1167 lpfc_max_xri_show(struct device
*dev
, struct device_attribute
*attr
,
1170 struct Scsi_Host
*shost
= class_to_shost(dev
);
1171 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1172 struct lpfc_hba
*phba
= vport
->phba
;
1175 if (lpfc_get_hba_info(phba
, &cnt
, NULL
, NULL
, NULL
, NULL
, NULL
))
1176 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
1177 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1181 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1182 * @dev: class device that is converted into a Scsi_host.
1183 * @attr: device attribute, not used.
1184 * @buf: on return contains the used xri count in decimal or "Unknown".
1187 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1188 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1189 * to "Unknown" and the buffer length is returned, therefore the caller
1190 * must check for "Unknown" in the buffer to detect a failure.
1192 * Returns: size of formatted string.
1195 lpfc_used_xri_show(struct device
*dev
, struct device_attribute
*attr
,
1198 struct Scsi_Host
*shost
= class_to_shost(dev
);
1199 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1200 struct lpfc_hba
*phba
= vport
->phba
;
1203 if (lpfc_get_hba_info(phba
, &cnt
, &acnt
, NULL
, NULL
, NULL
, NULL
))
1204 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
1205 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1209 * lpfc_max_vpi_show - Return maximum vpi
1210 * @dev: class device that is converted into a Scsi_host.
1211 * @attr: device attribute, not used.
1212 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1215 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1216 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1217 * to "Unknown" and the buffer length is returned, therefore the caller
1218 * must check for "Unknown" in the buffer to detect a failure.
1220 * Returns: size of formatted string.
1223 lpfc_max_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
1226 struct Scsi_Host
*shost
= class_to_shost(dev
);
1227 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1228 struct lpfc_hba
*phba
= vport
->phba
;
1231 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, NULL
))
1232 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
1233 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1237 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1238 * @dev: class device that is converted into a Scsi_host.
1239 * @attr: device attribute, not used.
1240 * @buf: on return contains the used vpi count in decimal or "Unknown".
1243 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1244 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1245 * to "Unknown" and the buffer length is returned, therefore the caller
1246 * must check for "Unknown" in the buffer to detect a failure.
1248 * Returns: size of formatted string.
1251 lpfc_used_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
1254 struct Scsi_Host
*shost
= class_to_shost(dev
);
1255 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1256 struct lpfc_hba
*phba
= vport
->phba
;
1259 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, &acnt
))
1260 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
1261 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1265 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1266 * @dev: class device that is converted into a Scsi_host.
1267 * @attr: device attribute, not used.
1268 * @buf: text that must be interpreted to determine if npiv is supported.
1271 * Buffer will contain text indicating npiv is not suppoerted on the port,
1272 * the port is an NPIV physical port, or it is an npiv virtual port with
1273 * the id of the vport.
1275 * Returns: size of formatted string.
1278 lpfc_npiv_info_show(struct device
*dev
, struct device_attribute
*attr
,
1281 struct Scsi_Host
*shost
= class_to_shost(dev
);
1282 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1283 struct lpfc_hba
*phba
= vport
->phba
;
1285 if (!(phba
->max_vpi
))
1286 return snprintf(buf
, PAGE_SIZE
, "NPIV Not Supported\n");
1287 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1288 return snprintf(buf
, PAGE_SIZE
, "NPIV Physical\n");
1289 return snprintf(buf
, PAGE_SIZE
, "NPIV Virtual (VPI %d)\n", vport
->vpi
);
1293 * lpfc_poll_show - Return text about poll support for the adapter
1294 * @dev: class device that is converted into a Scsi_host.
1295 * @attr: device attribute, not used.
1296 * @buf: on return contains the cfg_poll in hex.
1299 * cfg_poll should be a lpfc_polling_flags type.
1301 * Returns: size of formatted string.
1304 lpfc_poll_show(struct device
*dev
, struct device_attribute
*attr
,
1307 struct Scsi_Host
*shost
= class_to_shost(dev
);
1308 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1309 struct lpfc_hba
*phba
= vport
->phba
;
1311 return snprintf(buf
, PAGE_SIZE
, "%#x\n", phba
->cfg_poll
);
1315 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1316 * @dev: class device that is converted into a Scsi_host.
1317 * @attr: device attribute, not used.
1318 * @buf: one or more lpfc_polling_flags values.
1322 * buf contents converted to integer and checked for a valid value.
1325 * -EINVAL if the buffer connot be converted or is out of range
1326 * length of the buf on success
1329 lpfc_poll_store(struct device
*dev
, struct device_attribute
*attr
,
1330 const char *buf
, size_t count
)
1332 struct Scsi_Host
*shost
= class_to_shost(dev
);
1333 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1334 struct lpfc_hba
*phba
= vport
->phba
;
1339 if (!isdigit(buf
[0]))
1342 if (sscanf(buf
, "%i", &val
) != 1)
1345 if ((val
& 0x3) != val
)
1348 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1351 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1352 "3051 lpfc_poll changed from %d to %d\n",
1353 phba
->cfg_poll
, val
);
1355 spin_lock_irq(&phba
->hbalock
);
1357 old_val
= phba
->cfg_poll
;
1359 if (val
& ENABLE_FCP_RING_POLLING
) {
1360 if ((val
& DISABLE_FCP_RING_INT
) &&
1361 !(old_val
& DISABLE_FCP_RING_INT
)) {
1362 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1363 spin_unlock_irq(&phba
->hbalock
);
1366 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
1367 writel(creg_val
, phba
->HCregaddr
);
1368 readl(phba
->HCregaddr
); /* flush */
1370 lpfc_poll_start_timer(phba
);
1372 } else if (val
!= 0x0) {
1373 spin_unlock_irq(&phba
->hbalock
);
1377 if (!(val
& DISABLE_FCP_RING_INT
) &&
1378 (old_val
& DISABLE_FCP_RING_INT
))
1380 spin_unlock_irq(&phba
->hbalock
);
1381 del_timer(&phba
->fcp_poll_timer
);
1382 spin_lock_irq(&phba
->hbalock
);
1383 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1384 spin_unlock_irq(&phba
->hbalock
);
1387 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1388 writel(creg_val
, phba
->HCregaddr
);
1389 readl(phba
->HCregaddr
); /* flush */
1392 phba
->cfg_poll
= val
;
1394 spin_unlock_irq(&phba
->hbalock
);
1400 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1401 * @dev: class unused variable.
1402 * @attr: device attribute, not used.
1403 * @buf: on return contains the module description text.
1405 * Returns: size of formatted string.
1408 lpfc_fips_level_show(struct device
*dev
, struct device_attribute
*attr
,
1411 struct Scsi_Host
*shost
= class_to_shost(dev
);
1412 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1413 struct lpfc_hba
*phba
= vport
->phba
;
1415 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->fips_level
);
1419 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1420 * @dev: class unused variable.
1421 * @attr: device attribute, not used.
1422 * @buf: on return contains the module description text.
1424 * Returns: size of formatted string.
1427 lpfc_fips_rev_show(struct device
*dev
, struct device_attribute
*attr
,
1430 struct Scsi_Host
*shost
= class_to_shost(dev
);
1431 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1432 struct lpfc_hba
*phba
= vport
->phba
;
1434 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->fips_spec_rev
);
1438 * lpfc_dss_show - Return the current state of dss and the configured state
1439 * @dev: class converted to a Scsi_host structure.
1440 * @attr: device attribute, not used.
1441 * @buf: on return contains the formatted text.
1443 * Returns: size of formatted string.
1446 lpfc_dss_show(struct device
*dev
, struct device_attribute
*attr
,
1449 struct Scsi_Host
*shost
= class_to_shost(dev
);
1450 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1451 struct lpfc_hba
*phba
= vport
->phba
;
1453 return snprintf(buf
, PAGE_SIZE
, "%s - %sOperational\n",
1454 (phba
->cfg_enable_dss
) ? "Enabled" : "Disabled",
1455 (phba
->sli3_options
& LPFC_SLI3_DSS_ENABLED
) ?
1460 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1461 * @dev: class converted to a Scsi_host structure.
1462 * @attr: device attribute, not used.
1463 * @buf: on return contains the formatted support level.
1466 * Returns the maximum number of virtual functions a physical function can
1467 * support, 0 will be returned if called on virtual function.
1469 * Returns: size of formatted string.
1472 lpfc_sriov_hw_max_virtfn_show(struct device
*dev
,
1473 struct device_attribute
*attr
,
1476 struct Scsi_Host
*shost
= class_to_shost(dev
);
1477 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1478 struct lpfc_hba
*phba
= vport
->phba
;
1479 uint16_t max_nr_virtfn
;
1481 max_nr_virtfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
1482 return snprintf(buf
, PAGE_SIZE
, "%d\n", max_nr_virtfn
);
1486 * lpfc_param_show - Return a cfg attribute value in decimal
1489 * Macro that given an attr e.g. hba_queue_depth expands
1490 * into a function with the name lpfc_hba_queue_depth_show.
1492 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1493 * @dev: class device that is converted into a Scsi_host.
1494 * @attr: device attribute, not used.
1495 * @buf: on return contains the attribute value in decimal.
1497 * Returns: size of formatted string.
1499 #define lpfc_param_show(attr) \
1501 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1504 struct Scsi_Host *shost = class_to_shost(dev);\
1505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1506 struct lpfc_hba *phba = vport->phba;\
1508 val = phba->cfg_##attr;\
1509 return snprintf(buf, PAGE_SIZE, "%d\n",\
1514 * lpfc_param_hex_show - Return a cfg attribute value in hex
1517 * Macro that given an attr e.g. hba_queue_depth expands
1518 * into a function with the name lpfc_hba_queue_depth_show
1520 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1521 * @dev: class device that is converted into a Scsi_host.
1522 * @attr: device attribute, not used.
1523 * @buf: on return contains the attribute value in hexadecimal.
1525 * Returns: size of formatted string.
1527 #define lpfc_param_hex_show(attr) \
1529 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1532 struct Scsi_Host *shost = class_to_shost(dev);\
1533 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1534 struct lpfc_hba *phba = vport->phba;\
1536 val = phba->cfg_##attr;\
1537 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1542 * lpfc_param_init - Initializes a cfg attribute
1545 * Macro that given an attr e.g. hba_queue_depth expands
1546 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1547 * takes a default argument, a minimum and maximum argument.
1549 * lpfc_##attr##_init: Initializes an attribute.
1550 * @phba: pointer the the adapter structure.
1551 * @val: integer attribute value.
1553 * Validates the min and max values then sets the adapter config field
1554 * accordingly, or uses the default if out of range and prints an error message.
1558 * -EINVAL if default used
1560 #define lpfc_param_init(attr, default, minval, maxval) \
1562 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1564 if (val >= minval && val <= maxval) {\
1565 phba->cfg_##attr = val;\
1568 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1569 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1570 "allowed range is ["#minval", "#maxval"]\n", val); \
1571 phba->cfg_##attr = default;\
1576 * lpfc_param_set - Set a cfg attribute value
1579 * Macro that given an attr e.g. hba_queue_depth expands
1580 * into a function with the name lpfc_hba_queue_depth_set
1582 * lpfc_##attr##_set: Sets an attribute value.
1583 * @phba: pointer the the adapter structure.
1584 * @val: integer attribute value.
1587 * Validates the min and max values then sets the
1588 * adapter config field if in the valid range. prints error message
1589 * and does not set the parameter if invalid.
1593 * -EINVAL if val is invalid
1595 #define lpfc_param_set(attr, default, minval, maxval) \
1597 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1599 if (val >= minval && val <= maxval) {\
1600 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1601 "3052 lpfc_" #attr " changed from %d to %d\n", \
1602 phba->cfg_##attr, val); \
1603 phba->cfg_##attr = val;\
1606 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1607 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1608 "allowed range is ["#minval", "#maxval"]\n", val); \
1613 * lpfc_param_store - Set a vport attribute value
1616 * Macro that given an attr e.g. hba_queue_depth expands
1617 * into a function with the name lpfc_hba_queue_depth_store.
1619 * lpfc_##attr##_store: Set an sttribute value.
1620 * @dev: class device that is converted into a Scsi_host.
1621 * @attr: device attribute, not used.
1622 * @buf: contains the attribute value in ascii.
1626 * Convert the ascii text number to an integer, then
1627 * use the lpfc_##attr##_set function to set the value.
1630 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1631 * length of buffer upon success.
1633 #define lpfc_param_store(attr) \
1635 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1636 const char *buf, size_t count) \
1638 struct Scsi_Host *shost = class_to_shost(dev);\
1639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1640 struct lpfc_hba *phba = vport->phba;\
1642 if (!isdigit(buf[0]))\
1644 if (sscanf(buf, "%i", &val) != 1)\
1646 if (lpfc_##attr##_set(phba, val) == 0) \
1647 return strlen(buf);\
1653 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1656 * Macro that given an attr e.g. hba_queue_depth expands
1657 * into a function with the name lpfc_hba_queue_depth_show
1659 * lpfc_##attr##_show: prints the attribute value in decimal.
1660 * @dev: class device that is converted into a Scsi_host.
1661 * @attr: device attribute, not used.
1662 * @buf: on return contains the attribute value in decimal.
1664 * Returns: length of formatted string.
1666 #define lpfc_vport_param_show(attr) \
1668 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1671 struct Scsi_Host *shost = class_to_shost(dev);\
1672 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1674 val = vport->cfg_##attr;\
1675 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1679 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1682 * Macro that given an attr e.g.
1683 * hba_queue_depth expands into a function with the name
1684 * lpfc_hba_queue_depth_show
1686 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1687 * @dev: class device that is converted into a Scsi_host.
1688 * @attr: device attribute, not used.
1689 * @buf: on return contains the attribute value in hexadecimal.
1691 * Returns: length of formatted string.
1693 #define lpfc_vport_param_hex_show(attr) \
1695 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1698 struct Scsi_Host *shost = class_to_shost(dev);\
1699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1701 val = vport->cfg_##attr;\
1702 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1706 * lpfc_vport_param_init - Initialize a vport cfg attribute
1709 * Macro that given an attr e.g. hba_queue_depth expands
1710 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1711 * takes a default argument, a minimum and maximum argument.
1713 * lpfc_##attr##_init: validates the min and max values then sets the
1714 * adapter config field accordingly, or uses the default if out of range
1715 * and prints an error message.
1716 * @phba: pointer the the adapter structure.
1717 * @val: integer attribute value.
1721 * -EINVAL if default used
1723 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1725 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1727 if (val >= minval && val <= maxval) {\
1728 vport->cfg_##attr = val;\
1731 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1732 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1733 "allowed range is ["#minval", "#maxval"]\n", val); \
1734 vport->cfg_##attr = default;\
1739 * lpfc_vport_param_set - Set a vport cfg attribute
1742 * Macro that given an attr e.g. hba_queue_depth expands
1743 * into a function with the name lpfc_hba_queue_depth_set
1745 * lpfc_##attr##_set: validates the min and max values then sets the
1746 * adapter config field if in the valid range. prints error message
1747 * and does not set the parameter if invalid.
1748 * @phba: pointer the the adapter structure.
1749 * @val: integer attribute value.
1753 * -EINVAL if val is invalid
1755 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1757 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1759 if (val >= minval && val <= maxval) {\
1760 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1761 "3053 lpfc_" #attr " changed from %d to %d\n", \
1762 vport->cfg_##attr, val); \
1763 vport->cfg_##attr = val;\
1766 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1767 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1768 "allowed range is ["#minval", "#maxval"]\n", val); \
1773 * lpfc_vport_param_store - Set a vport attribute
1776 * Macro that given an attr e.g. hba_queue_depth
1777 * expands into a function with the name lpfc_hba_queue_depth_store
1779 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1780 * use the lpfc_##attr##_set function to set the value.
1781 * @cdev: class device that is converted into a Scsi_host.
1782 * @buf: contains the attribute value in decimal.
1786 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1787 * length of buffer upon success.
1789 #define lpfc_vport_param_store(attr) \
1791 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1792 const char *buf, size_t count) \
1794 struct Scsi_Host *shost = class_to_shost(dev);\
1795 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1797 if (!isdigit(buf[0]))\
1799 if (sscanf(buf, "%i", &val) != 1)\
1801 if (lpfc_##attr##_set(vport, val) == 0) \
1802 return strlen(buf);\
1808 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1809 static uint lpfc_##name = defval;\
1810 module_param(lpfc_##name, uint, S_IRUGO);\
1811 MODULE_PARM_DESC(lpfc_##name, desc);\
1812 lpfc_param_init(name, defval, minval, maxval)
1814 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1815 static uint lpfc_##name = defval;\
1816 module_param(lpfc_##name, uint, S_IRUGO);\
1817 MODULE_PARM_DESC(lpfc_##name, desc);\
1818 lpfc_param_show(name)\
1819 lpfc_param_init(name, defval, minval, maxval)\
1820 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1822 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1823 static uint lpfc_##name = defval;\
1824 module_param(lpfc_##name, uint, S_IRUGO);\
1825 MODULE_PARM_DESC(lpfc_##name, desc);\
1826 lpfc_param_show(name)\
1827 lpfc_param_init(name, defval, minval, maxval)\
1828 lpfc_param_set(name, defval, minval, maxval)\
1829 lpfc_param_store(name)\
1830 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1831 lpfc_##name##_show, lpfc_##name##_store)
1833 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1834 static uint lpfc_##name = defval;\
1835 module_param(lpfc_##name, uint, S_IRUGO);\
1836 MODULE_PARM_DESC(lpfc_##name, desc);\
1837 lpfc_param_hex_show(name)\
1838 lpfc_param_init(name, defval, minval, maxval)\
1839 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1841 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1842 static uint lpfc_##name = defval;\
1843 module_param(lpfc_##name, uint, S_IRUGO);\
1844 MODULE_PARM_DESC(lpfc_##name, desc);\
1845 lpfc_param_hex_show(name)\
1846 lpfc_param_init(name, defval, minval, maxval)\
1847 lpfc_param_set(name, defval, minval, maxval)\
1848 lpfc_param_store(name)\
1849 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1850 lpfc_##name##_show, lpfc_##name##_store)
1852 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1853 static uint lpfc_##name = defval;\
1854 module_param(lpfc_##name, uint, S_IRUGO);\
1855 MODULE_PARM_DESC(lpfc_##name, desc);\
1856 lpfc_vport_param_init(name, defval, minval, maxval)
1858 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1859 static uint lpfc_##name = defval;\
1860 module_param(lpfc_##name, uint, S_IRUGO);\
1861 MODULE_PARM_DESC(lpfc_##name, desc);\
1862 lpfc_vport_param_show(name)\
1863 lpfc_vport_param_init(name, defval, minval, maxval)\
1864 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1866 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1867 static uint lpfc_##name = defval;\
1868 module_param(lpfc_##name, uint, S_IRUGO);\
1869 MODULE_PARM_DESC(lpfc_##name, desc);\
1870 lpfc_vport_param_show(name)\
1871 lpfc_vport_param_init(name, defval, minval, maxval)\
1872 lpfc_vport_param_set(name, defval, minval, maxval)\
1873 lpfc_vport_param_store(name)\
1874 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1875 lpfc_##name##_show, lpfc_##name##_store)
1877 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1878 static uint lpfc_##name = defval;\
1879 module_param(lpfc_##name, uint, S_IRUGO);\
1880 MODULE_PARM_DESC(lpfc_##name, desc);\
1881 lpfc_vport_param_hex_show(name)\
1882 lpfc_vport_param_init(name, defval, minval, maxval)\
1883 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1885 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1886 static uint lpfc_##name = defval;\
1887 module_param(lpfc_##name, uint, S_IRUGO);\
1888 MODULE_PARM_DESC(lpfc_##name, desc);\
1889 lpfc_vport_param_hex_show(name)\
1890 lpfc_vport_param_init(name, defval, minval, maxval)\
1891 lpfc_vport_param_set(name, defval, minval, maxval)\
1892 lpfc_vport_param_store(name)\
1893 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1894 lpfc_##name##_show, lpfc_##name##_store)
1896 static DEVICE_ATTR(bg_info
, S_IRUGO
, lpfc_bg_info_show
, NULL
);
1897 static DEVICE_ATTR(bg_guard_err
, S_IRUGO
, lpfc_bg_guard_err_show
, NULL
);
1898 static DEVICE_ATTR(bg_apptag_err
, S_IRUGO
, lpfc_bg_apptag_err_show
, NULL
);
1899 static DEVICE_ATTR(bg_reftag_err
, S_IRUGO
, lpfc_bg_reftag_err_show
, NULL
);
1900 static DEVICE_ATTR(info
, S_IRUGO
, lpfc_info_show
, NULL
);
1901 static DEVICE_ATTR(serialnum
, S_IRUGO
, lpfc_serialnum_show
, NULL
);
1902 static DEVICE_ATTR(modeldesc
, S_IRUGO
, lpfc_modeldesc_show
, NULL
);
1903 static DEVICE_ATTR(modelname
, S_IRUGO
, lpfc_modelname_show
, NULL
);
1904 static DEVICE_ATTR(programtype
, S_IRUGO
, lpfc_programtype_show
, NULL
);
1905 static DEVICE_ATTR(portnum
, S_IRUGO
, lpfc_vportnum_show
, NULL
);
1906 static DEVICE_ATTR(fwrev
, S_IRUGO
, lpfc_fwrev_show
, NULL
);
1907 static DEVICE_ATTR(hdw
, S_IRUGO
, lpfc_hdw_show
, NULL
);
1908 static DEVICE_ATTR(link_state
, S_IRUGO
| S_IWUSR
, lpfc_link_state_show
,
1909 lpfc_link_state_store
);
1910 static DEVICE_ATTR(option_rom_version
, S_IRUGO
,
1911 lpfc_option_rom_version_show
, NULL
);
1912 static DEVICE_ATTR(num_discovered_ports
, S_IRUGO
,
1913 lpfc_num_discovered_ports_show
, NULL
);
1914 static DEVICE_ATTR(menlo_mgmt_mode
, S_IRUGO
, lpfc_mlomgmt_show
, NULL
);
1915 static DEVICE_ATTR(nport_evt_cnt
, S_IRUGO
, lpfc_nport_evt_cnt_show
, NULL
);
1916 static DEVICE_ATTR(lpfc_drvr_version
, S_IRUGO
, lpfc_drvr_version_show
, NULL
);
1917 static DEVICE_ATTR(lpfc_enable_fip
, S_IRUGO
, lpfc_enable_fip_show
, NULL
);
1918 static DEVICE_ATTR(board_mode
, S_IRUGO
| S_IWUSR
,
1919 lpfc_board_mode_show
, lpfc_board_mode_store
);
1920 static DEVICE_ATTR(issue_reset
, S_IWUSR
, NULL
, lpfc_issue_reset
);
1921 static DEVICE_ATTR(max_vpi
, S_IRUGO
, lpfc_max_vpi_show
, NULL
);
1922 static DEVICE_ATTR(used_vpi
, S_IRUGO
, lpfc_used_vpi_show
, NULL
);
1923 static DEVICE_ATTR(max_rpi
, S_IRUGO
, lpfc_max_rpi_show
, NULL
);
1924 static DEVICE_ATTR(used_rpi
, S_IRUGO
, lpfc_used_rpi_show
, NULL
);
1925 static DEVICE_ATTR(max_xri
, S_IRUGO
, lpfc_max_xri_show
, NULL
);
1926 static DEVICE_ATTR(used_xri
, S_IRUGO
, lpfc_used_xri_show
, NULL
);
1927 static DEVICE_ATTR(npiv_info
, S_IRUGO
, lpfc_npiv_info_show
, NULL
);
1928 static DEVICE_ATTR(lpfc_temp_sensor
, S_IRUGO
, lpfc_temp_sensor_show
, NULL
);
1929 static DEVICE_ATTR(lpfc_fips_level
, S_IRUGO
, lpfc_fips_level_show
, NULL
);
1930 static DEVICE_ATTR(lpfc_fips_rev
, S_IRUGO
, lpfc_fips_rev_show
, NULL
);
1931 static DEVICE_ATTR(lpfc_dss
, S_IRUGO
, lpfc_dss_show
, NULL
);
1932 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn
, S_IRUGO
,
1933 lpfc_sriov_hw_max_virtfn_show
, NULL
);
1935 static char *lpfc_soft_wwn_key
= "C99G71SL8032A";
1938 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1939 * @dev: class device that is converted into a Scsi_host.
1940 * @attr: device attribute, not used.
1941 * @buf: containing the string lpfc_soft_wwn_key.
1942 * @count: must be size of lpfc_soft_wwn_key.
1945 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1946 * length of buf indicates success
1949 lpfc_soft_wwn_enable_store(struct device
*dev
, struct device_attribute
*attr
,
1950 const char *buf
, size_t count
)
1952 struct Scsi_Host
*shost
= class_to_shost(dev
);
1953 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1954 struct lpfc_hba
*phba
= vport
->phba
;
1955 unsigned int cnt
= count
;
1958 * We're doing a simple sanity check for soft_wwpn setting.
1959 * We require that the user write a specific key to enable
1960 * the soft_wwpn attribute to be settable. Once the attribute
1961 * is written, the enable key resets. If further updates are
1962 * desired, the key must be written again to re-enable the
1965 * The "key" is not secret - it is a hardcoded string shown
1966 * here. The intent is to protect against the random user or
1967 * application that is just writing attributes.
1970 /* count may include a LF at end of string */
1971 if (buf
[cnt
-1] == '\n')
1974 if ((cnt
!= strlen(lpfc_soft_wwn_key
)) ||
1975 (strncmp(buf
, lpfc_soft_wwn_key
, strlen(lpfc_soft_wwn_key
)) != 0))
1978 phba
->soft_wwn_enable
= 1;
1981 static DEVICE_ATTR(lpfc_soft_wwn_enable
, S_IWUSR
, NULL
,
1982 lpfc_soft_wwn_enable_store
);
1985 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1986 * @dev: class device that is converted into a Scsi_host.
1987 * @attr: device attribute, not used.
1988 * @buf: on return contains the wwpn in hexadecimal.
1990 * Returns: size of formatted string.
1993 lpfc_soft_wwpn_show(struct device
*dev
, struct device_attribute
*attr
,
1996 struct Scsi_Host
*shost
= class_to_shost(dev
);
1997 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1998 struct lpfc_hba
*phba
= vport
->phba
;
2000 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
2001 (unsigned long long)phba
->cfg_soft_wwpn
);
2005 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2006 * @dev class device that is converted into a Scsi_host.
2007 * @attr: device attribute, not used.
2008 * @buf: contains the wwpn in hexadecimal.
2009 * @count: number of wwpn bytes in buf
2012 * -EACCES hba reset not enabled, adapter over temp
2013 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2014 * -EIO error taking adapter offline or online
2015 * value of count on success
2018 lpfc_soft_wwpn_store(struct device
*dev
, struct device_attribute
*attr
,
2019 const char *buf
, size_t count
)
2021 struct Scsi_Host
*shost
= class_to_shost(dev
);
2022 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2023 struct lpfc_hba
*phba
= vport
->phba
;
2024 struct completion online_compl
;
2025 int stat1
=0, stat2
=0;
2026 unsigned int i
, j
, cnt
=count
;
2030 if (!phba
->cfg_enable_hba_reset
)
2032 spin_lock_irq(&phba
->hbalock
);
2033 if (phba
->over_temp_state
== HBA_OVER_TEMP
) {
2034 spin_unlock_irq(&phba
->hbalock
);
2037 spin_unlock_irq(&phba
->hbalock
);
2038 /* count may include a LF at end of string */
2039 if (buf
[cnt
-1] == '\n')
2042 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
2043 ((cnt
== 17) && (*buf
++ != 'x')) ||
2044 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
2047 phba
->soft_wwn_enable
= 0;
2049 memset(wwpn
, 0, sizeof(wwpn
));
2051 /* Validate and store the new name */
2052 for (i
=0, j
=0; i
< 16; i
++) {
2055 value
= hex_to_bin(*buf
++);
2057 j
= (j
<< 4) | value
;
2061 wwpn
[i
/2] = j
& 0xff;
2065 phba
->cfg_soft_wwpn
= wwn_to_u64(wwpn
);
2066 fc_host_port_name(shost
) = phba
->cfg_soft_wwpn
;
2067 if (phba
->cfg_soft_wwnn
)
2068 fc_host_node_name(shost
) = phba
->cfg_soft_wwnn
;
2070 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
2071 "lpfc%d: Reinitializing to use soft_wwpn\n", phba
->brd_no
);
2073 stat1
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
2075 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2076 "0463 lpfc_soft_wwpn attribute set failed to "
2077 "reinit adapter - %d\n", stat1
);
2078 init_completion(&online_compl
);
2079 rc
= lpfc_workq_post_event(phba
, &stat2
, &online_compl
,
2084 wait_for_completion(&online_compl
);
2086 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2087 "0464 lpfc_soft_wwpn attribute set failed to "
2088 "reinit adapter - %d\n", stat2
);
2089 return (stat1
|| stat2
) ? -EIO
: count
;
2091 static DEVICE_ATTR(lpfc_soft_wwpn
, S_IRUGO
| S_IWUSR
,\
2092 lpfc_soft_wwpn_show
, lpfc_soft_wwpn_store
);
2095 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2096 * @dev: class device that is converted into a Scsi_host.
2097 * @attr: device attribute, not used.
2098 * @buf: on return contains the wwnn in hexadecimal.
2100 * Returns: size of formatted string.
2103 lpfc_soft_wwnn_show(struct device
*dev
, struct device_attribute
*attr
,
2106 struct Scsi_Host
*shost
= class_to_shost(dev
);
2107 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2108 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
2109 (unsigned long long)phba
->cfg_soft_wwnn
);
2113 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2114 * @cdev: class device that is converted into a Scsi_host.
2115 * @buf: contains the ww node name in hexadecimal.
2116 * @count: number of wwnn bytes in buf.
2119 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2120 * value of count on success
2123 lpfc_soft_wwnn_store(struct device
*dev
, struct device_attribute
*attr
,
2124 const char *buf
, size_t count
)
2126 struct Scsi_Host
*shost
= class_to_shost(dev
);
2127 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2128 unsigned int i
, j
, cnt
=count
;
2131 /* count may include a LF at end of string */
2132 if (buf
[cnt
-1] == '\n')
2135 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
2136 ((cnt
== 17) && (*buf
++ != 'x')) ||
2137 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
2141 * Allow wwnn to be set many times, as long as the enable is set.
2142 * However, once the wwpn is set, everything locks.
2145 memset(wwnn
, 0, sizeof(wwnn
));
2147 /* Validate and store the new name */
2148 for (i
=0, j
=0; i
< 16; i
++) {
2151 value
= hex_to_bin(*buf
++);
2153 j
= (j
<< 4) | value
;
2157 wwnn
[i
/2] = j
& 0xff;
2161 phba
->cfg_soft_wwnn
= wwn_to_u64(wwnn
);
2163 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
2164 "lpfc%d: soft_wwnn set. Value will take effect upon "
2165 "setting of the soft_wwpn\n", phba
->brd_no
);
2169 static DEVICE_ATTR(lpfc_soft_wwnn
, S_IRUGO
| S_IWUSR
,\
2170 lpfc_soft_wwnn_show
, lpfc_soft_wwnn_store
);
2173 static int lpfc_poll
= 0;
2174 module_param(lpfc_poll
, int, S_IRUGO
);
2175 MODULE_PARM_DESC(lpfc_poll
, "FCP ring polling mode control:"
2177 " 1 - poll with interrupts enabled"
2178 " 3 - poll and disable FCP ring interrupts");
2180 static DEVICE_ATTR(lpfc_poll
, S_IRUGO
| S_IWUSR
,
2181 lpfc_poll_show
, lpfc_poll_store
);
2183 int lpfc_sli_mode
= 0;
2184 module_param(lpfc_sli_mode
, int, S_IRUGO
);
2185 MODULE_PARM_DESC(lpfc_sli_mode
, "SLI mode selector:"
2186 " 0 - auto (SLI-3 if supported),"
2187 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2188 " 3 - select SLI-3");
2190 int lpfc_enable_npiv
= 1;
2191 module_param(lpfc_enable_npiv
, int, S_IRUGO
);
2192 MODULE_PARM_DESC(lpfc_enable_npiv
, "Enable NPIV functionality");
2193 lpfc_param_show(enable_npiv
);
2194 lpfc_param_init(enable_npiv
, 1, 0, 1);
2195 static DEVICE_ATTR(lpfc_enable_npiv
, S_IRUGO
, lpfc_enable_npiv_show
, NULL
);
2197 LPFC_ATTR_R(fcf_failover_policy
, 1, 1, 2,
2198 "FCF Fast failover=1 Priority failover=2");
2200 int lpfc_enable_rrq
;
2201 module_param(lpfc_enable_rrq
, int, S_IRUGO
);
2202 MODULE_PARM_DESC(lpfc_enable_rrq
, "Enable RRQ functionality");
2203 lpfc_param_show(enable_rrq
);
2204 lpfc_param_init(enable_rrq
, 0, 0, 1);
2205 static DEVICE_ATTR(lpfc_enable_rrq
, S_IRUGO
, lpfc_enable_rrq_show
, NULL
);
2208 # lpfc_suppress_link_up: Bring link up at initialization
2209 # 0x0 = bring link up (issue MBX_INIT_LINK)
2210 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2211 # 0x2 = never bring up link
2212 # Default value is 0.
2214 LPFC_ATTR_R(suppress_link_up
, LPFC_INITIALIZE_LINK
, LPFC_INITIALIZE_LINK
,
2215 LPFC_DELAY_INIT_LINK_INDEFINITELY
,
2216 "Suppress Link Up at initialization");
2218 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2226 lpfc_iocb_hw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2228 struct Scsi_Host
*shost
= class_to_shost(dev
);
2229 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
2231 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->iocb_max
);
2234 static DEVICE_ATTR(iocb_hw
, S_IRUGO
,
2235 lpfc_iocb_hw_show
, NULL
);
2237 lpfc_txq_hw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2239 struct Scsi_Host
*shost
= class_to_shost(dev
);
2240 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
2242 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2243 phba
->sli
.ring
[LPFC_ELS_RING
].txq_max
);
2246 static DEVICE_ATTR(txq_hw
, S_IRUGO
,
2247 lpfc_txq_hw_show
, NULL
);
2249 lpfc_txcmplq_hw_show(struct device
*dev
, struct device_attribute
*attr
,
2252 struct Scsi_Host
*shost
= class_to_shost(dev
);
2253 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
2255 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2256 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_max
);
2259 static DEVICE_ATTR(txcmplq_hw
, S_IRUGO
,
2260 lpfc_txcmplq_hw_show
, NULL
);
2262 int lpfc_iocb_cnt
= 2;
2263 module_param(lpfc_iocb_cnt
, int, S_IRUGO
);
2264 MODULE_PARM_DESC(lpfc_iocb_cnt
,
2265 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2266 lpfc_param_show(iocb_cnt
);
2267 lpfc_param_init(iocb_cnt
, 2, 1, 5);
2268 static DEVICE_ATTR(lpfc_iocb_cnt
, S_IRUGO
,
2269 lpfc_iocb_cnt_show
, NULL
);
2272 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2273 # until the timer expires. Value range is [0,255]. Default value is 30.
2275 static int lpfc_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
2276 static int lpfc_devloss_tmo
= LPFC_DEF_DEVLOSS_TMO
;
2277 module_param(lpfc_nodev_tmo
, int, 0);
2278 MODULE_PARM_DESC(lpfc_nodev_tmo
,
2279 "Seconds driver will hold I/O waiting "
2280 "for a device to come back");
2283 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2284 * @dev: class converted to a Scsi_host structure.
2285 * @attr: device attribute, not used.
2286 * @buf: on return contains the dev loss timeout in decimal.
2288 * Returns: size of formatted string.
2291 lpfc_nodev_tmo_show(struct device
*dev
, struct device_attribute
*attr
,
2294 struct Scsi_Host
*shost
= class_to_shost(dev
);
2295 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2297 return snprintf(buf
, PAGE_SIZE
, "%d\n", vport
->cfg_devloss_tmo
);
2301 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2302 * @vport: lpfc vport structure pointer.
2303 * @val: contains the nodev timeout value.
2306 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2307 * a kernel error message is printed and zero is returned.
2308 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2309 * Otherwise nodev tmo is set to the default value.
2312 * zero if already set or if val is in range
2313 * -EINVAL val out of range
2316 lpfc_nodev_tmo_init(struct lpfc_vport
*vport
, int val
)
2318 if (vport
->cfg_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
) {
2319 vport
->cfg_nodev_tmo
= vport
->cfg_devloss_tmo
;
2320 if (val
!= LPFC_DEF_DEVLOSS_TMO
)
2321 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2322 "0407 Ignoring nodev_tmo module "
2323 "parameter because devloss_tmo is "
2328 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
2329 vport
->cfg_nodev_tmo
= val
;
2330 vport
->cfg_devloss_tmo
= val
;
2333 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2334 "0400 lpfc_nodev_tmo attribute cannot be set to"
2335 " %d, allowed range is [%d, %d]\n",
2336 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
2337 vport
->cfg_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
2342 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2343 * @vport: lpfc vport structure pointer.
2346 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2349 lpfc_update_rport_devloss_tmo(struct lpfc_vport
*vport
)
2351 struct Scsi_Host
*shost
;
2352 struct lpfc_nodelist
*ndlp
;
2354 shost
= lpfc_shost_from_vport(vport
);
2355 spin_lock_irq(shost
->host_lock
);
2356 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
)
2357 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
)
2358 ndlp
->rport
->dev_loss_tmo
= vport
->cfg_devloss_tmo
;
2359 spin_unlock_irq(shost
->host_lock
);
2363 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2364 * @vport: lpfc vport structure pointer.
2365 * @val: contains the tmo value.
2368 * If the devloss tmo is already set or the vport dev loss tmo has changed
2369 * then a kernel error message is printed and zero is returned.
2370 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2371 * Otherwise nodev tmo is set to the default value.
2374 * zero if already set or if val is in range
2375 * -EINVAL val out of range
2378 lpfc_nodev_tmo_set(struct lpfc_vport
*vport
, int val
)
2380 if (vport
->dev_loss_tmo_changed
||
2381 (lpfc_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
)) {
2382 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2383 "0401 Ignoring change to nodev_tmo "
2384 "because devloss_tmo is set.\n");
2387 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
2388 vport
->cfg_nodev_tmo
= val
;
2389 vport
->cfg_devloss_tmo
= val
;
2391 * For compat: set the fc_host dev loss so new rports
2392 * will get the value.
2394 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport
)) = val
;
2395 lpfc_update_rport_devloss_tmo(vport
);
2398 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2399 "0403 lpfc_nodev_tmo attribute cannot be set to"
2400 "%d, allowed range is [%d, %d]\n",
2401 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
2405 lpfc_vport_param_store(nodev_tmo
)
2407 static DEVICE_ATTR(lpfc_nodev_tmo
, S_IRUGO
| S_IWUSR
,
2408 lpfc_nodev_tmo_show
, lpfc_nodev_tmo_store
);
2411 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2412 # disappear until the timer expires. Value range is [0,255]. Default
2415 module_param(lpfc_devloss_tmo
, int, S_IRUGO
);
2416 MODULE_PARM_DESC(lpfc_devloss_tmo
,
2417 "Seconds driver will hold I/O waiting "
2418 "for a device to come back");
2419 lpfc_vport_param_init(devloss_tmo
, LPFC_DEF_DEVLOSS_TMO
,
2420 LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
)
2421 lpfc_vport_param_show(devloss_tmo
)
2424 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2425 * @vport: lpfc vport structure pointer.
2426 * @val: contains the tmo value.
2429 * If val is in a valid range then set the vport nodev tmo,
2430 * devloss tmo, also set the vport dev loss tmo changed flag.
2431 * Else a kernel error message is printed.
2434 * zero if val is in range
2435 * -EINVAL val out of range
2438 lpfc_devloss_tmo_set(struct lpfc_vport
*vport
, int val
)
2440 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
2441 vport
->cfg_nodev_tmo
= val
;
2442 vport
->cfg_devloss_tmo
= val
;
2443 vport
->dev_loss_tmo_changed
= 1;
2444 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport
)) = val
;
2445 lpfc_update_rport_devloss_tmo(vport
);
2449 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2450 "0404 lpfc_devloss_tmo attribute cannot be set to"
2451 " %d, allowed range is [%d, %d]\n",
2452 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
2456 lpfc_vport_param_store(devloss_tmo
)
2457 static DEVICE_ATTR(lpfc_devloss_tmo
, S_IRUGO
| S_IWUSR
,
2458 lpfc_devloss_tmo_show
, lpfc_devloss_tmo_store
);
2461 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2462 # deluged with LOTS of information.
2463 # You can set a bit mask to record specific types of verbose messages:
2464 # See lpfc_logmsh.h for definitions.
2466 LPFC_VPORT_ATTR_HEX_RW(log_verbose
, 0x0, 0x0, 0xffffffff,
2467 "Verbose logging bit-mask");
2470 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2471 # objects that have been registered with the nameserver after login.
2473 LPFC_VPORT_ATTR_R(enable_da_id
, 0, 0, 1,
2474 "Deregister nameserver objects before LOGO");
2477 # lun_queue_depth: This parameter is used to limit the number of outstanding
2478 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2480 LPFC_VPORT_ATTR_R(lun_queue_depth
, 30, 1, 128,
2481 "Max number of FCP commands we can queue to a specific LUN");
2484 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2485 # commands per target port. Value range is [10,65535]. Default value is 65535.
2487 LPFC_VPORT_ATTR_R(tgt_queue_depth
, 65535, 10, 65535,
2488 "Max number of FCP commands we can queue to a specific target port");
2491 # hba_queue_depth: This parameter is used to limit the number of outstanding
2492 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2493 # value is greater than the maximum number of exchanges supported by the HBA,
2494 # then maximum number of exchanges supported by the HBA is used to determine
2495 # the hba_queue_depth.
2497 LPFC_ATTR_R(hba_queue_depth
, 8192, 32, 8192,
2498 "Max number of FCP commands we can queue to a lpfc HBA");
2501 # peer_port_login: This parameter allows/prevents logins
2502 # between peer ports hosted on the same physical port.
2503 # When this parameter is set 0 peer ports of same physical port
2504 # are not allowed to login to each other.
2505 # When this parameter is set 1 peer ports of same physical port
2506 # are allowed to login to each other.
2507 # Default value of this parameter is 0.
2509 LPFC_VPORT_ATTR_R(peer_port_login
, 0, 0, 1,
2510 "Allow peer ports on the same physical port to login to each "
2514 # restrict_login: This parameter allows/prevents logins
2515 # between Virtual Ports and remote initiators.
2516 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2517 # other initiators and will attempt to PLOGI all remote ports.
2518 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2519 # remote ports and will not attempt to PLOGI to other initiators.
2520 # This parameter does not restrict to the physical port.
2521 # This parameter does not restrict logins to Fabric resident remote ports.
2522 # Default value of this parameter is 1.
2524 static int lpfc_restrict_login
= 1;
2525 module_param(lpfc_restrict_login
, int, S_IRUGO
);
2526 MODULE_PARM_DESC(lpfc_restrict_login
,
2527 "Restrict virtual ports login to remote initiators.");
2528 lpfc_vport_param_show(restrict_login
);
2531 * lpfc_restrict_login_init - Set the vport restrict login flag
2532 * @vport: lpfc vport structure pointer.
2533 * @val: contains the restrict login value.
2536 * If val is not in a valid range then log a kernel error message and set
2537 * the vport restrict login to one.
2538 * If the port type is physical clear the restrict login flag and return.
2539 * Else set the restrict login flag to val.
2542 * zero if val is in range
2543 * -EINVAL val out of range
2546 lpfc_restrict_login_init(struct lpfc_vport
*vport
, int val
)
2548 if (val
< 0 || val
> 1) {
2549 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2550 "0422 lpfc_restrict_login attribute cannot "
2551 "be set to %d, allowed range is [0, 1]\n",
2553 vport
->cfg_restrict_login
= 1;
2556 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
2557 vport
->cfg_restrict_login
= 0;
2560 vport
->cfg_restrict_login
= val
;
2565 * lpfc_restrict_login_set - Set the vport restrict login flag
2566 * @vport: lpfc vport structure pointer.
2567 * @val: contains the restrict login value.
2570 * If val is not in a valid range then log a kernel error message and set
2571 * the vport restrict login to one.
2572 * If the port type is physical and the val is not zero log a kernel
2573 * error message, clear the restrict login flag and return zero.
2574 * Else set the restrict login flag to val.
2577 * zero if val is in range
2578 * -EINVAL val out of range
2581 lpfc_restrict_login_set(struct lpfc_vport
*vport
, int val
)
2583 if (val
< 0 || val
> 1) {
2584 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2585 "0425 lpfc_restrict_login attribute cannot "
2586 "be set to %d, allowed range is [0, 1]\n",
2588 vport
->cfg_restrict_login
= 1;
2591 if (vport
->port_type
== LPFC_PHYSICAL_PORT
&& val
!= 0) {
2592 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2593 "0468 lpfc_restrict_login must be 0 for "
2594 "Physical ports.\n");
2595 vport
->cfg_restrict_login
= 0;
2598 vport
->cfg_restrict_login
= val
;
2601 lpfc_vport_param_store(restrict_login
);
2602 static DEVICE_ATTR(lpfc_restrict_login
, S_IRUGO
| S_IWUSR
,
2603 lpfc_restrict_login_show
, lpfc_restrict_login_store
);
2606 # Some disk devices have a "select ID" or "select Target" capability.
2607 # From a protocol standpoint "select ID" usually means select the
2608 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2609 # annex" which contains a table that maps a "select ID" (a number
2610 # between 0 and 7F) to an ALPA. By default, for compatibility with
2611 # older drivers, the lpfc driver scans this table from low ALPA to high
2614 # Turning on the scan-down variable (on = 1, off = 0) will
2615 # cause the lpfc driver to use an inverted table, effectively
2616 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2618 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2619 # and will not work across a fabric. Also this parameter will take
2620 # effect only in the case when ALPA map is not available.)
2622 LPFC_VPORT_ATTR_R(scan_down
, 1, 0, 1,
2623 "Start scanning for devices from highest ALPA to lowest");
2626 # lpfc_topology: link topology for init link
2627 # 0x0 = attempt loop mode then point-to-point
2628 # 0x01 = internal loopback mode
2629 # 0x02 = attempt point-to-point mode only
2630 # 0x04 = attempt loop mode only
2631 # 0x06 = attempt point-to-point mode then loop
2632 # Set point-to-point mode if you want to run as an N_Port.
2633 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2634 # Default value is 0.
2638 * lpfc_topology_set - Set the adapters topology field
2639 * @phba: lpfc_hba pointer.
2640 * @val: topology value.
2643 * If val is in a valid range then set the adapter's topology field and
2644 * issue a lip; if the lip fails reset the topology to the old value.
2646 * If the value is not in range log a kernel error message and return an error.
2649 * zero if val is in range and lip okay
2650 * non-zero return value from lpfc_issue_lip()
2651 * -EINVAL val out of range
2654 lpfc_topology_store(struct device
*dev
, struct device_attribute
*attr
,
2655 const char *buf
, size_t count
)
2657 struct Scsi_Host
*shost
= class_to_shost(dev
);
2658 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2659 struct lpfc_hba
*phba
= vport
->phba
;
2662 const char *val_buf
= buf
;
2666 if (!strncmp(buf
, "nolip ", strlen("nolip "))) {
2668 val_buf
= &buf
[strlen("nolip ")];
2671 if (!isdigit(val_buf
[0]))
2673 if (sscanf(val_buf
, "%i", &val
) != 1)
2676 if (val
>= 0 && val
<= 6) {
2677 prev_val
= phba
->cfg_topology
;
2678 phba
->cfg_topology
= val
;
2682 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2683 "3054 lpfc_topology changed from %d to %d\n",
2685 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
2687 phba
->cfg_topology
= prev_val
;
2692 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2693 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2694 "allowed range is [0, 6]\n",
2698 static int lpfc_topology
= 0;
2699 module_param(lpfc_topology
, int, S_IRUGO
);
2700 MODULE_PARM_DESC(lpfc_topology
, "Select Fibre Channel topology");
2701 lpfc_param_show(topology
)
2702 lpfc_param_init(topology
, 0, 0, 6)
2703 static DEVICE_ATTR(lpfc_topology
, S_IRUGO
| S_IWUSR
,
2704 lpfc_topology_show
, lpfc_topology_store
);
2707 * lpfc_static_vport_show: Read callback function for
2708 * lpfc_static_vport sysfs file.
2709 * @dev: Pointer to class device object.
2710 * @attr: device attribute structure.
2711 * @buf: Data buffer.
2713 * This function is the read call back function for
2714 * lpfc_static_vport sysfs file. The lpfc_static_vport
2715 * sysfs file report the mageability of the vport.
2718 lpfc_static_vport_show(struct device
*dev
, struct device_attribute
*attr
,
2721 struct Scsi_Host
*shost
= class_to_shost(dev
);
2722 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2723 if (vport
->vport_flag
& STATIC_VPORT
)
2724 sprintf(buf
, "1\n");
2726 sprintf(buf
, "0\n");
2732 * Sysfs attribute to control the statistical data collection.
2734 static DEVICE_ATTR(lpfc_static_vport
, S_IRUGO
,
2735 lpfc_static_vport_show
, NULL
);
2738 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2739 * @dev: Pointer to class device.
2740 * @buf: Data buffer.
2741 * @count: Size of the data buffer.
2743 * This function get called when an user write to the lpfc_stat_data_ctrl
2744 * sysfs file. This function parse the command written to the sysfs file
2745 * and take appropriate action. These commands are used for controlling
2746 * driver statistical data collection.
2747 * Following are the command this function handles.
2749 * setbucket <bucket_type> <base> <step>
2750 * = Set the latency buckets.
2751 * destroybucket = destroy all the buckets.
2752 * start = start data collection
2753 * stop = stop data collection
2754 * reset = reset the collected data
2757 lpfc_stat_data_ctrl_store(struct device
*dev
, struct device_attribute
*attr
,
2758 const char *buf
, size_t count
)
2760 struct Scsi_Host
*shost
= class_to_shost(dev
);
2761 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2762 struct lpfc_hba
*phba
= vport
->phba
;
2763 #define LPFC_MAX_DATA_CTRL_LEN 1024
2764 static char bucket_data
[LPFC_MAX_DATA_CTRL_LEN
];
2766 char *str_ptr
, *token
;
2767 struct lpfc_vport
**vports
;
2768 struct Scsi_Host
*v_shost
;
2769 char *bucket_type_str
, *base_str
, *step_str
;
2770 unsigned long base
, step
, bucket_type
;
2772 if (!strncmp(buf
, "setbucket", strlen("setbucket"))) {
2773 if (strlen(buf
) > (LPFC_MAX_DATA_CTRL_LEN
- 1))
2776 strcpy(bucket_data
, buf
);
2777 str_ptr
= &bucket_data
[0];
2778 /* Ignore this token - this is command token */
2779 token
= strsep(&str_ptr
, "\t ");
2783 bucket_type_str
= strsep(&str_ptr
, "\t ");
2784 if (!bucket_type_str
)
2787 if (!strncmp(bucket_type_str
, "linear", strlen("linear")))
2788 bucket_type
= LPFC_LINEAR_BUCKET
;
2789 else if (!strncmp(bucket_type_str
, "power2", strlen("power2")))
2790 bucket_type
= LPFC_POWER2_BUCKET
;
2794 base_str
= strsep(&str_ptr
, "\t ");
2797 base
= simple_strtoul(base_str
, NULL
, 0);
2799 step_str
= strsep(&str_ptr
, "\t ");
2802 step
= simple_strtoul(step_str
, NULL
, 0);
2806 /* Block the data collection for every vport */
2807 vports
= lpfc_create_vport_work_array(phba
);
2811 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2812 v_shost
= lpfc_shost_from_vport(vports
[i
]);
2813 spin_lock_irq(v_shost
->host_lock
);
2814 /* Block and reset data collection */
2815 vports
[i
]->stat_data_blocked
= 1;
2816 if (vports
[i
]->stat_data_enabled
)
2817 lpfc_vport_reset_stat_data(vports
[i
]);
2818 spin_unlock_irq(v_shost
->host_lock
);
2821 /* Set the bucket attributes */
2822 phba
->bucket_type
= bucket_type
;
2823 phba
->bucket_base
= base
;
2824 phba
->bucket_step
= step
;
2826 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2827 v_shost
= lpfc_shost_from_vport(vports
[i
]);
2829 /* Unblock data collection */
2830 spin_lock_irq(v_shost
->host_lock
);
2831 vports
[i
]->stat_data_blocked
= 0;
2832 spin_unlock_irq(v_shost
->host_lock
);
2834 lpfc_destroy_vport_work_array(phba
, vports
);
2838 if (!strncmp(buf
, "destroybucket", strlen("destroybucket"))) {
2839 vports
= lpfc_create_vport_work_array(phba
);
2843 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2844 v_shost
= lpfc_shost_from_vport(vports
[i
]);
2845 spin_lock_irq(shost
->host_lock
);
2846 vports
[i
]->stat_data_blocked
= 1;
2847 lpfc_free_bucket(vport
);
2848 vport
->stat_data_enabled
= 0;
2849 vports
[i
]->stat_data_blocked
= 0;
2850 spin_unlock_irq(shost
->host_lock
);
2852 lpfc_destroy_vport_work_array(phba
, vports
);
2853 phba
->bucket_type
= LPFC_NO_BUCKET
;
2854 phba
->bucket_base
= 0;
2855 phba
->bucket_step
= 0;
2859 if (!strncmp(buf
, "start", strlen("start"))) {
2860 /* If no buckets configured return error */
2861 if (phba
->bucket_type
== LPFC_NO_BUCKET
)
2863 spin_lock_irq(shost
->host_lock
);
2864 if (vport
->stat_data_enabled
) {
2865 spin_unlock_irq(shost
->host_lock
);
2868 lpfc_alloc_bucket(vport
);
2869 vport
->stat_data_enabled
= 1;
2870 spin_unlock_irq(shost
->host_lock
);
2874 if (!strncmp(buf
, "stop", strlen("stop"))) {
2875 spin_lock_irq(shost
->host_lock
);
2876 if (vport
->stat_data_enabled
== 0) {
2877 spin_unlock_irq(shost
->host_lock
);
2880 lpfc_free_bucket(vport
);
2881 vport
->stat_data_enabled
= 0;
2882 spin_unlock_irq(shost
->host_lock
);
2886 if (!strncmp(buf
, "reset", strlen("reset"))) {
2887 if ((phba
->bucket_type
== LPFC_NO_BUCKET
)
2888 || !vport
->stat_data_enabled
)
2890 spin_lock_irq(shost
->host_lock
);
2891 vport
->stat_data_blocked
= 1;
2892 lpfc_vport_reset_stat_data(vport
);
2893 vport
->stat_data_blocked
= 0;
2894 spin_unlock_irq(shost
->host_lock
);
2902 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2903 * @dev: Pointer to class device object.
2904 * @buf: Data buffer.
2906 * This function is the read call back function for
2907 * lpfc_stat_data_ctrl sysfs file. This function report the
2908 * current statistical data collection state.
2911 lpfc_stat_data_ctrl_show(struct device
*dev
, struct device_attribute
*attr
,
2914 struct Scsi_Host
*shost
= class_to_shost(dev
);
2915 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2916 struct lpfc_hba
*phba
= vport
->phba
;
2920 unsigned long bucket_value
;
2922 switch (phba
->bucket_type
) {
2923 case LPFC_LINEAR_BUCKET
:
2924 bucket_type
= "linear";
2926 case LPFC_POWER2_BUCKET
:
2927 bucket_type
= "power2";
2930 bucket_type
= "No Bucket";
2934 sprintf(&buf
[index
], "Statistical Data enabled :%d, "
2935 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2936 " Bucket step :%d\nLatency Ranges :",
2937 vport
->stat_data_enabled
, vport
->stat_data_blocked
,
2938 bucket_type
, phba
->bucket_base
, phba
->bucket_step
);
2939 index
= strlen(buf
);
2940 if (phba
->bucket_type
!= LPFC_NO_BUCKET
) {
2941 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
; i
++) {
2942 if (phba
->bucket_type
== LPFC_LINEAR_BUCKET
)
2943 bucket_value
= phba
->bucket_base
+
2944 phba
->bucket_step
* i
;
2946 bucket_value
= phba
->bucket_base
+
2947 (1 << i
) * phba
->bucket_step
;
2949 if (index
+ 10 > PAGE_SIZE
)
2951 sprintf(&buf
[index
], "%08ld ", bucket_value
);
2952 index
= strlen(buf
);
2955 sprintf(&buf
[index
], "\n");
2960 * Sysfs attribute to control the statistical data collection.
2962 static DEVICE_ATTR(lpfc_stat_data_ctrl
, S_IRUGO
| S_IWUSR
,
2963 lpfc_stat_data_ctrl_show
, lpfc_stat_data_ctrl_store
);
2966 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2970 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2973 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2974 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2975 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2979 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2981 * @kobj: Pointer to the kernel object
2982 * @bin_attr: Attribute object
2983 * @buff: Buffer pointer
2985 * @count: Buffer size
2987 * This function is the read call back function for lpfc_drvr_stat_data
2988 * sysfs file. This function export the statistical data to user
2992 sysfs_drvr_stat_data_read(struct file
*filp
, struct kobject
*kobj
,
2993 struct bin_attribute
*bin_attr
,
2994 char *buf
, loff_t off
, size_t count
)
2996 struct device
*dev
= container_of(kobj
, struct device
,
2998 struct Scsi_Host
*shost
= class_to_shost(dev
);
2999 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3000 struct lpfc_hba
*phba
= vport
->phba
;
3001 int i
= 0, index
= 0;
3002 unsigned long nport_index
;
3003 struct lpfc_nodelist
*ndlp
= NULL
;
3004 nport_index
= (unsigned long)off
/
3005 MAX_STAT_DATA_SIZE_PER_TARGET
;
3007 if (!vport
->stat_data_enabled
|| vport
->stat_data_blocked
3008 || (phba
->bucket_type
== LPFC_NO_BUCKET
))
3011 spin_lock_irq(shost
->host_lock
);
3012 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3013 if (!NLP_CHK_NODE_ACT(ndlp
) || !ndlp
->lat_data
)
3016 if (nport_index
> 0) {
3021 if ((index
+ MAX_STAT_DATA_SIZE_PER_TARGET
)
3025 if (!ndlp
->lat_data
)
3029 sprintf(&buf
[index
], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3030 ndlp
->nlp_portname
.u
.wwn
[0],
3031 ndlp
->nlp_portname
.u
.wwn
[1],
3032 ndlp
->nlp_portname
.u
.wwn
[2],
3033 ndlp
->nlp_portname
.u
.wwn
[3],
3034 ndlp
->nlp_portname
.u
.wwn
[4],
3035 ndlp
->nlp_portname
.u
.wwn
[5],
3036 ndlp
->nlp_portname
.u
.wwn
[6],
3037 ndlp
->nlp_portname
.u
.wwn
[7]);
3039 index
= strlen(buf
);
3041 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
; i
++) {
3042 sprintf(&buf
[index
], "%010u,",
3043 ndlp
->lat_data
[i
].cmd_count
);
3044 index
= strlen(buf
);
3046 sprintf(&buf
[index
], "\n");
3047 index
= strlen(buf
);
3049 spin_unlock_irq(shost
->host_lock
);
3053 static struct bin_attribute sysfs_drvr_stat_data_attr
= {
3055 .name
= "lpfc_drvr_stat_data",
3058 .size
= LPFC_MAX_TARGET
* MAX_STAT_DATA_SIZE_PER_TARGET
,
3059 .read
= sysfs_drvr_stat_data_read
,
3064 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3066 # Value range is [0,16]. Default value is 0.
3069 * lpfc_link_speed_set - Set the adapters link speed
3070 * @phba: lpfc_hba pointer.
3071 * @val: link speed value.
3074 * If val is in a valid range then set the adapter's link speed field and
3075 * issue a lip; if the lip fails reset the link speed to the old value.
3078 * If the value is not in range log a kernel error message and return an error.
3081 * zero if val is in range and lip okay.
3082 * non-zero return value from lpfc_issue_lip()
3083 * -EINVAL val out of range
3086 lpfc_link_speed_store(struct device
*dev
, struct device_attribute
*attr
,
3087 const char *buf
, size_t count
)
3089 struct Scsi_Host
*shost
= class_to_shost(dev
);
3090 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3091 struct lpfc_hba
*phba
= vport
->phba
;
3092 int val
= LPFC_USER_LINK_SPEED_AUTO
;
3094 const char *val_buf
= buf
;
3098 if (!strncmp(buf
, "nolip ", strlen("nolip "))) {
3100 val_buf
= &buf
[strlen("nolip ")];
3103 if (!isdigit(val_buf
[0]))
3105 if (sscanf(val_buf
, "%i", &val
) != 1)
3108 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3109 "3055 lpfc_link_speed changed from %d to %d %s\n",
3110 phba
->cfg_link_speed
, val
, nolip
? "(nolip)" : "(lip)");
3112 if (((val
== LPFC_USER_LINK_SPEED_1G
) && !(phba
->lmt
& LMT_1Gb
)) ||
3113 ((val
== LPFC_USER_LINK_SPEED_2G
) && !(phba
->lmt
& LMT_2Gb
)) ||
3114 ((val
== LPFC_USER_LINK_SPEED_4G
) && !(phba
->lmt
& LMT_4Gb
)) ||
3115 ((val
== LPFC_USER_LINK_SPEED_8G
) && !(phba
->lmt
& LMT_8Gb
)) ||
3116 ((val
== LPFC_USER_LINK_SPEED_10G
) && !(phba
->lmt
& LMT_10Gb
)) ||
3117 ((val
== LPFC_USER_LINK_SPEED_16G
) && !(phba
->lmt
& LMT_16Gb
))) {
3118 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3119 "2879 lpfc_link_speed attribute cannot be set "
3120 "to %d. Speed is not supported by this port.\n",
3124 if ((val
>= 0) && (val
<= LPFC_USER_LINK_SPEED_MAX
) &&
3125 (LPFC_USER_LINK_SPEED_BITMAP
& (1 << val
))) {
3126 prev_val
= phba
->cfg_link_speed
;
3127 phba
->cfg_link_speed
= val
;
3131 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
3133 phba
->cfg_link_speed
= prev_val
;
3138 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3139 "0469 lpfc_link_speed attribute cannot be set to %d, "
3140 "allowed values are ["LPFC_LINK_SPEED_STRING
"]\n", val
);
3144 static int lpfc_link_speed
= 0;
3145 module_param(lpfc_link_speed
, int, S_IRUGO
);
3146 MODULE_PARM_DESC(lpfc_link_speed
, "Select link speed");
3147 lpfc_param_show(link_speed
)
3150 * lpfc_link_speed_init - Set the adapters link speed
3151 * @phba: lpfc_hba pointer.
3152 * @val: link speed value.
3155 * If val is in a valid range then set the adapter's link speed field.
3158 * If the value is not in range log a kernel error message, clear the link
3159 * speed and return an error.
3162 * zero if val saved.
3163 * -EINVAL val out of range
3166 lpfc_link_speed_init(struct lpfc_hba
*phba
, int val
)
3168 if ((val
>= 0) && (val
<= LPFC_USER_LINK_SPEED_MAX
) &&
3169 (LPFC_USER_LINK_SPEED_BITMAP
& (1 << val
))) {
3170 phba
->cfg_link_speed
= val
;
3173 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3174 "0405 lpfc_link_speed attribute cannot "
3175 "be set to %d, allowed values are "
3176 "["LPFC_LINK_SPEED_STRING
"]\n", val
);
3177 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
3181 static DEVICE_ATTR(lpfc_link_speed
, S_IRUGO
| S_IWUSR
,
3182 lpfc_link_speed_show
, lpfc_link_speed_store
);
3185 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3186 # 0 = aer disabled or not supported
3187 # 1 = aer supported and enabled (default)
3188 # Value range is [0,1]. Default value is 1.
3192 * lpfc_aer_support_store - Set the adapter for aer support
3194 * @dev: class device that is converted into a Scsi_host.
3195 * @attr: device attribute, not used.
3196 * @buf: containing enable or disable aer flag.
3197 * @count: unused variable.
3200 * If the val is 1 and currently the device's AER capability was not
3201 * enabled, invoke the kernel's enable AER helper routine, trying to
3202 * enable the device's AER capability. If the helper routine enabling
3203 * AER returns success, update the device's cfg_aer_support flag to
3204 * indicate AER is supported by the device; otherwise, if the device
3205 * AER capability is already enabled to support AER, then do nothing.
3207 * If the val is 0 and currently the device's AER support was enabled,
3208 * invoke the kernel's disable AER helper routine. After that, update
3209 * the device's cfg_aer_support flag to indicate AER is not supported
3210 * by the device; otherwise, if the device AER capability is already
3211 * disabled from supporting AER, then do nothing.
3214 * length of the buf on success if val is in range the intended mode
3216 * -EINVAL if val out of range or intended mode is not supported.
3219 lpfc_aer_support_store(struct device
*dev
, struct device_attribute
*attr
,
3220 const char *buf
, size_t count
)
3222 struct Scsi_Host
*shost
= class_to_shost(dev
);
3223 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
3224 struct lpfc_hba
*phba
= vport
->phba
;
3225 int val
= 0, rc
= -EINVAL
;
3227 if (!isdigit(buf
[0]))
3229 if (sscanf(buf
, "%i", &val
) != 1)
3234 if (phba
->hba_flag
& HBA_AER_ENABLED
) {
3235 rc
= pci_disable_pcie_error_reporting(phba
->pcidev
);
3237 spin_lock_irq(&phba
->hbalock
);
3238 phba
->hba_flag
&= ~HBA_AER_ENABLED
;
3239 spin_unlock_irq(&phba
->hbalock
);
3240 phba
->cfg_aer_support
= 0;
3245 phba
->cfg_aer_support
= 0;
3250 if (!(phba
->hba_flag
& HBA_AER_ENABLED
)) {
3251 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
3253 spin_lock_irq(&phba
->hbalock
);
3254 phba
->hba_flag
|= HBA_AER_ENABLED
;
3255 spin_unlock_irq(&phba
->hbalock
);
3256 phba
->cfg_aer_support
= 1;
3261 phba
->cfg_aer_support
= 1;
3272 static int lpfc_aer_support
= 1;
3273 module_param(lpfc_aer_support
, int, S_IRUGO
);
3274 MODULE_PARM_DESC(lpfc_aer_support
, "Enable PCIe device AER support");
3275 lpfc_param_show(aer_support
)
3278 * lpfc_aer_support_init - Set the initial adapters aer support flag
3279 * @phba: lpfc_hba pointer.
3280 * @val: enable aer or disable aer flag.
3283 * If val is in a valid range [0,1], then set the adapter's initial
3284 * cfg_aer_support field. It will be up to the driver's probe_one
3285 * routine to determine whether the device's AER support can be set
3289 * If the value is not in range log a kernel error message, and
3290 * choose the default value of setting AER support and return.
3293 * zero if val saved.
3294 * -EINVAL val out of range
3297 lpfc_aer_support_init(struct lpfc_hba
*phba
, int val
)
3299 if (val
== 0 || val
== 1) {
3300 phba
->cfg_aer_support
= val
;
3303 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3304 "2712 lpfc_aer_support attribute value %d out "
3305 "of range, allowed values are 0|1, setting it "
3306 "to default value of 1\n", val
);
3307 /* By default, try to enable AER on a device */
3308 phba
->cfg_aer_support
= 1;
3312 static DEVICE_ATTR(lpfc_aer_support
, S_IRUGO
| S_IWUSR
,
3313 lpfc_aer_support_show
, lpfc_aer_support_store
);
3316 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3317 * @dev: class device that is converted into a Scsi_host.
3318 * @attr: device attribute, not used.
3319 * @buf: containing flag 1 for aer cleanup state.
3320 * @count: unused variable.
3323 * If the @buf contains 1 and the device currently has the AER support
3324 * enabled, then invokes the kernel AER helper routine
3325 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3326 * error status register.
3331 * -EINVAL if the buf does not contain the 1 or the device is not currently
3332 * enabled with the AER support.
3335 lpfc_aer_cleanup_state(struct device
*dev
, struct device_attribute
*attr
,
3336 const char *buf
, size_t count
)
3338 struct Scsi_Host
*shost
= class_to_shost(dev
);
3339 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3340 struct lpfc_hba
*phba
= vport
->phba
;
3343 if (!isdigit(buf
[0]))
3345 if (sscanf(buf
, "%i", &val
) != 1)
3350 if (phba
->hba_flag
& HBA_AER_ENABLED
)
3351 rc
= pci_cleanup_aer_uncorrect_error_status(phba
->pcidev
);
3359 static DEVICE_ATTR(lpfc_aer_state_cleanup
, S_IWUSR
, NULL
,
3360 lpfc_aer_cleanup_state
);
3363 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3365 * @dev: class device that is converted into a Scsi_host.
3366 * @attr: device attribute, not used.
3367 * @buf: containing the string the number of vfs to be enabled.
3368 * @count: unused variable.
3371 * When this api is called either through user sysfs, the driver shall
3372 * try to enable or disable SR-IOV virtual functions according to the
3375 * If zero virtual function has been enabled to the physical function,
3376 * the driver shall invoke the pci enable virtual function api trying
3377 * to enable the virtual functions. If the nr_vfn provided is greater
3378 * than the maximum supported, the maximum virtual function number will
3379 * be used for invoking the api; otherwise, the nr_vfn provided shall
3380 * be used for invoking the api. If the api call returned success, the
3381 * actual number of virtual functions enabled will be set to the driver
3382 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3383 * cfg_sriov_nr_virtfn remains zero.
3385 * If none-zero virtual functions have already been enabled to the
3386 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3387 * -EINVAL will be returned and the driver does nothing;
3389 * If the nr_vfn provided is zero and none-zero virtual functions have
3390 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3391 * disabling virtual function api shall be invoded to disable all the
3392 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3393 * zero. Otherwise, if zero virtual function has been enabled, do
3397 * length of the buf on success if val is in range the intended mode
3399 * -EINVAL if val out of range or intended mode is not supported.
3402 lpfc_sriov_nr_virtfn_store(struct device
*dev
, struct device_attribute
*attr
,
3403 const char *buf
, size_t count
)
3405 struct Scsi_Host
*shost
= class_to_shost(dev
);
3406 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
3407 struct lpfc_hba
*phba
= vport
->phba
;
3408 struct pci_dev
*pdev
= phba
->pcidev
;
3409 int val
= 0, rc
= -EINVAL
;
3411 /* Sanity check on user data */
3412 if (!isdigit(buf
[0]))
3414 if (sscanf(buf
, "%i", &val
) != 1)
3419 /* Request disabling virtual functions */
3421 if (phba
->cfg_sriov_nr_virtfn
> 0) {
3422 pci_disable_sriov(pdev
);
3423 phba
->cfg_sriov_nr_virtfn
= 0;
3428 /* Request enabling virtual functions */
3429 if (phba
->cfg_sriov_nr_virtfn
> 0) {
3430 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3431 "3018 There are %d virtual functions "
3432 "enabled on physical function.\n",
3433 phba
->cfg_sriov_nr_virtfn
);
3437 if (val
<= LPFC_MAX_VFN_PER_PFN
)
3438 phba
->cfg_sriov_nr_virtfn
= val
;
3440 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3441 "3019 Enabling %d virtual functions is not "
3446 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
, phba
->cfg_sriov_nr_virtfn
);
3448 phba
->cfg_sriov_nr_virtfn
= 0;
3456 static int lpfc_sriov_nr_virtfn
= LPFC_DEF_VFN_PER_PFN
;
3457 module_param(lpfc_sriov_nr_virtfn
, int, S_IRUGO
|S_IWUSR
);
3458 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn
, "Enable PCIe device SR-IOV virtual fn");
3459 lpfc_param_show(sriov_nr_virtfn
)
3462 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3463 * @phba: lpfc_hba pointer.
3464 * @val: link speed value.
3467 * If val is in a valid range [0,255], then set the adapter's initial
3468 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3469 * number shall be used instead. It will be up to the driver's probe_one
3470 * routine to determine whether the device's SR-IOV is supported or not.
3473 * zero if val saved.
3474 * -EINVAL val out of range
3477 lpfc_sriov_nr_virtfn_init(struct lpfc_hba
*phba
, int val
)
3479 if (val
>= 0 && val
<= LPFC_MAX_VFN_PER_PFN
) {
3480 phba
->cfg_sriov_nr_virtfn
= val
;
3484 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3485 "3017 Enabling %d virtual functions is not "
3489 static DEVICE_ATTR(lpfc_sriov_nr_virtfn
, S_IRUGO
| S_IWUSR
,
3490 lpfc_sriov_nr_virtfn_show
, lpfc_sriov_nr_virtfn_store
);
3493 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3494 # Value range is [2,3]. Default value is 3.
3496 LPFC_VPORT_ATTR_R(fcp_class
, 3, 2, 3,
3497 "Select Fibre Channel class of service for FCP sequences");
3500 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3501 # is [0,1]. Default value is 0.
3503 LPFC_VPORT_ATTR_RW(use_adisc
, 0, 0, 1,
3504 "Use ADISC on rediscovery to authenticate FCP devices");
3507 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3508 # depth. Default value is 0. When the value of this parameter is zero the
3509 # SCSI command completion time is not used for controlling I/O queue depth. When
3510 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3511 # to limit the I/O completion time to the parameter value.
3512 # The value is set in milliseconds.
3514 static int lpfc_max_scsicmpl_time
;
3515 module_param(lpfc_max_scsicmpl_time
, int, S_IRUGO
);
3516 MODULE_PARM_DESC(lpfc_max_scsicmpl_time
,
3517 "Use command completion time to control queue depth");
3518 lpfc_vport_param_show(max_scsicmpl_time
);
3519 lpfc_vport_param_init(max_scsicmpl_time
, 0, 0, 60000);
3521 lpfc_max_scsicmpl_time_set(struct lpfc_vport
*vport
, int val
)
3523 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3524 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3526 if (val
== vport
->cfg_max_scsicmpl_time
)
3528 if ((val
< 0) || (val
> 60000))
3530 vport
->cfg_max_scsicmpl_time
= val
;
3532 spin_lock_irq(shost
->host_lock
);
3533 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3534 if (!NLP_CHK_NODE_ACT(ndlp
))
3536 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
3538 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
3540 spin_unlock_irq(shost
->host_lock
);
3543 lpfc_vport_param_store(max_scsicmpl_time
);
3544 static DEVICE_ATTR(lpfc_max_scsicmpl_time
, S_IRUGO
| S_IWUSR
,
3545 lpfc_max_scsicmpl_time_show
,
3546 lpfc_max_scsicmpl_time_store
);
3549 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3550 # range is [0,1]. Default value is 0.
3552 LPFC_ATTR_R(ack0
, 0, 0, 1, "Enable ACK0 support");
3555 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3556 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3557 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3558 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3559 # cr_delay is set to 0.
3561 LPFC_ATTR_RW(cr_delay
, 0, 0, 63, "A count of milliseconds after which an "
3562 "interrupt response is generated");
3564 LPFC_ATTR_RW(cr_count
, 1, 1, 255, "A count of I/O completions after which an "
3565 "interrupt response is generated");
3568 # lpfc_multi_ring_support: Determines how many rings to spread available
3569 # cmd/rsp IOCB entries across.
3570 # Value range is [1,2]. Default value is 1.
3572 LPFC_ATTR_R(multi_ring_support
, 1, 1, 2, "Determines number of primary "
3573 "SLI rings to spread IOCB entries across");
3576 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3577 # identifies what rctl value to configure the additional ring for.
3578 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3580 LPFC_ATTR_R(multi_ring_rctl
, FC_RCTL_DD_UNSOL_DATA
, 1,
3581 255, "Identifies RCTL for additional ring configuration");
3584 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3585 # identifies what type value to configure the additional ring for.
3586 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3588 LPFC_ATTR_R(multi_ring_type
, FC_TYPE_IP
, 1,
3589 255, "Identifies TYPE for additional ring configuration");
3592 # lpfc_fdmi_on: controls FDMI support.
3593 # 0 = no FDMI support
3594 # 1 = support FDMI without attribute of hostname
3595 # 2 = support FDMI with attribute of hostname
3596 # Value range [0,2]. Default value is 0.
3598 LPFC_VPORT_ATTR_RW(fdmi_on
, 0, 0, 2, "Enable FDMI support");
3601 # Specifies the maximum number of ELS cmds we can have outstanding (for
3602 # discovery). Value range is [1,64]. Default value = 32.
3604 LPFC_VPORT_ATTR(discovery_threads
, 32, 1, 64, "Maximum number of ELS commands "
3605 "during discovery");
3608 # lpfc_max_luns: maximum allowed LUN.
3609 # Value range is [0,65535]. Default value is 255.
3610 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3612 LPFC_VPORT_ATTR_R(max_luns
, 255, 0, 65535, "Maximum allowed LUN");
3615 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3616 # Value range is [1,255], default value is 10.
3618 LPFC_ATTR_RW(poll_tmo
, 10, 1, 255,
3619 "Milliseconds driver will wait between polling FCP ring");
3622 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3623 # support this feature
3626 # 2 = MSI-X enabled (default)
3627 # Value range is [0,2]. Default value is 2.
3629 LPFC_ATTR_R(use_msi
, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3630 "MSI-X (2), if possible");
3633 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3635 # Value range is [636,651042]. Default value is 10000.
3637 LPFC_ATTR_R(fcp_imax
, LPFC_FP_DEF_IMAX
, LPFC_MIM_IMAX
, LPFC_DMULT_CONST
,
3638 "Set the maximum number of fast-path FCP interrupts per second");
3641 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3643 # Value range is [1,31]. Default value is 4.
3645 LPFC_ATTR_R(fcp_wq_count
, LPFC_FP_WQN_DEF
, LPFC_FP_WQN_MIN
, LPFC_FP_WQN_MAX
,
3646 "Set the number of fast-path FCP work queues, if possible");
3649 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3651 # Value range is [1,7]. Default value is 1.
3653 LPFC_ATTR_R(fcp_eq_count
, LPFC_FP_EQN_DEF
, LPFC_FP_EQN_MIN
, LPFC_FP_EQN_MAX
,
3654 "Set the number of fast-path FCP event queues, if possible");
3657 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3658 # 0 = HBA resets disabled
3659 # 1 = HBA resets enabled (default)
3660 # Value range is [0,1]. Default value is 1.
3662 LPFC_ATTR_R(enable_hba_reset
, 1, 0, 1, "Enable HBA resets from the driver.");
3665 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3666 # 0 = HBA Heartbeat disabled
3667 # 1 = HBA Heartbeat enabled (default)
3668 # Value range is [0,1]. Default value is 1.
3670 LPFC_ATTR_R(enable_hba_heartbeat
, 0, 0, 1, "Enable HBA Heartbeat.");
3673 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3674 # 0 = BlockGuard disabled (default)
3675 # 1 = BlockGuard enabled
3676 # Value range is [0,1]. Default value is 0.
3678 LPFC_ATTR_R(enable_bg
, 0, 0, 1, "Enable BlockGuard Support");
3682 # - Bit mask of host protection capabilities used to register with the
3684 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3685 # - Allows you to ultimately specify which profiles to use
3686 # - Default will result in registering capabilities for all profiles.
3689 unsigned int lpfc_prot_mask
= SHOST_DIF_TYPE1_PROTECTION
|
3690 SHOST_DIX_TYPE0_PROTECTION
|
3691 SHOST_DIX_TYPE1_PROTECTION
;
3693 module_param(lpfc_prot_mask
, uint
, S_IRUGO
);
3694 MODULE_PARM_DESC(lpfc_prot_mask
, "host protection mask");
3697 # lpfc_prot_guard: i
3698 # - Bit mask of protection guard types to register with the SCSI mid-layer
3699 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3700 # - Allows you to ultimately specify which profiles to use
3701 # - Default will result in registering capabilities for all guard types
3704 unsigned char lpfc_prot_guard
= SHOST_DIX_GUARD_IP
;
3705 module_param(lpfc_prot_guard
, byte
, S_IRUGO
);
3706 MODULE_PARM_DESC(lpfc_prot_guard
, "host protection guard type");
3709 * Delay initial NPort discovery when Clean Address bit is cleared in
3710 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3711 * This parameter can have value 0 or 1.
3712 * When this parameter is set to 0, no delay is added to the initial
3714 * When this parameter is set to non-zero value, initial Nport discovery is
3715 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3716 * accept and FCID/Fabric name/Fabric portname is changed.
3717 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3718 * when Clean Address bit is cleared in FLOGI/FDISC
3719 * accept and FCID/Fabric name/Fabric portname is changed.
3720 * Default value is 0.
3722 int lpfc_delay_discovery
;
3723 module_param(lpfc_delay_discovery
, int, S_IRUGO
);
3724 MODULE_PARM_DESC(lpfc_delay_discovery
,
3725 "Delay NPort discovery when Clean Address bit is cleared. "
3726 "Allowed values: 0,1.");
3729 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3730 * This value can be set to values between 64 and 256. The default value is
3731 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3732 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3734 LPFC_ATTR_R(sg_seg_cnt
, LPFC_DEFAULT_SG_SEG_CNT
, LPFC_DEFAULT_SG_SEG_CNT
,
3735 LPFC_MAX_SG_SEG_CNT
, "Max Scatter Gather Segment Count");
3737 LPFC_ATTR_R(prot_sg_seg_cnt
, LPFC_DEFAULT_PROT_SG_SEG_CNT
,
3738 LPFC_DEFAULT_PROT_SG_SEG_CNT
, LPFC_MAX_PROT_SG_SEG_CNT
,
3739 "Max Protection Scatter Gather Segment Count");
3741 struct device_attribute
*lpfc_hba_attrs
[] = {
3743 &dev_attr_bg_guard_err
,
3744 &dev_attr_bg_apptag_err
,
3745 &dev_attr_bg_reftag_err
,
3747 &dev_attr_serialnum
,
3748 &dev_attr_modeldesc
,
3749 &dev_attr_modelname
,
3750 &dev_attr_programtype
,
3754 &dev_attr_option_rom_version
,
3755 &dev_attr_link_state
,
3756 &dev_attr_num_discovered_ports
,
3757 &dev_attr_menlo_mgmt_mode
,
3758 &dev_attr_lpfc_drvr_version
,
3759 &dev_attr_lpfc_enable_fip
,
3760 &dev_attr_lpfc_temp_sensor
,
3761 &dev_attr_lpfc_log_verbose
,
3762 &dev_attr_lpfc_lun_queue_depth
,
3763 &dev_attr_lpfc_tgt_queue_depth
,
3764 &dev_attr_lpfc_hba_queue_depth
,
3765 &dev_attr_lpfc_peer_port_login
,
3766 &dev_attr_lpfc_nodev_tmo
,
3767 &dev_attr_lpfc_devloss_tmo
,
3768 &dev_attr_lpfc_fcp_class
,
3769 &dev_attr_lpfc_use_adisc
,
3770 &dev_attr_lpfc_ack0
,
3771 &dev_attr_lpfc_topology
,
3772 &dev_attr_lpfc_scan_down
,
3773 &dev_attr_lpfc_link_speed
,
3774 &dev_attr_lpfc_cr_delay
,
3775 &dev_attr_lpfc_cr_count
,
3776 &dev_attr_lpfc_multi_ring_support
,
3777 &dev_attr_lpfc_multi_ring_rctl
,
3778 &dev_attr_lpfc_multi_ring_type
,
3779 &dev_attr_lpfc_fdmi_on
,
3780 &dev_attr_lpfc_max_luns
,
3781 &dev_attr_lpfc_enable_npiv
,
3782 &dev_attr_lpfc_fcf_failover_policy
,
3783 &dev_attr_lpfc_enable_rrq
,
3784 &dev_attr_nport_evt_cnt
,
3785 &dev_attr_board_mode
,
3792 &dev_attr_npiv_info
,
3793 &dev_attr_issue_reset
,
3794 &dev_attr_lpfc_poll
,
3795 &dev_attr_lpfc_poll_tmo
,
3796 &dev_attr_lpfc_use_msi
,
3797 &dev_attr_lpfc_fcp_imax
,
3798 &dev_attr_lpfc_fcp_wq_count
,
3799 &dev_attr_lpfc_fcp_eq_count
,
3800 &dev_attr_lpfc_enable_bg
,
3801 &dev_attr_lpfc_soft_wwnn
,
3802 &dev_attr_lpfc_soft_wwpn
,
3803 &dev_attr_lpfc_soft_wwn_enable
,
3804 &dev_attr_lpfc_enable_hba_reset
,
3805 &dev_attr_lpfc_enable_hba_heartbeat
,
3806 &dev_attr_lpfc_sg_seg_cnt
,
3807 &dev_attr_lpfc_max_scsicmpl_time
,
3808 &dev_attr_lpfc_stat_data_ctrl
,
3809 &dev_attr_lpfc_prot_sg_seg_cnt
,
3810 &dev_attr_lpfc_aer_support
,
3811 &dev_attr_lpfc_aer_state_cleanup
,
3812 &dev_attr_lpfc_sriov_nr_virtfn
,
3813 &dev_attr_lpfc_suppress_link_up
,
3814 &dev_attr_lpfc_iocb_cnt
,
3817 &dev_attr_txcmplq_hw
,
3818 &dev_attr_lpfc_fips_level
,
3819 &dev_attr_lpfc_fips_rev
,
3821 &dev_attr_lpfc_sriov_hw_max_virtfn
,
3825 struct device_attribute
*lpfc_vport_attrs
[] = {
3827 &dev_attr_link_state
,
3828 &dev_attr_num_discovered_ports
,
3829 &dev_attr_lpfc_drvr_version
,
3830 &dev_attr_lpfc_log_verbose
,
3831 &dev_attr_lpfc_lun_queue_depth
,
3832 &dev_attr_lpfc_tgt_queue_depth
,
3833 &dev_attr_lpfc_nodev_tmo
,
3834 &dev_attr_lpfc_devloss_tmo
,
3835 &dev_attr_lpfc_hba_queue_depth
,
3836 &dev_attr_lpfc_peer_port_login
,
3837 &dev_attr_lpfc_restrict_login
,
3838 &dev_attr_lpfc_fcp_class
,
3839 &dev_attr_lpfc_use_adisc
,
3840 &dev_attr_lpfc_fdmi_on
,
3841 &dev_attr_lpfc_max_luns
,
3842 &dev_attr_nport_evt_cnt
,
3843 &dev_attr_npiv_info
,
3844 &dev_attr_lpfc_enable_da_id
,
3845 &dev_attr_lpfc_max_scsicmpl_time
,
3846 &dev_attr_lpfc_stat_data_ctrl
,
3847 &dev_attr_lpfc_static_vport
,
3848 &dev_attr_lpfc_fips_level
,
3849 &dev_attr_lpfc_fips_rev
,
3854 * sysfs_ctlreg_write - Write method for writing to ctlreg
3855 * @filp: open sysfs file
3856 * @kobj: kernel kobject that contains the kernel class device.
3857 * @bin_attr: kernel attributes passed to us.
3858 * @buf: contains the data to be written to the adapter IOREG space.
3859 * @off: offset into buffer to beginning of data.
3860 * @count: bytes to transfer.
3863 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3864 * Uses the adapter io control registers to send buf contents to the adapter.
3867 * -ERANGE off and count combo out of range
3868 * -EINVAL off, count or buff address invalid
3869 * -EPERM adapter is offline
3870 * value of count, buf contents written
3873 sysfs_ctlreg_write(struct file
*filp
, struct kobject
*kobj
,
3874 struct bin_attribute
*bin_attr
,
3875 char *buf
, loff_t off
, size_t count
)
3878 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3879 struct Scsi_Host
*shost
= class_to_shost(dev
);
3880 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3881 struct lpfc_hba
*phba
= vport
->phba
;
3883 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
3886 if ((off
+ count
) > FF_REG_AREA_SIZE
)
3889 if (count
== 0) return 0;
3891 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
3894 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
3898 spin_lock_irq(&phba
->hbalock
);
3899 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t))
3900 writel(*((uint32_t *)(buf
+ buf_off
)),
3901 phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
3903 spin_unlock_irq(&phba
->hbalock
);
3909 * sysfs_ctlreg_read - Read method for reading from ctlreg
3910 * @filp: open sysfs file
3911 * @kobj: kernel kobject that contains the kernel class device.
3912 * @bin_attr: kernel attributes passed to us.
3913 * @buf: if successful contains the data from the adapter IOREG space.
3914 * @off: offset into buffer to beginning of data.
3915 * @count: bytes to transfer.
3918 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3919 * Uses the adapter io control registers to read data into buf.
3922 * -ERANGE off and count combo out of range
3923 * -EINVAL off, count or buff address invalid
3924 * value of count, buf contents read
3927 sysfs_ctlreg_read(struct file
*filp
, struct kobject
*kobj
,
3928 struct bin_attribute
*bin_attr
,
3929 char *buf
, loff_t off
, size_t count
)
3933 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3934 struct Scsi_Host
*shost
= class_to_shost(dev
);
3935 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3936 struct lpfc_hba
*phba
= vport
->phba
;
3938 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
3941 if (off
> FF_REG_AREA_SIZE
)
3944 if ((off
+ count
) > FF_REG_AREA_SIZE
)
3945 count
= FF_REG_AREA_SIZE
- off
;
3947 if (count
== 0) return 0;
3949 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
3952 spin_lock_irq(&phba
->hbalock
);
3954 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t)) {
3955 tmp_ptr
= (uint32_t *)(buf
+ buf_off
);
3956 *tmp_ptr
= readl(phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
3959 spin_unlock_irq(&phba
->hbalock
);
3964 static struct bin_attribute sysfs_ctlreg_attr
= {
3967 .mode
= S_IRUSR
| S_IWUSR
,
3970 .read
= sysfs_ctlreg_read
,
3971 .write
= sysfs_ctlreg_write
,
3975 * sysfs_mbox_idle - frees the sysfs mailbox
3976 * @phba: lpfc_hba pointer
3979 sysfs_mbox_idle(struct lpfc_hba
*phba
)
3981 phba
->sysfs_mbox
.state
= SMBOX_IDLE
;
3982 phba
->sysfs_mbox
.offset
= 0;
3984 if (phba
->sysfs_mbox
.mbox
) {
3985 mempool_free(phba
->sysfs_mbox
.mbox
,
3986 phba
->mbox_mem_pool
);
3987 phba
->sysfs_mbox
.mbox
= NULL
;
3992 * sysfs_mbox_write - Write method for writing information via mbox
3993 * @filp: open sysfs file
3994 * @kobj: kernel kobject that contains the kernel class device.
3995 * @bin_attr: kernel attributes passed to us.
3996 * @buf: contains the data to be written to sysfs mbox.
3997 * @off: offset into buffer to beginning of data.
3998 * @count: bytes to transfer.
4001 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4002 * Uses the sysfs mbox to send buf contents to the adapter.
4005 * -ERANGE off and count combo out of range
4006 * -EINVAL off, count or buff address invalid
4007 * zero if count is zero
4008 * -EPERM adapter is offline
4009 * -ENOMEM failed to allocate memory for the mail box
4010 * -EAGAIN offset, state or mbox is NULL
4011 * count number of bytes transferred
4014 sysfs_mbox_write(struct file
*filp
, struct kobject
*kobj
,
4015 struct bin_attribute
*bin_attr
,
4016 char *buf
, loff_t off
, size_t count
)
4018 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4019 struct Scsi_Host
*shost
= class_to_shost(dev
);
4020 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4021 struct lpfc_hba
*phba
= vport
->phba
;
4022 struct lpfcMboxq
*mbox
= NULL
;
4024 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
4027 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
4034 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4037 memset(mbox
, 0, sizeof (LPFC_MBOXQ_t
));
4040 spin_lock_irq(&phba
->hbalock
);
4043 if (phba
->sysfs_mbox
.mbox
)
4044 mempool_free(mbox
, phba
->mbox_mem_pool
);
4046 phba
->sysfs_mbox
.mbox
= mbox
;
4047 phba
->sysfs_mbox
.state
= SMBOX_WRITING
;
4049 if (phba
->sysfs_mbox
.state
!= SMBOX_WRITING
||
4050 phba
->sysfs_mbox
.offset
!= off
||
4051 phba
->sysfs_mbox
.mbox
== NULL
) {
4052 sysfs_mbox_idle(phba
);
4053 spin_unlock_irq(&phba
->hbalock
);
4058 memcpy((uint8_t *) &phba
->sysfs_mbox
.mbox
->u
.mb
+ off
,
4061 phba
->sysfs_mbox
.offset
= off
+ count
;
4063 spin_unlock_irq(&phba
->hbalock
);
4069 * sysfs_mbox_read - Read method for reading information via mbox
4070 * @filp: open sysfs file
4071 * @kobj: kernel kobject that contains the kernel class device.
4072 * @bin_attr: kernel attributes passed to us.
4073 * @buf: contains the data to be read from sysfs mbox.
4074 * @off: offset into buffer to beginning of data.
4075 * @count: bytes to transfer.
4078 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4079 * Uses the sysfs mbox to receive data from to the adapter.
4082 * -ERANGE off greater than mailbox command size
4083 * -EINVAL off, count or buff address invalid
4084 * zero if off and count are zero
4085 * -EACCES adapter over temp
4086 * -EPERM garbage can value to catch a multitude of errors
4087 * -EAGAIN management IO not permitted, state or off error
4088 * -ETIME mailbox timeout
4089 * -ENODEV mailbox error
4090 * count number of bytes transferred
4093 sysfs_mbox_read(struct file
*filp
, struct kobject
*kobj
,
4094 struct bin_attribute
*bin_attr
,
4095 char *buf
, loff_t off
, size_t count
)
4097 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4098 struct Scsi_Host
*shost
= class_to_shost(dev
);
4099 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4100 struct lpfc_hba
*phba
= vport
->phba
;
4104 if (off
> MAILBOX_CMD_SIZE
)
4107 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
4108 count
= MAILBOX_CMD_SIZE
- off
;
4110 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
4113 if (off
&& count
== 0)
4116 spin_lock_irq(&phba
->hbalock
);
4118 if (phba
->over_temp_state
== HBA_OVER_TEMP
) {
4119 sysfs_mbox_idle(phba
);
4120 spin_unlock_irq(&phba
->hbalock
);
4125 phba
->sysfs_mbox
.state
== SMBOX_WRITING
&&
4126 phba
->sysfs_mbox
.offset
>= 2 * sizeof(uint32_t)) {
4127 pmb
= &phba
->sysfs_mbox
.mbox
->u
.mb
;
4128 switch (pmb
->mbxCommand
) {
4132 case MBX_CONFIG_LINK
:
4133 case MBX_CONFIG_RING
:
4134 case MBX_RESET_RING
:
4135 case MBX_UNREG_LOGIN
:
4137 case MBX_DUMP_CONTEXT
:
4142 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
4143 printk(KERN_WARNING
"mbox_read:Command 0x%x "
4144 "is illegal in on-line state\n",
4146 sysfs_mbox_idle(phba
);
4147 spin_unlock_irq(&phba
->hbalock
);
4151 case MBX_WRITE_VPARMS
:
4154 case MBX_READ_CONFIG
:
4155 case MBX_READ_RCONFIG
:
4156 case MBX_READ_STATUS
:
4159 case MBX_READ_LNK_STAT
:
4160 case MBX_DUMP_MEMORY
:
4162 case MBX_UPDATE_CFG
:
4163 case MBX_KILL_BOARD
:
4165 case MBX_LOAD_EXP_ROM
:
4167 case MBX_DEL_LD_ENTRY
:
4168 case MBX_SET_VARIABLE
:
4170 case MBX_PORT_CAPABILITIES
:
4171 case MBX_PORT_IOV_CONTROL
:
4173 case MBX_SECURITY_MGMT
:
4175 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
4176 printk(KERN_WARNING
"mbox_read:Command 0x%x "
4177 "is not permitted\n", pmb
->mbxCommand
);
4178 sysfs_mbox_idle(phba
);
4179 spin_unlock_irq(&phba
->hbalock
);
4183 case MBX_READ_SPARM64
:
4184 case MBX_READ_TOPOLOGY
:
4186 case MBX_REG_LOGIN64
:
4187 case MBX_CONFIG_PORT
:
4188 case MBX_RUN_BIU_DIAG
:
4189 printk(KERN_WARNING
"mbox_read: Illegal Command 0x%x\n",
4191 sysfs_mbox_idle(phba
);
4192 spin_unlock_irq(&phba
->hbalock
);
4195 printk(KERN_WARNING
"mbox_read: Unknown Command 0x%x\n",
4197 sysfs_mbox_idle(phba
);
4198 spin_unlock_irq(&phba
->hbalock
);
4202 /* If HBA encountered an error attention, allow only DUMP
4203 * or RESTART mailbox commands until the HBA is restarted.
4205 if (phba
->pport
->stopped
&&
4206 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4207 pmb
->mbxCommand
!= MBX_RESTART
&&
4208 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4209 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4210 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4211 "1259 mbox: Issued mailbox cmd "
4212 "0x%x while in stopped state.\n",
4215 phba
->sysfs_mbox
.mbox
->vport
= vport
;
4217 /* Don't allow mailbox commands to be sent when blocked
4218 * or when in the middle of discovery
4220 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4221 sysfs_mbox_idle(phba
);
4222 spin_unlock_irq(&phba
->hbalock
);
4226 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4227 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4229 spin_unlock_irq(&phba
->hbalock
);
4230 rc
= lpfc_sli_issue_mbox (phba
,
4231 phba
->sysfs_mbox
.mbox
,
4233 spin_lock_irq(&phba
->hbalock
);
4236 spin_unlock_irq(&phba
->hbalock
);
4237 rc
= lpfc_sli_issue_mbox_wait (phba
,
4238 phba
->sysfs_mbox
.mbox
,
4239 lpfc_mbox_tmo_val(phba
, pmb
->mbxCommand
) * HZ
);
4240 spin_lock_irq(&phba
->hbalock
);
4243 if (rc
!= MBX_SUCCESS
) {
4244 if (rc
== MBX_TIMEOUT
) {
4245 phba
->sysfs_mbox
.mbox
= NULL
;
4247 sysfs_mbox_idle(phba
);
4248 spin_unlock_irq(&phba
->hbalock
);
4249 return (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4251 phba
->sysfs_mbox
.state
= SMBOX_READING
;
4253 else if (phba
->sysfs_mbox
.offset
!= off
||
4254 phba
->sysfs_mbox
.state
!= SMBOX_READING
) {
4255 printk(KERN_WARNING
"mbox_read: Bad State\n");
4256 sysfs_mbox_idle(phba
);
4257 spin_unlock_irq(&phba
->hbalock
);
4261 memcpy(buf
, (uint8_t *) &pmb
+ off
, count
);
4263 phba
->sysfs_mbox
.offset
= off
+ count
;
4265 if (phba
->sysfs_mbox
.offset
== MAILBOX_CMD_SIZE
)
4266 sysfs_mbox_idle(phba
);
4268 spin_unlock_irq(&phba
->hbalock
);
4273 static struct bin_attribute sysfs_mbox_attr
= {
4276 .mode
= S_IRUSR
| S_IWUSR
,
4278 .size
= MAILBOX_SYSFS_MAX
,
4279 .read
= sysfs_mbox_read
,
4280 .write
= sysfs_mbox_write
,
4284 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
4285 * @vport: address of lpfc vport structure.
4289 * error return code from sysfs_create_bin_file()
4292 lpfc_alloc_sysfs_attr(struct lpfc_vport
*vport
)
4294 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4297 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
4298 &sysfs_drvr_stat_data_attr
);
4300 /* Virtual ports do not need ctrl_reg and mbox */
4301 if (error
|| vport
->port_type
== LPFC_NPIV_PORT
)
4304 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
4305 &sysfs_ctlreg_attr
);
4307 goto out_remove_stat_attr
;
4309 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
4312 goto out_remove_ctlreg_attr
;
4315 out_remove_ctlreg_attr
:
4316 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
4317 out_remove_stat_attr
:
4318 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
,
4319 &sysfs_drvr_stat_data_attr
);
4325 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4326 * @vport: address of lpfc vport structure.
4329 lpfc_free_sysfs_attr(struct lpfc_vport
*vport
)
4331 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4332 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
,
4333 &sysfs_drvr_stat_data_attr
);
4334 /* Virtual ports do not need ctrl_reg and mbox */
4335 if (vport
->port_type
== LPFC_NPIV_PORT
)
4337 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_mbox_attr
);
4338 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
4343 * Dynamic FC Host Attributes Support
4347 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4348 * @shost: kernel scsi host pointer.
4351 lpfc_get_host_port_id(struct Scsi_Host
*shost
)
4353 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4355 /* note: fc_myDID already in cpu endianness */
4356 fc_host_port_id(shost
) = vport
->fc_myDID
;
4360 * lpfc_get_host_port_type - Set the value of the scsi host port type
4361 * @shost: kernel scsi host pointer.
4364 lpfc_get_host_port_type(struct Scsi_Host
*shost
)
4366 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4367 struct lpfc_hba
*phba
= vport
->phba
;
4369 spin_lock_irq(shost
->host_lock
);
4371 if (vport
->port_type
== LPFC_NPIV_PORT
) {
4372 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
4373 } else if (lpfc_is_link_up(phba
)) {
4374 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4375 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
4376 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
4378 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
4380 if (vport
->fc_flag
& FC_FABRIC
)
4381 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
4383 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
4386 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
4388 spin_unlock_irq(shost
->host_lock
);
4392 * lpfc_get_host_port_state - Set the value of the scsi host port state
4393 * @shost: kernel scsi host pointer.
4396 lpfc_get_host_port_state(struct Scsi_Host
*shost
)
4398 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4399 struct lpfc_hba
*phba
= vport
->phba
;
4401 spin_lock_irq(shost
->host_lock
);
4403 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
4404 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
4406 switch (phba
->link_state
) {
4407 case LPFC_LINK_UNKNOWN
:
4408 case LPFC_LINK_DOWN
:
4409 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
4413 case LPFC_HBA_READY
:
4414 /* Links up, beyond this port_type reports state */
4415 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
4417 case LPFC_HBA_ERROR
:
4418 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
4421 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
4426 spin_unlock_irq(shost
->host_lock
);
4430 * lpfc_get_host_speed - Set the value of the scsi host speed
4431 * @shost: kernel scsi host pointer.
4434 lpfc_get_host_speed(struct Scsi_Host
*shost
)
4436 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4437 struct lpfc_hba
*phba
= vport
->phba
;
4439 spin_lock_irq(shost
->host_lock
);
4441 if (lpfc_is_link_up(phba
)) {
4442 switch(phba
->fc_linkspeed
) {
4443 case LPFC_LINK_SPEED_1GHZ
:
4444 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
4446 case LPFC_LINK_SPEED_2GHZ
:
4447 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
4449 case LPFC_LINK_SPEED_4GHZ
:
4450 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
4452 case LPFC_LINK_SPEED_8GHZ
:
4453 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
4455 case LPFC_LINK_SPEED_10GHZ
:
4456 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
4458 case LPFC_LINK_SPEED_16GHZ
:
4459 fc_host_speed(shost
) = FC_PORTSPEED_16GBIT
;
4462 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
4466 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
4468 spin_unlock_irq(shost
->host_lock
);
4472 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4473 * @shost: kernel scsi host pointer.
4476 lpfc_get_host_fabric_name (struct Scsi_Host
*shost
)
4478 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4479 struct lpfc_hba
*phba
= vport
->phba
;
4482 spin_lock_irq(shost
->host_lock
);
4484 if ((vport
->fc_flag
& FC_FABRIC
) ||
4485 ((phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) &&
4486 (vport
->fc_flag
& FC_PUBLIC_LOOP
)))
4487 node_name
= wwn_to_u64(phba
->fc_fabparam
.nodeName
.u
.wwn
);
4489 /* fabric is local port if there is no F/FL_Port */
4492 spin_unlock_irq(shost
->host_lock
);
4494 fc_host_fabric_name(shost
) = node_name
;
4498 * lpfc_get_stats - Return statistical information about the adapter
4499 * @shost: kernel scsi host pointer.
4502 * NULL on error for link down, no mbox pool, sli2 active,
4503 * management not allowed, memory allocation error, or mbox error.
4507 * address of the adapter host statistics
4509 static struct fc_host_statistics
*
4510 lpfc_get_stats(struct Scsi_Host
*shost
)
4512 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4513 struct lpfc_hba
*phba
= vport
->phba
;
4514 struct lpfc_sli
*psli
= &phba
->sli
;
4515 struct fc_host_statistics
*hs
= &phba
->link_stats
;
4516 struct lpfc_lnk_stat
* lso
= &psli
->lnk_stat_offsets
;
4517 LPFC_MBOXQ_t
*pmboxq
;
4519 unsigned long seconds
;
4523 * prevent udev from issuing mailbox commands until the port is
4526 if (phba
->link_state
< LPFC_LINK_DOWN
||
4527 !phba
->mbox_mem_pool
||
4528 (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
) == 0)
4531 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
4534 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4537 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
4539 pmb
= &pmboxq
->u
.mb
;
4540 pmb
->mbxCommand
= MBX_READ_STATUS
;
4541 pmb
->mbxOwner
= OWN_HOST
;
4542 pmboxq
->context1
= NULL
;
4543 pmboxq
->vport
= vport
;
4545 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
4546 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4548 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4550 if (rc
!= MBX_SUCCESS
) {
4551 if (rc
!= MBX_TIMEOUT
)
4552 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4556 memset(hs
, 0, sizeof (struct fc_host_statistics
));
4558 hs
->tx_frames
= pmb
->un
.varRdStatus
.xmitFrameCnt
;
4559 hs
->tx_words
= (pmb
->un
.varRdStatus
.xmitByteCnt
* 256);
4560 hs
->rx_frames
= pmb
->un
.varRdStatus
.rcvFrameCnt
;
4561 hs
->rx_words
= (pmb
->un
.varRdStatus
.rcvByteCnt
* 256);
4563 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
4564 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
4565 pmb
->mbxOwner
= OWN_HOST
;
4566 pmboxq
->context1
= NULL
;
4567 pmboxq
->vport
= vport
;
4569 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
4570 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4572 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4574 if (rc
!= MBX_SUCCESS
) {
4575 if (rc
!= MBX_TIMEOUT
)
4576 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4580 hs
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
4581 hs
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
4582 hs
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
4583 hs
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
4584 hs
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
4585 hs
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
4586 hs
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
4588 hs
->link_failure_count
-= lso
->link_failure_count
;
4589 hs
->loss_of_sync_count
-= lso
->loss_of_sync_count
;
4590 hs
->loss_of_signal_count
-= lso
->loss_of_signal_count
;
4591 hs
->prim_seq_protocol_err_count
-= lso
->prim_seq_protocol_err_count
;
4592 hs
->invalid_tx_word_count
-= lso
->invalid_tx_word_count
;
4593 hs
->invalid_crc_count
-= lso
->invalid_crc_count
;
4594 hs
->error_frames
-= lso
->error_frames
;
4596 if (phba
->hba_flag
& HBA_FCOE_MODE
) {
4598 hs
->nos_count
= (phba
->link_events
>> 1);
4599 hs
->nos_count
-= lso
->link_events
;
4600 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4601 hs
->lip_count
= (phba
->fc_eventTag
>> 1);
4602 hs
->lip_count
-= lso
->link_events
;
4606 hs
->nos_count
= (phba
->fc_eventTag
>> 1);
4607 hs
->nos_count
-= lso
->link_events
;
4610 hs
->dumped_frames
= -1;
4612 seconds
= get_seconds();
4613 if (seconds
< psli
->stats_start
)
4614 hs
->seconds_since_last_reset
= seconds
+
4615 ((unsigned long)-1 - psli
->stats_start
);
4617 hs
->seconds_since_last_reset
= seconds
- psli
->stats_start
;
4619 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4625 * lpfc_reset_stats - Copy the adapter link stats information
4626 * @shost: kernel scsi host pointer.
4629 lpfc_reset_stats(struct Scsi_Host
*shost
)
4631 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4632 struct lpfc_hba
*phba
= vport
->phba
;
4633 struct lpfc_sli
*psli
= &phba
->sli
;
4634 struct lpfc_lnk_stat
*lso
= &psli
->lnk_stat_offsets
;
4635 LPFC_MBOXQ_t
*pmboxq
;
4639 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
4642 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4645 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4647 pmb
= &pmboxq
->u
.mb
;
4648 pmb
->mbxCommand
= MBX_READ_STATUS
;
4649 pmb
->mbxOwner
= OWN_HOST
;
4650 pmb
->un
.varWords
[0] = 0x1; /* reset request */
4651 pmboxq
->context1
= NULL
;
4652 pmboxq
->vport
= vport
;
4654 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4655 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
4656 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4658 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4660 if (rc
!= MBX_SUCCESS
) {
4661 if (rc
!= MBX_TIMEOUT
)
4662 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4666 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4667 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
4668 pmb
->mbxOwner
= OWN_HOST
;
4669 pmboxq
->context1
= NULL
;
4670 pmboxq
->vport
= vport
;
4672 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4673 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
4674 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4676 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4678 if (rc
!= MBX_SUCCESS
) {
4679 if (rc
!= MBX_TIMEOUT
)
4680 mempool_free( pmboxq
, phba
->mbox_mem_pool
);
4684 lso
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
4685 lso
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
4686 lso
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
4687 lso
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
4688 lso
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
4689 lso
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
4690 lso
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
4691 if (phba
->hba_flag
& HBA_FCOE_MODE
)
4692 lso
->link_events
= (phba
->link_events
>> 1);
4694 lso
->link_events
= (phba
->fc_eventTag
>> 1);
4696 psli
->stats_start
= get_seconds();
4698 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4704 * The LPFC driver treats linkdown handling as target loss events so there
4705 * are no sysfs handlers for link_down_tmo.
4709 * lpfc_get_node_by_target - Return the nodelist for a target
4710 * @starget: kernel scsi target pointer.
4713 * address of the node list if found
4714 * NULL target not found
4716 static struct lpfc_nodelist
*
4717 lpfc_get_node_by_target(struct scsi_target
*starget
)
4719 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
4720 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4721 struct lpfc_nodelist
*ndlp
;
4723 spin_lock_irq(shost
->host_lock
);
4724 /* Search for this, mapped, target ID */
4725 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4726 if (NLP_CHK_NODE_ACT(ndlp
) &&
4727 ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
4728 starget
->id
== ndlp
->nlp_sid
) {
4729 spin_unlock_irq(shost
->host_lock
);
4733 spin_unlock_irq(shost
->host_lock
);
4738 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4739 * @starget: kernel scsi target pointer.
4742 lpfc_get_starget_port_id(struct scsi_target
*starget
)
4744 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
4746 fc_starget_port_id(starget
) = ndlp
? ndlp
->nlp_DID
: -1;
4750 * lpfc_get_starget_node_name - Set the target node name
4751 * @starget: kernel scsi target pointer.
4753 * Description: Set the target node name to the ndlp node name wwn or zero.
4756 lpfc_get_starget_node_name(struct scsi_target
*starget
)
4758 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
4760 fc_starget_node_name(starget
) =
4761 ndlp
? wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
) : 0;
4765 * lpfc_get_starget_port_name - Set the target port name
4766 * @starget: kernel scsi target pointer.
4768 * Description: set the target port name to the ndlp port name wwn or zero.
4771 lpfc_get_starget_port_name(struct scsi_target
*starget
)
4773 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
4775 fc_starget_port_name(starget
) =
4776 ndlp
? wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
) : 0;
4780 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4781 * @rport: fc rport address.
4782 * @timeout: new value for dev loss tmo.
4785 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4786 * dev_loss_tmo to one.
4789 lpfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
4792 rport
->dev_loss_tmo
= timeout
;
4794 rport
->dev_loss_tmo
= 1;
4798 * lpfc_rport_show_function - Return rport target information
4801 * Macro that uses field to generate a function with the name lpfc_show_rport_
4803 * lpfc_show_rport_##field: returns the bytes formatted in buf
4804 * @cdev: class converted to an fc_rport.
4805 * @buf: on return contains the target_field or zero.
4807 * Returns: size of formatted string.
4809 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4811 lpfc_show_rport_##field (struct device *dev, \
4812 struct device_attribute *attr, \
4815 struct fc_rport *rport = transport_class_to_rport(dev); \
4816 struct lpfc_rport_data *rdata = rport->hostdata; \
4817 return snprintf(buf, sz, format_string, \
4818 (rdata->target) ? cast rdata->target->field : 0); \
4821 #define lpfc_rport_rd_attr(field, format_string, sz) \
4822 lpfc_rport_show_function(field, format_string, sz, ) \
4823 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4826 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4827 * @fc_vport: The fc_vport who's symbolic name has been changed.
4830 * This function is called by the transport after the @fc_vport's symbolic name
4831 * has been changed. This function re-registers the symbolic name with the
4832 * switch to propagate the change into the fabric if the vport is active.
4835 lpfc_set_vport_symbolic_name(struct fc_vport
*fc_vport
)
4837 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
4839 if (vport
->port_state
== LPFC_VPORT_READY
)
4840 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
4844 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4845 * @phba: Pointer to lpfc_hba struct.
4847 * This function is called by the lpfc_get_cfgparam() routine to set the
4848 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4849 * log message according to the module's lpfc_log_verbose parameter setting
4850 * before hba port or vport created.
4853 lpfc_hba_log_verbose_init(struct lpfc_hba
*phba
, uint32_t verbose
)
4855 phba
->cfg_log_verbose
= verbose
;
4858 struct fc_function_template lpfc_transport_functions
= {
4859 /* fixed attributes the driver supports */
4860 .show_host_node_name
= 1,
4861 .show_host_port_name
= 1,
4862 .show_host_supported_classes
= 1,
4863 .show_host_supported_fc4s
= 1,
4864 .show_host_supported_speeds
= 1,
4865 .show_host_maxframe_size
= 1,
4866 .show_host_symbolic_name
= 1,
4868 /* dynamic attributes the driver supports */
4869 .get_host_port_id
= lpfc_get_host_port_id
,
4870 .show_host_port_id
= 1,
4872 .get_host_port_type
= lpfc_get_host_port_type
,
4873 .show_host_port_type
= 1,
4875 .get_host_port_state
= lpfc_get_host_port_state
,
4876 .show_host_port_state
= 1,
4878 /* active_fc4s is shown but doesn't change (thus no get function) */
4879 .show_host_active_fc4s
= 1,
4881 .get_host_speed
= lpfc_get_host_speed
,
4882 .show_host_speed
= 1,
4884 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
4885 .show_host_fabric_name
= 1,
4888 * The LPFC driver treats linkdown handling as target loss events
4889 * so there are no sysfs handlers for link_down_tmo.
4892 .get_fc_host_stats
= lpfc_get_stats
,
4893 .reset_fc_host_stats
= lpfc_reset_stats
,
4895 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
4896 .show_rport_maxframe_size
= 1,
4897 .show_rport_supported_classes
= 1,
4899 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
4900 .show_rport_dev_loss_tmo
= 1,
4902 .get_starget_port_id
= lpfc_get_starget_port_id
,
4903 .show_starget_port_id
= 1,
4905 .get_starget_node_name
= lpfc_get_starget_node_name
,
4906 .show_starget_node_name
= 1,
4908 .get_starget_port_name
= lpfc_get_starget_port_name
,
4909 .show_starget_port_name
= 1,
4911 .issue_fc_host_lip
= lpfc_issue_lip
,
4912 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
4913 .terminate_rport_io
= lpfc_terminate_rport_io
,
4915 .dd_fcvport_size
= sizeof(struct lpfc_vport
*),
4917 .vport_disable
= lpfc_vport_disable
,
4919 .set_vport_symbolic_name
= lpfc_set_vport_symbolic_name
,
4921 .bsg_request
= lpfc_bsg_request
,
4922 .bsg_timeout
= lpfc_bsg_timeout
,
4925 struct fc_function_template lpfc_vport_transport_functions
= {
4926 /* fixed attributes the driver supports */
4927 .show_host_node_name
= 1,
4928 .show_host_port_name
= 1,
4929 .show_host_supported_classes
= 1,
4930 .show_host_supported_fc4s
= 1,
4931 .show_host_supported_speeds
= 1,
4932 .show_host_maxframe_size
= 1,
4933 .show_host_symbolic_name
= 1,
4935 /* dynamic attributes the driver supports */
4936 .get_host_port_id
= lpfc_get_host_port_id
,
4937 .show_host_port_id
= 1,
4939 .get_host_port_type
= lpfc_get_host_port_type
,
4940 .show_host_port_type
= 1,
4942 .get_host_port_state
= lpfc_get_host_port_state
,
4943 .show_host_port_state
= 1,
4945 /* active_fc4s is shown but doesn't change (thus no get function) */
4946 .show_host_active_fc4s
= 1,
4948 .get_host_speed
= lpfc_get_host_speed
,
4949 .show_host_speed
= 1,
4951 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
4952 .show_host_fabric_name
= 1,
4955 * The LPFC driver treats linkdown handling as target loss events
4956 * so there are no sysfs handlers for link_down_tmo.
4959 .get_fc_host_stats
= lpfc_get_stats
,
4960 .reset_fc_host_stats
= lpfc_reset_stats
,
4962 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
4963 .show_rport_maxframe_size
= 1,
4964 .show_rport_supported_classes
= 1,
4966 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
4967 .show_rport_dev_loss_tmo
= 1,
4969 .get_starget_port_id
= lpfc_get_starget_port_id
,
4970 .show_starget_port_id
= 1,
4972 .get_starget_node_name
= lpfc_get_starget_node_name
,
4973 .show_starget_node_name
= 1,
4975 .get_starget_port_name
= lpfc_get_starget_port_name
,
4976 .show_starget_port_name
= 1,
4978 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
4979 .terminate_rport_io
= lpfc_terminate_rport_io
,
4981 .vport_disable
= lpfc_vport_disable
,
4983 .set_vport_symbolic_name
= lpfc_set_vport_symbolic_name
,
4987 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4988 * @phba: lpfc_hba pointer.
4991 lpfc_get_cfgparam(struct lpfc_hba
*phba
)
4993 lpfc_cr_delay_init(phba
, lpfc_cr_delay
);
4994 lpfc_cr_count_init(phba
, lpfc_cr_count
);
4995 lpfc_multi_ring_support_init(phba
, lpfc_multi_ring_support
);
4996 lpfc_multi_ring_rctl_init(phba
, lpfc_multi_ring_rctl
);
4997 lpfc_multi_ring_type_init(phba
, lpfc_multi_ring_type
);
4998 lpfc_ack0_init(phba
, lpfc_ack0
);
4999 lpfc_topology_init(phba
, lpfc_topology
);
5000 lpfc_link_speed_init(phba
, lpfc_link_speed
);
5001 lpfc_poll_tmo_init(phba
, lpfc_poll_tmo
);
5002 lpfc_enable_npiv_init(phba
, lpfc_enable_npiv
);
5003 lpfc_fcf_failover_policy_init(phba
, lpfc_fcf_failover_policy
);
5004 lpfc_enable_rrq_init(phba
, lpfc_enable_rrq
);
5005 lpfc_use_msi_init(phba
, lpfc_use_msi
);
5006 lpfc_fcp_imax_init(phba
, lpfc_fcp_imax
);
5007 lpfc_fcp_wq_count_init(phba
, lpfc_fcp_wq_count
);
5008 lpfc_fcp_eq_count_init(phba
, lpfc_fcp_eq_count
);
5009 lpfc_enable_hba_reset_init(phba
, lpfc_enable_hba_reset
);
5010 lpfc_enable_hba_heartbeat_init(phba
, lpfc_enable_hba_heartbeat
);
5011 lpfc_enable_bg_init(phba
, lpfc_enable_bg
);
5012 if (phba
->sli_rev
== LPFC_SLI_REV4
)
5015 phba
->cfg_poll
= lpfc_poll
;
5016 phba
->cfg_soft_wwnn
= 0L;
5017 phba
->cfg_soft_wwpn
= 0L;
5018 lpfc_sg_seg_cnt_init(phba
, lpfc_sg_seg_cnt
);
5019 lpfc_prot_sg_seg_cnt_init(phba
, lpfc_prot_sg_seg_cnt
);
5020 lpfc_hba_queue_depth_init(phba
, lpfc_hba_queue_depth
);
5021 lpfc_hba_log_verbose_init(phba
, lpfc_log_verbose
);
5022 lpfc_aer_support_init(phba
, lpfc_aer_support
);
5023 lpfc_sriov_nr_virtfn_init(phba
, lpfc_sriov_nr_virtfn
);
5024 lpfc_suppress_link_up_init(phba
, lpfc_suppress_link_up
);
5025 lpfc_iocb_cnt_init(phba
, lpfc_iocb_cnt
);
5026 phba
->cfg_enable_dss
= 1;
5031 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5032 * @vport: lpfc_vport pointer.
5035 lpfc_get_vport_cfgparam(struct lpfc_vport
*vport
)
5037 lpfc_log_verbose_init(vport
, lpfc_log_verbose
);
5038 lpfc_lun_queue_depth_init(vport
, lpfc_lun_queue_depth
);
5039 lpfc_tgt_queue_depth_init(vport
, lpfc_tgt_queue_depth
);
5040 lpfc_devloss_tmo_init(vport
, lpfc_devloss_tmo
);
5041 lpfc_nodev_tmo_init(vport
, lpfc_nodev_tmo
);
5042 lpfc_peer_port_login_init(vport
, lpfc_peer_port_login
);
5043 lpfc_restrict_login_init(vport
, lpfc_restrict_login
);
5044 lpfc_fcp_class_init(vport
, lpfc_fcp_class
);
5045 lpfc_use_adisc_init(vport
, lpfc_use_adisc
);
5046 lpfc_max_scsicmpl_time_init(vport
, lpfc_max_scsicmpl_time
);
5047 lpfc_fdmi_on_init(vport
, lpfc_fdmi_on
);
5048 lpfc_discovery_threads_init(vport
, lpfc_discovery_threads
);
5049 lpfc_max_luns_init(vport
, lpfc_max_luns
);
5050 lpfc_scan_down_init(vport
, lpfc_scan_down
);
5051 lpfc_enable_da_id_init(vport
, lpfc_enable_da_id
);