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 * Write key size should be multiple of 4. If write key is changed
58 * make sure that library write key is also changed.
60 #define LPFC_REG_WRITE_KEY_SIZE 4
61 #define LPFC_REG_WRITE_KEY "EMLX"
64 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
65 * @incr: integer to convert.
66 * @hdw: ascii string holding converted integer plus a string terminator.
69 * JEDEC Joint Electron Device Engineering Council.
70 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71 * character string. The string is then terminated with a NULL in byte 9.
72 * Hex 0-9 becomes ascii '0' to '9'.
73 * Hex a-f becomes ascii '=' to 'B' capital B.
76 * Coded for 32 bit integers only.
79 lpfc_jedec_to_ascii(int incr
, char hdw
[])
82 for (i
= 0; i
< 8; i
++) {
85 hdw
[7 - i
] = 0x30 + j
;
87 hdw
[7 - i
] = 0x61 + j
- 10;
95 * lpfc_drvr_version_show - Return the Emulex driver string with version number
96 * @dev: class unused variable.
97 * @attr: device attribute, not used.
98 * @buf: on return contains the module description text.
100 * Returns: size of formatted string.
103 lpfc_drvr_version_show(struct device
*dev
, struct device_attribute
*attr
,
106 return snprintf(buf
, PAGE_SIZE
, LPFC_MODULE_DESC
"\n");
110 * lpfc_enable_fip_show - Return the fip mode of the HBA
111 * @dev: class unused variable.
112 * @attr: device attribute, not used.
113 * @buf: on return contains the module description text.
115 * Returns: size of formatted string.
118 lpfc_enable_fip_show(struct device
*dev
, struct device_attribute
*attr
,
121 struct Scsi_Host
*shost
= class_to_shost(dev
);
122 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
123 struct lpfc_hba
*phba
= vport
->phba
;
125 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
126 return snprintf(buf
, PAGE_SIZE
, "1\n");
128 return snprintf(buf
, PAGE_SIZE
, "0\n");
132 lpfc_bg_info_show(struct device
*dev
, struct device_attribute
*attr
,
135 struct Scsi_Host
*shost
= class_to_shost(dev
);
136 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
137 struct lpfc_hba
*phba
= vport
->phba
;
139 if (phba
->cfg_enable_bg
)
140 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
141 return snprintf(buf
, PAGE_SIZE
, "BlockGuard Enabled\n");
143 return snprintf(buf
, PAGE_SIZE
,
144 "BlockGuard Not Supported\n");
146 return snprintf(buf
, PAGE_SIZE
,
147 "BlockGuard Disabled\n");
151 lpfc_bg_guard_err_show(struct device
*dev
, struct device_attribute
*attr
,
154 struct Scsi_Host
*shost
= class_to_shost(dev
);
155 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
156 struct lpfc_hba
*phba
= vport
->phba
;
158 return snprintf(buf
, PAGE_SIZE
, "%llu\n",
159 (unsigned long long)phba
->bg_guard_err_cnt
);
163 lpfc_bg_apptag_err_show(struct device
*dev
, struct device_attribute
*attr
,
166 struct Scsi_Host
*shost
= class_to_shost(dev
);
167 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
168 struct lpfc_hba
*phba
= vport
->phba
;
170 return snprintf(buf
, PAGE_SIZE
, "%llu\n",
171 (unsigned long long)phba
->bg_apptag_err_cnt
);
175 lpfc_bg_reftag_err_show(struct device
*dev
, struct device_attribute
*attr
,
178 struct Scsi_Host
*shost
= class_to_shost(dev
);
179 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
180 struct lpfc_hba
*phba
= vport
->phba
;
182 return snprintf(buf
, PAGE_SIZE
, "%llu\n",
183 (unsigned long long)phba
->bg_reftag_err_cnt
);
187 * lpfc_info_show - Return some pci info about the host in ascii
188 * @dev: class converted to a Scsi_host structure.
189 * @attr: device attribute, not used.
190 * @buf: on return contains the formatted text from lpfc_info().
192 * Returns: size of formatted string.
195 lpfc_info_show(struct device
*dev
, struct device_attribute
*attr
,
198 struct Scsi_Host
*host
= class_to_shost(dev
);
200 return snprintf(buf
, PAGE_SIZE
, "%s\n",lpfc_info(host
));
204 * lpfc_serialnum_show - Return the hba serial number in ascii
205 * @dev: class converted to a Scsi_host structure.
206 * @attr: device attribute, not used.
207 * @buf: on return contains the formatted text serial number.
209 * Returns: size of formatted string.
212 lpfc_serialnum_show(struct device
*dev
, struct device_attribute
*attr
,
215 struct Scsi_Host
*shost
= class_to_shost(dev
);
216 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
217 struct lpfc_hba
*phba
= vport
->phba
;
219 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->SerialNumber
);
223 * lpfc_temp_sensor_show - Return the temperature sensor level
224 * @dev: class converted to a Scsi_host structure.
225 * @attr: device attribute, not used.
226 * @buf: on return contains the formatted support level.
229 * Returns a number indicating the temperature sensor level currently
230 * supported, zero or one in ascii.
232 * Returns: size of formatted string.
235 lpfc_temp_sensor_show(struct device
*dev
, struct device_attribute
*attr
,
238 struct Scsi_Host
*shost
= class_to_shost(dev
);
239 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
240 struct lpfc_hba
*phba
= vport
->phba
;
241 return snprintf(buf
, PAGE_SIZE
, "%d\n",phba
->temp_sensor_support
);
245 * lpfc_modeldesc_show - Return the model description of the hba
246 * @dev: class converted to a Scsi_host structure.
247 * @attr: device attribute, not used.
248 * @buf: on return contains the scsi vpd model description.
250 * Returns: size of formatted string.
253 lpfc_modeldesc_show(struct device
*dev
, struct device_attribute
*attr
,
256 struct Scsi_Host
*shost
= class_to_shost(dev
);
257 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
258 struct lpfc_hba
*phba
= vport
->phba
;
260 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelDesc
);
264 * lpfc_modelname_show - Return the model name of the hba
265 * @dev: class converted to a Scsi_host structure.
266 * @attr: device attribute, not used.
267 * @buf: on return contains the scsi vpd model name.
269 * Returns: size of formatted string.
272 lpfc_modelname_show(struct device
*dev
, struct device_attribute
*attr
,
275 struct Scsi_Host
*shost
= class_to_shost(dev
);
276 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
277 struct lpfc_hba
*phba
= vport
->phba
;
279 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelName
);
283 * lpfc_programtype_show - Return the program type of the hba
284 * @dev: class converted to a Scsi_host structure.
285 * @attr: device attribute, not used.
286 * @buf: on return contains the scsi vpd program type.
288 * Returns: size of formatted string.
291 lpfc_programtype_show(struct device
*dev
, struct device_attribute
*attr
,
294 struct Scsi_Host
*shost
= class_to_shost(dev
);
295 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
296 struct lpfc_hba
*phba
= vport
->phba
;
298 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ProgramType
);
302 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
303 * @dev: class converted to a Scsi_host structure.
304 * @attr: device attribute, not used.
305 * @buf: on return contains the Menlo Maintenance sli flag.
307 * Returns: size of formatted string.
310 lpfc_mlomgmt_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
312 struct Scsi_Host
*shost
= class_to_shost(dev
);
313 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
314 struct lpfc_hba
*phba
= vport
->phba
;
316 return snprintf(buf
, PAGE_SIZE
, "%d\n",
317 (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
));
321 * lpfc_vportnum_show - Return the port number in ascii of the hba
322 * @dev: class converted to a Scsi_host structure.
323 * @attr: device attribute, not used.
324 * @buf: on return contains scsi vpd program type.
326 * Returns: size of formatted string.
329 lpfc_vportnum_show(struct device
*dev
, struct device_attribute
*attr
,
332 struct Scsi_Host
*shost
= class_to_shost(dev
);
333 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
334 struct lpfc_hba
*phba
= vport
->phba
;
336 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->Port
);
340 * lpfc_fwrev_show - Return the firmware rev running in the hba
341 * @dev: class converted to a Scsi_host structure.
342 * @attr: device attribute, not used.
343 * @buf: on return contains the scsi vpd program type.
345 * Returns: size of formatted string.
348 lpfc_fwrev_show(struct device
*dev
, struct device_attribute
*attr
,
351 struct Scsi_Host
*shost
= class_to_shost(dev
);
352 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
353 struct lpfc_hba
*phba
= vport
->phba
;
356 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
357 return snprintf(buf
, PAGE_SIZE
, "%s, sli-%d\n", fwrev
, phba
->sli_rev
);
361 * lpfc_hdw_show - Return the jedec information about the hba
362 * @dev: class converted to a Scsi_host structure.
363 * @attr: device attribute, not used.
364 * @buf: on return contains the scsi vpd program type.
366 * Returns: size of formatted string.
369 lpfc_hdw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
372 struct Scsi_Host
*shost
= class_to_shost(dev
);
373 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
374 struct lpfc_hba
*phba
= vport
->phba
;
375 lpfc_vpd_t
*vp
= &phba
->vpd
;
377 lpfc_jedec_to_ascii(vp
->rev
.biuRev
, hdw
);
378 return snprintf(buf
, PAGE_SIZE
, "%s\n", hdw
);
382 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
383 * @dev: class converted to a Scsi_host structure.
384 * @attr: device attribute, not used.
385 * @buf: on return contains the ROM and FCode ascii strings.
387 * Returns: size of formatted string.
390 lpfc_option_rom_version_show(struct device
*dev
, struct device_attribute
*attr
,
393 struct Scsi_Host
*shost
= class_to_shost(dev
);
394 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
395 struct lpfc_hba
*phba
= vport
->phba
;
397 return snprintf(buf
, PAGE_SIZE
, "%s\n", phba
->OptionROMVersion
);
401 * lpfc_state_show - Return the link state of the port
402 * @dev: class converted to a Scsi_host structure.
403 * @attr: device attribute, not used.
404 * @buf: on return contains text describing the state of the link.
407 * The switch statement has no default so zero will be returned.
409 * Returns: size of formatted string.
412 lpfc_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
415 struct Scsi_Host
*shost
= class_to_shost(dev
);
416 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
417 struct lpfc_hba
*phba
= vport
->phba
;
420 switch (phba
->link_state
) {
421 case LPFC_LINK_UNKNOWN
:
422 case LPFC_WARM_START
:
423 case LPFC_INIT_START
:
424 case LPFC_INIT_MBX_CMDS
:
427 if (phba
->hba_flag
& LINK_DISABLED
)
428 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
429 "Link Down - User disabled\n");
431 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
437 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Up - ");
439 switch (vport
->port_state
) {
440 case LPFC_LOCAL_CFG_LINK
:
441 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
442 "Configuring Link\n");
446 case LPFC_FABRIC_CFG_LINK
:
449 case LPFC_BUILD_DISC_LIST
:
451 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
454 case LPFC_VPORT_READY
:
455 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Ready\n");
458 case LPFC_VPORT_FAILED
:
459 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Failed\n");
462 case LPFC_VPORT_UNKNOWN
:
463 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
467 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)
468 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
469 " Menlo Maint Mode\n");
470 else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
471 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
472 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
475 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
478 if (vport
->fc_flag
& FC_FABRIC
)
479 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
482 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
491 * lpfc_link_state_store - Transition the link_state on an HBA port
492 * @dev: class device that is converted into a Scsi_host.
493 * @attr: device attribute, not used.
494 * @buf: one or more lpfc_polling_flags values.
498 * -EINVAL if the buffer is not "up" or "down"
499 * return from link state change function if non-zero
500 * length of the buf on success
503 lpfc_link_state_store(struct device
*dev
, struct device_attribute
*attr
,
504 const char *buf
, size_t count
)
506 struct Scsi_Host
*shost
= class_to_shost(dev
);
507 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
508 struct lpfc_hba
*phba
= vport
->phba
;
510 int status
= -EINVAL
;
512 if ((strncmp(buf
, "up", sizeof("up") - 1) == 0) &&
513 (phba
->link_state
== LPFC_LINK_DOWN
))
514 status
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
515 else if ((strncmp(buf
, "down", sizeof("down") - 1) == 0) &&
516 (phba
->link_state
>= LPFC_LINK_UP
))
517 status
= phba
->lpfc_hba_down_link(phba
, MBX_NOWAIT
);
526 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
527 * @dev: class device that is converted into a Scsi_host.
528 * @attr: device attribute, not used.
529 * @buf: on return contains the sum of fc mapped and unmapped.
532 * Returns the ascii text number of the sum of the fc mapped and unmapped
535 * Returns: size of formatted string.
538 lpfc_num_discovered_ports_show(struct device
*dev
,
539 struct device_attribute
*attr
, char *buf
)
541 struct Scsi_Host
*shost
= class_to_shost(dev
);
542 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
544 return snprintf(buf
, PAGE_SIZE
, "%d\n",
545 vport
->fc_map_cnt
+ vport
->fc_unmap_cnt
);
549 * lpfc_issue_lip - Misnomer, name carried over from long ago
550 * @shost: Scsi_Host pointer.
553 * Bring the link down gracefully then re-init the link. The firmware will
554 * re-init the fiber channel interface as required. Does not issue a LIP.
557 * -EPERM port offline or management commands are being blocked
558 * -ENOMEM cannot allocate memory for the mailbox command
559 * -EIO error sending the mailbox command
563 lpfc_issue_lip(struct Scsi_Host
*shost
)
565 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
566 struct lpfc_hba
*phba
= vport
->phba
;
567 LPFC_MBOXQ_t
*pmboxq
;
568 int mbxstatus
= MBXERR_ERROR
;
570 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
571 (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
))
574 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
579 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
580 pmboxq
->u
.mb
.mbxCommand
= MBX_DOWN_LINK
;
581 pmboxq
->u
.mb
.mbxOwner
= OWN_HOST
;
583 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
* 2);
585 if ((mbxstatus
== MBX_SUCCESS
) &&
586 (pmboxq
->u
.mb
.mbxStatus
== 0 ||
587 pmboxq
->u
.mb
.mbxStatus
== MBXERR_LINK_DOWN
)) {
588 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
589 lpfc_init_link(phba
, pmboxq
, phba
->cfg_topology
,
590 phba
->cfg_link_speed
);
591 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
593 if ((mbxstatus
== MBX_SUCCESS
) &&
594 (pmboxq
->u
.mb
.mbxStatus
== MBXERR_SEC_NO_PERMISSION
))
595 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
596 "2859 SLI authentication is required "
597 "for INIT_LINK but has not done yet\n");
600 lpfc_set_loopback_flag(phba
);
601 if (mbxstatus
!= MBX_TIMEOUT
)
602 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
604 if (mbxstatus
== MBXERR_ERROR
)
611 * lpfc_do_offline - Issues a mailbox command to bring the link down
612 * @phba: lpfc_hba pointer.
613 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
616 * Assumes any error from lpfc_do_offline() will be negative.
617 * Can wait up to 5 seconds for the port ring buffers count
618 * to reach zero, prints a warning if it is not zero and continues.
619 * lpfc_workq_post_event() returns a non-zero return code if call fails.
622 * -EIO error posting the event
626 lpfc_do_offline(struct lpfc_hba
*phba
, uint32_t type
)
628 struct completion online_compl
;
629 struct lpfc_sli_ring
*pring
;
630 struct lpfc_sli
*psli
;
636 init_completion(&online_compl
);
637 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
638 LPFC_EVT_OFFLINE_PREP
);
642 wait_for_completion(&online_compl
);
649 /* Wait a little for things to settle down, but not
650 * long enough for dev loss timeout to expire.
652 for (i
= 0; i
< psli
->num_rings
; i
++) {
653 pring
= &psli
->ring
[i
];
654 while (pring
->txcmplq_cnt
) {
656 if (cnt
++ > 500) { /* 5 secs */
657 lpfc_printf_log(phba
,
658 KERN_WARNING
, LOG_INIT
,
659 "0466 Outstanding IO when "
660 "bringing Adapter offline\n");
666 init_completion(&online_compl
);
667 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
, type
);
671 wait_for_completion(&online_compl
);
680 * lpfc_selective_reset - Offline then onlines the port
681 * @phba: lpfc_hba pointer.
684 * If the port is configured to allow a reset then the hba is brought
685 * offline then online.
688 * Assumes any error from lpfc_do_offline() will be negative.
689 * Do not make this function static.
692 * lpfc_do_offline() return code if not zero
693 * -EIO reset not configured or error posting the event
697 lpfc_selective_reset(struct lpfc_hba
*phba
)
699 struct completion online_compl
;
703 if (!phba
->cfg_enable_hba_reset
)
706 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
711 init_completion(&online_compl
);
712 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
717 wait_for_completion(&online_compl
);
726 * lpfc_issue_reset - Selectively resets an adapter
727 * @dev: class device that is converted into a Scsi_host.
728 * @attr: device attribute, not used.
729 * @buf: containing the string "selective".
730 * @count: unused variable.
733 * If the buf contains the string "selective" then lpfc_selective_reset()
734 * is called to perform the reset.
737 * Assumes any error from lpfc_selective_reset() will be negative.
738 * If lpfc_selective_reset() returns zero then the length of the buffer
739 * is returned which indicates success
742 * -EINVAL if the buffer does not contain the string "selective"
743 * length of buf if lpfc-selective_reset() if the call succeeds
744 * return value of lpfc_selective_reset() if the call fails
747 lpfc_issue_reset(struct device
*dev
, struct device_attribute
*attr
,
748 const char *buf
, size_t count
)
750 struct Scsi_Host
*shost
= class_to_shost(dev
);
751 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
752 struct lpfc_hba
*phba
= vport
->phba
;
754 int status
= -EINVAL
;
756 if (strncmp(buf
, "selective", sizeof("selective") - 1) == 0)
757 status
= phba
->lpfc_selective_reset(phba
);
766 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
767 * @phba: lpfc_hba pointer.
770 * SLI4 interface type-2 device to wait on the sliport status register for
771 * the readyness after performing a firmware reset.
777 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba
*phba
)
779 struct lpfc_register portstat_reg
= {0};
783 lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
784 &portstat_reg
.word0
);
786 /* verify if privilaged for the request operation */
787 if (!bf_get(lpfc_sliport_status_rn
, &portstat_reg
) &&
788 !bf_get(lpfc_sliport_status_err
, &portstat_reg
))
791 /* wait for the SLI port firmware ready after firmware reset */
792 for (i
= 0; i
< LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT
; i
++) {
794 lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
795 &portstat_reg
.word0
);
796 if (!bf_get(lpfc_sliport_status_err
, &portstat_reg
))
798 if (!bf_get(lpfc_sliport_status_rn
, &portstat_reg
))
800 if (!bf_get(lpfc_sliport_status_rdy
, &portstat_reg
))
805 if (i
< LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT
)
812 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
813 * @phba: lpfc_hba pointer.
816 * Request SLI4 interface type-2 device to perform a physical register set
823 lpfc_sli4_pdev_reg_request(struct lpfc_hba
*phba
, uint32_t opcode
)
825 struct completion online_compl
;
826 struct pci_dev
*pdev
= phba
->pcidev
;
831 if (!phba
->cfg_enable_hba_reset
)
834 if ((phba
->sli_rev
< LPFC_SLI_REV4
) ||
835 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
836 LPFC_SLI_INTF_IF_TYPE_2
))
839 /* Disable SR-IOV virtual functions if enabled */
840 if (phba
->cfg_sriov_nr_virtfn
) {
841 pci_disable_sriov(pdev
);
842 phba
->cfg_sriov_nr_virtfn
= 0;
844 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
849 /* wait for the device to be quiesced before firmware reset */
852 reg_val
= readl(phba
->sli4_hba
.conf_regs_memmap_p
+
853 LPFC_CTL_PDEV_CTL_OFFSET
);
855 if (opcode
== LPFC_FW_DUMP
)
856 reg_val
|= LPFC_FW_DUMP_REQUEST
;
857 else if (opcode
== LPFC_FW_RESET
)
858 reg_val
|= LPFC_CTL_PDEV_CTL_FRST
;
859 else if (opcode
== LPFC_DV_RESET
)
860 reg_val
|= LPFC_CTL_PDEV_CTL_DRST
;
862 writel(reg_val
, phba
->sli4_hba
.conf_regs_memmap_p
+
863 LPFC_CTL_PDEV_CTL_OFFSET
);
865 readl(phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_CTL_PDEV_CTL_OFFSET
);
867 /* delay driver action following IF_TYPE_2 reset */
868 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
873 init_completion(&online_compl
);
874 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
879 wait_for_completion(&online_compl
);
888 * lpfc_nport_evt_cnt_show - Return the number of nport events
889 * @dev: class device that is converted into a Scsi_host.
890 * @attr: device attribute, not used.
891 * @buf: on return contains the ascii number of nport events.
893 * Returns: size of formatted string.
896 lpfc_nport_evt_cnt_show(struct device
*dev
, struct device_attribute
*attr
,
899 struct Scsi_Host
*shost
= class_to_shost(dev
);
900 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
901 struct lpfc_hba
*phba
= vport
->phba
;
903 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->nport_event_cnt
);
907 * lpfc_board_mode_show - Return the state of the board
908 * @dev: class device that is converted into a Scsi_host.
909 * @attr: device attribute, not used.
910 * @buf: on return contains the state of the adapter.
912 * Returns: size of formatted string.
915 lpfc_board_mode_show(struct device
*dev
, struct device_attribute
*attr
,
918 struct Scsi_Host
*shost
= class_to_shost(dev
);
919 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
920 struct lpfc_hba
*phba
= vport
->phba
;
923 if (phba
->link_state
== LPFC_HBA_ERROR
)
925 else if (phba
->link_state
== LPFC_WARM_START
)
926 state
= "warm start";
927 else if (phba
->link_state
== LPFC_INIT_START
)
932 return snprintf(buf
, PAGE_SIZE
, "%s\n", state
);
936 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
937 * @dev: class device that is converted into a Scsi_host.
938 * @attr: device attribute, not used.
939 * @buf: containing one of the strings "online", "offline", "warm" or "error".
940 * @count: unused variable.
943 * -EACCES if enable hba reset not enabled
944 * -EINVAL if the buffer does not contain a valid string (see above)
945 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
946 * buf length greater than zero indicates success
949 lpfc_board_mode_store(struct device
*dev
, struct device_attribute
*attr
,
950 const char *buf
, size_t count
)
952 struct Scsi_Host
*shost
= class_to_shost(dev
);
953 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
954 struct lpfc_hba
*phba
= vport
->phba
;
955 struct completion online_compl
;
959 if (!phba
->cfg_enable_hba_reset
)
962 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
963 "3050 lpfc_board_mode set to %s\n", buf
);
965 init_completion(&online_compl
);
967 if(strncmp(buf
, "online", sizeof("online") - 1) == 0) {
968 rc
= lpfc_workq_post_event(phba
, &status
, &online_compl
,
972 wait_for_completion(&online_compl
);
973 } else if (strncmp(buf
, "offline", sizeof("offline") - 1) == 0)
974 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
975 else if (strncmp(buf
, "warm", sizeof("warm") - 1) == 0)
976 if (phba
->sli_rev
== LPFC_SLI_REV4
)
979 status
= lpfc_do_offline(phba
, LPFC_EVT_WARM_START
);
980 else if (strncmp(buf
, "error", sizeof("error") - 1) == 0)
981 if (phba
->sli_rev
== LPFC_SLI_REV4
)
984 status
= lpfc_do_offline(phba
, LPFC_EVT_KILL
);
985 else if (strncmp(buf
, "dump", sizeof("dump") - 1) == 0)
986 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_FW_DUMP
);
987 else if (strncmp(buf
, "fw_reset", sizeof("fw_reset") - 1) == 0)
988 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_FW_RESET
);
989 else if (strncmp(buf
, "dv_reset", sizeof("dv_reset") - 1) == 0)
990 status
= lpfc_sli4_pdev_reg_request(phba
, LPFC_DV_RESET
);
1001 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1002 * @phba: pointer to the adapter structure.
1003 * @mxri: max xri count.
1004 * @axri: available xri count.
1005 * @mrpi: max rpi count.
1006 * @arpi: available rpi count.
1007 * @mvpi: max vpi count.
1008 * @avpi: available vpi count.
1011 * If an integer pointer for an count is not null then the value for the
1012 * count is returned.
1019 lpfc_get_hba_info(struct lpfc_hba
*phba
,
1020 uint32_t *mxri
, uint32_t *axri
,
1021 uint32_t *mrpi
, uint32_t *arpi
,
1022 uint32_t *mvpi
, uint32_t *avpi
)
1024 struct lpfc_mbx_read_config
*rd_config
;
1025 LPFC_MBOXQ_t
*pmboxq
;
1031 * prevent udev from issuing mailbox commands until the port is
1034 if (phba
->link_state
< LPFC_LINK_DOWN
||
1035 !phba
->mbox_mem_pool
||
1036 (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
) == 0)
1039 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
1042 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1045 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
1047 pmb
= &pmboxq
->u
.mb
;
1048 pmb
->mbxCommand
= MBX_READ_CONFIG
;
1049 pmb
->mbxOwner
= OWN_HOST
;
1050 pmboxq
->context1
= NULL
;
1052 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
1053 rc
= MBX_NOT_FINISHED
;
1055 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
1057 if (rc
!= MBX_SUCCESS
) {
1058 if (rc
!= MBX_TIMEOUT
)
1059 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1063 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1064 rd_config
= &pmboxq
->u
.mqe
.un
.rd_config
;
1066 *mrpi
= bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
1068 *arpi
= bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
) -
1069 phba
->sli4_hba
.max_cfg_param
.rpi_used
;
1071 *mxri
= bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
1073 *axri
= bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
) -
1074 phba
->sli4_hba
.max_cfg_param
.xri_used
;
1076 /* Account for differences with SLI-3. Get vpi count from
1077 * mailbox data and subtract one for max vpi value.
1079 max_vpi
= (bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
) > 0) ?
1080 (bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
) - 1) : 0;
1085 *avpi
= max_vpi
- phba
->sli4_hba
.max_cfg_param
.vpi_used
;
1088 *mrpi
= pmb
->un
.varRdConfig
.max_rpi
;
1090 *arpi
= pmb
->un
.varRdConfig
.avail_rpi
;
1092 *mxri
= pmb
->un
.varRdConfig
.max_xri
;
1094 *axri
= pmb
->un
.varRdConfig
.avail_xri
;
1096 *mvpi
= pmb
->un
.varRdConfig
.max_vpi
;
1098 *avpi
= pmb
->un
.varRdConfig
.avail_vpi
;
1101 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1106 * lpfc_max_rpi_show - Return maximum rpi
1107 * @dev: class device that is converted into a Scsi_host.
1108 * @attr: device attribute, not used.
1109 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1112 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1113 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1114 * to "Unknown" and the buffer length is returned, therefore the caller
1115 * must check for "Unknown" in the buffer to detect a failure.
1117 * Returns: size of formatted string.
1120 lpfc_max_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
1123 struct Scsi_Host
*shost
= class_to_shost(dev
);
1124 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1125 struct lpfc_hba
*phba
= vport
->phba
;
1128 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, NULL
, NULL
, NULL
))
1129 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
1130 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1134 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1135 * @dev: class device that is converted into a Scsi_host.
1136 * @attr: device attribute, not used.
1137 * @buf: containing the used rpi count in decimal or "Unknown".
1140 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1141 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1142 * to "Unknown" and the buffer length is returned, therefore the caller
1143 * must check for "Unknown" in the buffer to detect a failure.
1145 * Returns: size of formatted string.
1148 lpfc_used_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
1151 struct Scsi_Host
*shost
= class_to_shost(dev
);
1152 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1153 struct lpfc_hba
*phba
= vport
->phba
;
1156 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, &acnt
, NULL
, NULL
))
1157 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
1158 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1162 * lpfc_max_xri_show - Return maximum xri
1163 * @dev: class device that is converted into a Scsi_host.
1164 * @attr: device attribute, not used.
1165 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1168 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1169 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1170 * to "Unknown" and the buffer length is returned, therefore the caller
1171 * must check for "Unknown" in the buffer to detect a failure.
1173 * Returns: size of formatted string.
1176 lpfc_max_xri_show(struct device
*dev
, struct device_attribute
*attr
,
1179 struct Scsi_Host
*shost
= class_to_shost(dev
);
1180 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1181 struct lpfc_hba
*phba
= vport
->phba
;
1184 if (lpfc_get_hba_info(phba
, &cnt
, NULL
, NULL
, NULL
, NULL
, NULL
))
1185 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
1186 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1190 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1191 * @dev: class device that is converted into a Scsi_host.
1192 * @attr: device attribute, not used.
1193 * @buf: on return contains the used xri count in decimal or "Unknown".
1196 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1197 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1198 * to "Unknown" and the buffer length is returned, therefore the caller
1199 * must check for "Unknown" in the buffer to detect a failure.
1201 * Returns: size of formatted string.
1204 lpfc_used_xri_show(struct device
*dev
, struct device_attribute
*attr
,
1207 struct Scsi_Host
*shost
= class_to_shost(dev
);
1208 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1209 struct lpfc_hba
*phba
= vport
->phba
;
1212 if (lpfc_get_hba_info(phba
, &cnt
, &acnt
, NULL
, NULL
, NULL
, NULL
))
1213 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
1214 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1218 * lpfc_max_vpi_show - Return maximum vpi
1219 * @dev: class device that is converted into a Scsi_host.
1220 * @attr: device attribute, not used.
1221 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1224 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1225 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1226 * to "Unknown" and the buffer length is returned, therefore the caller
1227 * must check for "Unknown" in the buffer to detect a failure.
1229 * Returns: size of formatted string.
1232 lpfc_max_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
1235 struct Scsi_Host
*shost
= class_to_shost(dev
);
1236 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1237 struct lpfc_hba
*phba
= vport
->phba
;
1240 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, NULL
))
1241 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
1242 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1246 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1247 * @dev: class device that is converted into a Scsi_host.
1248 * @attr: device attribute, not used.
1249 * @buf: on return contains the used vpi count in decimal or "Unknown".
1252 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1253 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1254 * to "Unknown" and the buffer length is returned, therefore the caller
1255 * must check for "Unknown" in the buffer to detect a failure.
1257 * Returns: size of formatted string.
1260 lpfc_used_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
1263 struct Scsi_Host
*shost
= class_to_shost(dev
);
1264 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1265 struct lpfc_hba
*phba
= vport
->phba
;
1268 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, &acnt
))
1269 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
1270 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
1274 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1275 * @dev: class device that is converted into a Scsi_host.
1276 * @attr: device attribute, not used.
1277 * @buf: text that must be interpreted to determine if npiv is supported.
1280 * Buffer will contain text indicating npiv is not suppoerted on the port,
1281 * the port is an NPIV physical port, or it is an npiv virtual port with
1282 * the id of the vport.
1284 * Returns: size of formatted string.
1287 lpfc_npiv_info_show(struct device
*dev
, struct device_attribute
*attr
,
1290 struct Scsi_Host
*shost
= class_to_shost(dev
);
1291 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1292 struct lpfc_hba
*phba
= vport
->phba
;
1294 if (!(phba
->max_vpi
))
1295 return snprintf(buf
, PAGE_SIZE
, "NPIV Not Supported\n");
1296 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1297 return snprintf(buf
, PAGE_SIZE
, "NPIV Physical\n");
1298 return snprintf(buf
, PAGE_SIZE
, "NPIV Virtual (VPI %d)\n", vport
->vpi
);
1302 * lpfc_poll_show - Return text about poll support for the adapter
1303 * @dev: class device that is converted into a Scsi_host.
1304 * @attr: device attribute, not used.
1305 * @buf: on return contains the cfg_poll in hex.
1308 * cfg_poll should be a lpfc_polling_flags type.
1310 * Returns: size of formatted string.
1313 lpfc_poll_show(struct device
*dev
, struct device_attribute
*attr
,
1316 struct Scsi_Host
*shost
= class_to_shost(dev
);
1317 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1318 struct lpfc_hba
*phba
= vport
->phba
;
1320 return snprintf(buf
, PAGE_SIZE
, "%#x\n", phba
->cfg_poll
);
1324 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1325 * @dev: class device that is converted into a Scsi_host.
1326 * @attr: device attribute, not used.
1327 * @buf: one or more lpfc_polling_flags values.
1331 * buf contents converted to integer and checked for a valid value.
1334 * -EINVAL if the buffer connot be converted or is out of range
1335 * length of the buf on success
1338 lpfc_poll_store(struct device
*dev
, struct device_attribute
*attr
,
1339 const char *buf
, size_t count
)
1341 struct Scsi_Host
*shost
= class_to_shost(dev
);
1342 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1343 struct lpfc_hba
*phba
= vport
->phba
;
1348 if (!isdigit(buf
[0]))
1351 if (sscanf(buf
, "%i", &val
) != 1)
1354 if ((val
& 0x3) != val
)
1357 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1360 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1361 "3051 lpfc_poll changed from %d to %d\n",
1362 phba
->cfg_poll
, val
);
1364 spin_lock_irq(&phba
->hbalock
);
1366 old_val
= phba
->cfg_poll
;
1368 if (val
& ENABLE_FCP_RING_POLLING
) {
1369 if ((val
& DISABLE_FCP_RING_INT
) &&
1370 !(old_val
& DISABLE_FCP_RING_INT
)) {
1371 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1372 spin_unlock_irq(&phba
->hbalock
);
1375 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
1376 writel(creg_val
, phba
->HCregaddr
);
1377 readl(phba
->HCregaddr
); /* flush */
1379 lpfc_poll_start_timer(phba
);
1381 } else if (val
!= 0x0) {
1382 spin_unlock_irq(&phba
->hbalock
);
1386 if (!(val
& DISABLE_FCP_RING_INT
) &&
1387 (old_val
& DISABLE_FCP_RING_INT
))
1389 spin_unlock_irq(&phba
->hbalock
);
1390 del_timer(&phba
->fcp_poll_timer
);
1391 spin_lock_irq(&phba
->hbalock
);
1392 if (lpfc_readl(phba
->HCregaddr
, &creg_val
)) {
1393 spin_unlock_irq(&phba
->hbalock
);
1396 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1397 writel(creg_val
, phba
->HCregaddr
);
1398 readl(phba
->HCregaddr
); /* flush */
1401 phba
->cfg_poll
= val
;
1403 spin_unlock_irq(&phba
->hbalock
);
1409 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1410 * @dev: class unused variable.
1411 * @attr: device attribute, not used.
1412 * @buf: on return contains the module description text.
1414 * Returns: size of formatted string.
1417 lpfc_fips_level_show(struct device
*dev
, struct device_attribute
*attr
,
1420 struct Scsi_Host
*shost
= class_to_shost(dev
);
1421 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1422 struct lpfc_hba
*phba
= vport
->phba
;
1424 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->fips_level
);
1428 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1429 * @dev: class unused variable.
1430 * @attr: device attribute, not used.
1431 * @buf: on return contains the module description text.
1433 * Returns: size of formatted string.
1436 lpfc_fips_rev_show(struct device
*dev
, struct device_attribute
*attr
,
1439 struct Scsi_Host
*shost
= class_to_shost(dev
);
1440 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1441 struct lpfc_hba
*phba
= vport
->phba
;
1443 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->fips_spec_rev
);
1447 * lpfc_dss_show - Return the current state of dss and the configured state
1448 * @dev: class converted to a Scsi_host structure.
1449 * @attr: device attribute, not used.
1450 * @buf: on return contains the formatted text.
1452 * Returns: size of formatted string.
1455 lpfc_dss_show(struct device
*dev
, struct device_attribute
*attr
,
1458 struct Scsi_Host
*shost
= class_to_shost(dev
);
1459 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1460 struct lpfc_hba
*phba
= vport
->phba
;
1462 return snprintf(buf
, PAGE_SIZE
, "%s - %sOperational\n",
1463 (phba
->cfg_enable_dss
) ? "Enabled" : "Disabled",
1464 (phba
->sli3_options
& LPFC_SLI3_DSS_ENABLED
) ?
1469 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1470 * @dev: class converted to a Scsi_host structure.
1471 * @attr: device attribute, not used.
1472 * @buf: on return contains the formatted support level.
1475 * Returns the maximum number of virtual functions a physical function can
1476 * support, 0 will be returned if called on virtual function.
1478 * Returns: size of formatted string.
1481 lpfc_sriov_hw_max_virtfn_show(struct device
*dev
,
1482 struct device_attribute
*attr
,
1485 struct Scsi_Host
*shost
= class_to_shost(dev
);
1486 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1487 struct lpfc_hba
*phba
= vport
->phba
;
1488 uint16_t max_nr_virtfn
;
1490 max_nr_virtfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
1491 return snprintf(buf
, PAGE_SIZE
, "%d\n", max_nr_virtfn
);
1495 * lpfc_param_show - Return a cfg attribute value in decimal
1498 * Macro that given an attr e.g. hba_queue_depth expands
1499 * into a function with the name lpfc_hba_queue_depth_show.
1501 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1502 * @dev: class device that is converted into a Scsi_host.
1503 * @attr: device attribute, not used.
1504 * @buf: on return contains the attribute value in decimal.
1506 * Returns: size of formatted string.
1508 #define lpfc_param_show(attr) \
1510 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1513 struct Scsi_Host *shost = class_to_shost(dev);\
1514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1515 struct lpfc_hba *phba = vport->phba;\
1517 val = phba->cfg_##attr;\
1518 return snprintf(buf, PAGE_SIZE, "%d\n",\
1523 * lpfc_param_hex_show - Return a cfg attribute value in hex
1526 * Macro that given an attr e.g. hba_queue_depth expands
1527 * into a function with the name lpfc_hba_queue_depth_show
1529 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1530 * @dev: class device that is converted into a Scsi_host.
1531 * @attr: device attribute, not used.
1532 * @buf: on return contains the attribute value in hexadecimal.
1534 * Returns: size of formatted string.
1536 #define lpfc_param_hex_show(attr) \
1538 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1541 struct Scsi_Host *shost = class_to_shost(dev);\
1542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1543 struct lpfc_hba *phba = vport->phba;\
1545 val = phba->cfg_##attr;\
1546 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1551 * lpfc_param_init - Initializes a cfg attribute
1554 * Macro that given an attr e.g. hba_queue_depth expands
1555 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1556 * takes a default argument, a minimum and maximum argument.
1558 * lpfc_##attr##_init: Initializes an attribute.
1559 * @phba: pointer the the adapter structure.
1560 * @val: integer attribute value.
1562 * Validates the min and max values then sets the adapter config field
1563 * accordingly, or uses the default if out of range and prints an error message.
1567 * -EINVAL if default used
1569 #define lpfc_param_init(attr, default, minval, maxval) \
1571 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1573 if (val >= minval && val <= maxval) {\
1574 phba->cfg_##attr = val;\
1577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1578 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1579 "allowed range is ["#minval", "#maxval"]\n", val); \
1580 phba->cfg_##attr = default;\
1585 * lpfc_param_set - Set a cfg attribute value
1588 * Macro that given an attr e.g. hba_queue_depth expands
1589 * into a function with the name lpfc_hba_queue_depth_set
1591 * lpfc_##attr##_set: Sets an attribute value.
1592 * @phba: pointer the the adapter structure.
1593 * @val: integer attribute value.
1596 * Validates the min and max values then sets the
1597 * adapter config field if in the valid range. prints error message
1598 * and does not set the parameter if invalid.
1602 * -EINVAL if val is invalid
1604 #define lpfc_param_set(attr, default, minval, maxval) \
1606 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1608 if (val >= minval && val <= maxval) {\
1609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1610 "3052 lpfc_" #attr " changed from %d to %d\n", \
1611 phba->cfg_##attr, val); \
1612 phba->cfg_##attr = val;\
1615 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1616 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1617 "allowed range is ["#minval", "#maxval"]\n", val); \
1622 * lpfc_param_store - Set a vport attribute value
1625 * Macro that given an attr e.g. hba_queue_depth expands
1626 * into a function with the name lpfc_hba_queue_depth_store.
1628 * lpfc_##attr##_store: Set an sttribute value.
1629 * @dev: class device that is converted into a Scsi_host.
1630 * @attr: device attribute, not used.
1631 * @buf: contains the attribute value in ascii.
1635 * Convert the ascii text number to an integer, then
1636 * use the lpfc_##attr##_set function to set the value.
1639 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1640 * length of buffer upon success.
1642 #define lpfc_param_store(attr) \
1644 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1645 const char *buf, size_t count) \
1647 struct Scsi_Host *shost = class_to_shost(dev);\
1648 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1649 struct lpfc_hba *phba = vport->phba;\
1651 if (!isdigit(buf[0]))\
1653 if (sscanf(buf, "%i", &val) != 1)\
1655 if (lpfc_##attr##_set(phba, val) == 0) \
1656 return strlen(buf);\
1662 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1665 * Macro that given an attr e.g. hba_queue_depth expands
1666 * into a function with the name lpfc_hba_queue_depth_show
1668 * lpfc_##attr##_show: prints the attribute value in decimal.
1669 * @dev: class device that is converted into a Scsi_host.
1670 * @attr: device attribute, not used.
1671 * @buf: on return contains the attribute value in decimal.
1673 * Returns: length of formatted string.
1675 #define lpfc_vport_param_show(attr) \
1677 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1680 struct Scsi_Host *shost = class_to_shost(dev);\
1681 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1683 val = vport->cfg_##attr;\
1684 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1688 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1691 * Macro that given an attr e.g.
1692 * hba_queue_depth expands into a function with the name
1693 * lpfc_hba_queue_depth_show
1695 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1696 * @dev: class device that is converted into a Scsi_host.
1697 * @attr: device attribute, not used.
1698 * @buf: on return contains the attribute value in hexadecimal.
1700 * Returns: length of formatted string.
1702 #define lpfc_vport_param_hex_show(attr) \
1704 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1707 struct Scsi_Host *shost = class_to_shost(dev);\
1708 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1710 val = vport->cfg_##attr;\
1711 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1715 * lpfc_vport_param_init - Initialize a vport cfg attribute
1718 * Macro that given an attr e.g. hba_queue_depth expands
1719 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1720 * takes a default argument, a minimum and maximum argument.
1722 * lpfc_##attr##_init: validates the min and max values then sets the
1723 * adapter config field accordingly, or uses the default if out of range
1724 * and prints an error message.
1725 * @phba: pointer the the adapter structure.
1726 * @val: integer attribute value.
1730 * -EINVAL if default used
1732 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1734 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1736 if (val >= minval && val <= maxval) {\
1737 vport->cfg_##attr = val;\
1740 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1741 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1742 "allowed range is ["#minval", "#maxval"]\n", val); \
1743 vport->cfg_##attr = default;\
1748 * lpfc_vport_param_set - Set a vport cfg attribute
1751 * Macro that given an attr e.g. hba_queue_depth expands
1752 * into a function with the name lpfc_hba_queue_depth_set
1754 * lpfc_##attr##_set: validates the min and max values then sets the
1755 * adapter config field if in the valid range. prints error message
1756 * and does not set the parameter if invalid.
1757 * @phba: pointer the the adapter structure.
1758 * @val: integer attribute value.
1762 * -EINVAL if val is invalid
1764 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1766 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1768 if (val >= minval && val <= maxval) {\
1769 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1770 "3053 lpfc_" #attr " changed from %d to %d\n", \
1771 vport->cfg_##attr, val); \
1772 vport->cfg_##attr = val;\
1775 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1776 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1777 "allowed range is ["#minval", "#maxval"]\n", val); \
1782 * lpfc_vport_param_store - Set a vport attribute
1785 * Macro that given an attr e.g. hba_queue_depth
1786 * expands into a function with the name lpfc_hba_queue_depth_store
1788 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1789 * use the lpfc_##attr##_set function to set the value.
1790 * @cdev: class device that is converted into a Scsi_host.
1791 * @buf: contains the attribute value in decimal.
1795 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1796 * length of buffer upon success.
1798 #define lpfc_vport_param_store(attr) \
1800 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1801 const char *buf, size_t count) \
1803 struct Scsi_Host *shost = class_to_shost(dev);\
1804 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1806 if (!isdigit(buf[0]))\
1808 if (sscanf(buf, "%i", &val) != 1)\
1810 if (lpfc_##attr##_set(vport, val) == 0) \
1811 return strlen(buf);\
1817 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1818 static uint lpfc_##name = defval;\
1819 module_param(lpfc_##name, uint, S_IRUGO);\
1820 MODULE_PARM_DESC(lpfc_##name, desc);\
1821 lpfc_param_init(name, defval, minval, maxval)
1823 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1824 static uint lpfc_##name = defval;\
1825 module_param(lpfc_##name, uint, S_IRUGO);\
1826 MODULE_PARM_DESC(lpfc_##name, desc);\
1827 lpfc_param_show(name)\
1828 lpfc_param_init(name, defval, minval, maxval)\
1829 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1831 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1832 static uint lpfc_##name = defval;\
1833 module_param(lpfc_##name, uint, S_IRUGO);\
1834 MODULE_PARM_DESC(lpfc_##name, desc);\
1835 lpfc_param_show(name)\
1836 lpfc_param_init(name, defval, minval, maxval)\
1837 lpfc_param_set(name, defval, minval, maxval)\
1838 lpfc_param_store(name)\
1839 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1840 lpfc_##name##_show, lpfc_##name##_store)
1842 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1843 static uint lpfc_##name = defval;\
1844 module_param(lpfc_##name, uint, S_IRUGO);\
1845 MODULE_PARM_DESC(lpfc_##name, desc);\
1846 lpfc_param_hex_show(name)\
1847 lpfc_param_init(name, defval, minval, maxval)\
1848 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1850 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1851 static uint lpfc_##name = defval;\
1852 module_param(lpfc_##name, uint, S_IRUGO);\
1853 MODULE_PARM_DESC(lpfc_##name, desc);\
1854 lpfc_param_hex_show(name)\
1855 lpfc_param_init(name, defval, minval, maxval)\
1856 lpfc_param_set(name, defval, minval, maxval)\
1857 lpfc_param_store(name)\
1858 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1859 lpfc_##name##_show, lpfc_##name##_store)
1861 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1862 static uint lpfc_##name = defval;\
1863 module_param(lpfc_##name, uint, S_IRUGO);\
1864 MODULE_PARM_DESC(lpfc_##name, desc);\
1865 lpfc_vport_param_init(name, defval, minval, maxval)
1867 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1868 static uint lpfc_##name = defval;\
1869 module_param(lpfc_##name, uint, S_IRUGO);\
1870 MODULE_PARM_DESC(lpfc_##name, desc);\
1871 lpfc_vport_param_show(name)\
1872 lpfc_vport_param_init(name, defval, minval, maxval)\
1873 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1875 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1876 static uint lpfc_##name = defval;\
1877 module_param(lpfc_##name, uint, S_IRUGO);\
1878 MODULE_PARM_DESC(lpfc_##name, desc);\
1879 lpfc_vport_param_show(name)\
1880 lpfc_vport_param_init(name, defval, minval, maxval)\
1881 lpfc_vport_param_set(name, defval, minval, maxval)\
1882 lpfc_vport_param_store(name)\
1883 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1884 lpfc_##name##_show, lpfc_##name##_store)
1886 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1887 static uint lpfc_##name = defval;\
1888 module_param(lpfc_##name, uint, S_IRUGO);\
1889 MODULE_PARM_DESC(lpfc_##name, desc);\
1890 lpfc_vport_param_hex_show(name)\
1891 lpfc_vport_param_init(name, defval, minval, maxval)\
1892 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1894 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1895 static uint lpfc_##name = defval;\
1896 module_param(lpfc_##name, uint, S_IRUGO);\
1897 MODULE_PARM_DESC(lpfc_##name, desc);\
1898 lpfc_vport_param_hex_show(name)\
1899 lpfc_vport_param_init(name, defval, minval, maxval)\
1900 lpfc_vport_param_set(name, defval, minval, maxval)\
1901 lpfc_vport_param_store(name)\
1902 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1903 lpfc_##name##_show, lpfc_##name##_store)
1905 static DEVICE_ATTR(bg_info
, S_IRUGO
, lpfc_bg_info_show
, NULL
);
1906 static DEVICE_ATTR(bg_guard_err
, S_IRUGO
, lpfc_bg_guard_err_show
, NULL
);
1907 static DEVICE_ATTR(bg_apptag_err
, S_IRUGO
, lpfc_bg_apptag_err_show
, NULL
);
1908 static DEVICE_ATTR(bg_reftag_err
, S_IRUGO
, lpfc_bg_reftag_err_show
, NULL
);
1909 static DEVICE_ATTR(info
, S_IRUGO
, lpfc_info_show
, NULL
);
1910 static DEVICE_ATTR(serialnum
, S_IRUGO
, lpfc_serialnum_show
, NULL
);
1911 static DEVICE_ATTR(modeldesc
, S_IRUGO
, lpfc_modeldesc_show
, NULL
);
1912 static DEVICE_ATTR(modelname
, S_IRUGO
, lpfc_modelname_show
, NULL
);
1913 static DEVICE_ATTR(programtype
, S_IRUGO
, lpfc_programtype_show
, NULL
);
1914 static DEVICE_ATTR(portnum
, S_IRUGO
, lpfc_vportnum_show
, NULL
);
1915 static DEVICE_ATTR(fwrev
, S_IRUGO
, lpfc_fwrev_show
, NULL
);
1916 static DEVICE_ATTR(hdw
, S_IRUGO
, lpfc_hdw_show
, NULL
);
1917 static DEVICE_ATTR(link_state
, S_IRUGO
| S_IWUSR
, lpfc_link_state_show
,
1918 lpfc_link_state_store
);
1919 static DEVICE_ATTR(option_rom_version
, S_IRUGO
,
1920 lpfc_option_rom_version_show
, NULL
);
1921 static DEVICE_ATTR(num_discovered_ports
, S_IRUGO
,
1922 lpfc_num_discovered_ports_show
, NULL
);
1923 static DEVICE_ATTR(menlo_mgmt_mode
, S_IRUGO
, lpfc_mlomgmt_show
, NULL
);
1924 static DEVICE_ATTR(nport_evt_cnt
, S_IRUGO
, lpfc_nport_evt_cnt_show
, NULL
);
1925 static DEVICE_ATTR(lpfc_drvr_version
, S_IRUGO
, lpfc_drvr_version_show
, NULL
);
1926 static DEVICE_ATTR(lpfc_enable_fip
, S_IRUGO
, lpfc_enable_fip_show
, NULL
);
1927 static DEVICE_ATTR(board_mode
, S_IRUGO
| S_IWUSR
,
1928 lpfc_board_mode_show
, lpfc_board_mode_store
);
1929 static DEVICE_ATTR(issue_reset
, S_IWUSR
, NULL
, lpfc_issue_reset
);
1930 static DEVICE_ATTR(max_vpi
, S_IRUGO
, lpfc_max_vpi_show
, NULL
);
1931 static DEVICE_ATTR(used_vpi
, S_IRUGO
, lpfc_used_vpi_show
, NULL
);
1932 static DEVICE_ATTR(max_rpi
, S_IRUGO
, lpfc_max_rpi_show
, NULL
);
1933 static DEVICE_ATTR(used_rpi
, S_IRUGO
, lpfc_used_rpi_show
, NULL
);
1934 static DEVICE_ATTR(max_xri
, S_IRUGO
, lpfc_max_xri_show
, NULL
);
1935 static DEVICE_ATTR(used_xri
, S_IRUGO
, lpfc_used_xri_show
, NULL
);
1936 static DEVICE_ATTR(npiv_info
, S_IRUGO
, lpfc_npiv_info_show
, NULL
);
1937 static DEVICE_ATTR(lpfc_temp_sensor
, S_IRUGO
, lpfc_temp_sensor_show
, NULL
);
1938 static DEVICE_ATTR(lpfc_fips_level
, S_IRUGO
, lpfc_fips_level_show
, NULL
);
1939 static DEVICE_ATTR(lpfc_fips_rev
, S_IRUGO
, lpfc_fips_rev_show
, NULL
);
1940 static DEVICE_ATTR(lpfc_dss
, S_IRUGO
, lpfc_dss_show
, NULL
);
1941 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn
, S_IRUGO
,
1942 lpfc_sriov_hw_max_virtfn_show
, NULL
);
1944 static char *lpfc_soft_wwn_key
= "C99G71SL8032A";
1947 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1948 * @dev: class device that is converted into a Scsi_host.
1949 * @attr: device attribute, not used.
1950 * @buf: containing the string lpfc_soft_wwn_key.
1951 * @count: must be size of lpfc_soft_wwn_key.
1954 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1955 * length of buf indicates success
1958 lpfc_soft_wwn_enable_store(struct device
*dev
, struct device_attribute
*attr
,
1959 const char *buf
, size_t count
)
1961 struct Scsi_Host
*shost
= class_to_shost(dev
);
1962 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1963 struct lpfc_hba
*phba
= vport
->phba
;
1964 unsigned int cnt
= count
;
1967 * We're doing a simple sanity check for soft_wwpn setting.
1968 * We require that the user write a specific key to enable
1969 * the soft_wwpn attribute to be settable. Once the attribute
1970 * is written, the enable key resets. If further updates are
1971 * desired, the key must be written again to re-enable the
1974 * The "key" is not secret - it is a hardcoded string shown
1975 * here. The intent is to protect against the random user or
1976 * application that is just writing attributes.
1979 /* count may include a LF at end of string */
1980 if (buf
[cnt
-1] == '\n')
1983 if ((cnt
!= strlen(lpfc_soft_wwn_key
)) ||
1984 (strncmp(buf
, lpfc_soft_wwn_key
, strlen(lpfc_soft_wwn_key
)) != 0))
1987 phba
->soft_wwn_enable
= 1;
1990 static DEVICE_ATTR(lpfc_soft_wwn_enable
, S_IWUSR
, NULL
,
1991 lpfc_soft_wwn_enable_store
);
1994 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1995 * @dev: class device that is converted into a Scsi_host.
1996 * @attr: device attribute, not used.
1997 * @buf: on return contains the wwpn in hexadecimal.
1999 * Returns: size of formatted string.
2002 lpfc_soft_wwpn_show(struct device
*dev
, struct device_attribute
*attr
,
2005 struct Scsi_Host
*shost
= class_to_shost(dev
);
2006 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2007 struct lpfc_hba
*phba
= vport
->phba
;
2009 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
2010 (unsigned long long)phba
->cfg_soft_wwpn
);
2014 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2015 * @dev class device that is converted into a Scsi_host.
2016 * @attr: device attribute, not used.
2017 * @buf: contains the wwpn in hexadecimal.
2018 * @count: number of wwpn bytes in buf
2021 * -EACCES hba reset not enabled, adapter over temp
2022 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2023 * -EIO error taking adapter offline or online
2024 * value of count on success
2027 lpfc_soft_wwpn_store(struct device
*dev
, struct device_attribute
*attr
,
2028 const char *buf
, size_t count
)
2030 struct Scsi_Host
*shost
= class_to_shost(dev
);
2031 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2032 struct lpfc_hba
*phba
= vport
->phba
;
2033 struct completion online_compl
;
2034 int stat1
=0, stat2
=0;
2035 unsigned int i
, j
, cnt
=count
;
2039 if (!phba
->cfg_enable_hba_reset
)
2041 spin_lock_irq(&phba
->hbalock
);
2042 if (phba
->over_temp_state
== HBA_OVER_TEMP
) {
2043 spin_unlock_irq(&phba
->hbalock
);
2046 spin_unlock_irq(&phba
->hbalock
);
2047 /* count may include a LF at end of string */
2048 if (buf
[cnt
-1] == '\n')
2051 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
2052 ((cnt
== 17) && (*buf
++ != 'x')) ||
2053 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
2056 phba
->soft_wwn_enable
= 0;
2058 memset(wwpn
, 0, sizeof(wwpn
));
2060 /* Validate and store the new name */
2061 for (i
=0, j
=0; i
< 16; i
++) {
2064 value
= hex_to_bin(*buf
++);
2066 j
= (j
<< 4) | value
;
2070 wwpn
[i
/2] = j
& 0xff;
2074 phba
->cfg_soft_wwpn
= wwn_to_u64(wwpn
);
2075 fc_host_port_name(shost
) = phba
->cfg_soft_wwpn
;
2076 if (phba
->cfg_soft_wwnn
)
2077 fc_host_node_name(shost
) = phba
->cfg_soft_wwnn
;
2079 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
2080 "lpfc%d: Reinitializing to use soft_wwpn\n", phba
->brd_no
);
2082 stat1
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
2084 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2085 "0463 lpfc_soft_wwpn attribute set failed to "
2086 "reinit adapter - %d\n", stat1
);
2087 init_completion(&online_compl
);
2088 rc
= lpfc_workq_post_event(phba
, &stat2
, &online_compl
,
2093 wait_for_completion(&online_compl
);
2095 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2096 "0464 lpfc_soft_wwpn attribute set failed to "
2097 "reinit adapter - %d\n", stat2
);
2098 return (stat1
|| stat2
) ? -EIO
: count
;
2100 static DEVICE_ATTR(lpfc_soft_wwpn
, S_IRUGO
| S_IWUSR
,\
2101 lpfc_soft_wwpn_show
, lpfc_soft_wwpn_store
);
2104 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2105 * @dev: class device that is converted into a Scsi_host.
2106 * @attr: device attribute, not used.
2107 * @buf: on return contains the wwnn in hexadecimal.
2109 * Returns: size of formatted string.
2112 lpfc_soft_wwnn_show(struct device
*dev
, struct device_attribute
*attr
,
2115 struct Scsi_Host
*shost
= class_to_shost(dev
);
2116 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2117 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
2118 (unsigned long long)phba
->cfg_soft_wwnn
);
2122 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2123 * @cdev: class device that is converted into a Scsi_host.
2124 * @buf: contains the ww node name in hexadecimal.
2125 * @count: number of wwnn bytes in buf.
2128 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2129 * value of count on success
2132 lpfc_soft_wwnn_store(struct device
*dev
, struct device_attribute
*attr
,
2133 const char *buf
, size_t count
)
2135 struct Scsi_Host
*shost
= class_to_shost(dev
);
2136 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
2137 unsigned int i
, j
, cnt
=count
;
2140 /* count may include a LF at end of string */
2141 if (buf
[cnt
-1] == '\n')
2144 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
2145 ((cnt
== 17) && (*buf
++ != 'x')) ||
2146 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
2150 * Allow wwnn to be set many times, as long as the enable is set.
2151 * However, once the wwpn is set, everything locks.
2154 memset(wwnn
, 0, sizeof(wwnn
));
2156 /* Validate and store the new name */
2157 for (i
=0, j
=0; i
< 16; i
++) {
2160 value
= hex_to_bin(*buf
++);
2162 j
= (j
<< 4) | value
;
2166 wwnn
[i
/2] = j
& 0xff;
2170 phba
->cfg_soft_wwnn
= wwn_to_u64(wwnn
);
2172 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
2173 "lpfc%d: soft_wwnn set. Value will take effect upon "
2174 "setting of the soft_wwpn\n", phba
->brd_no
);
2178 static DEVICE_ATTR(lpfc_soft_wwnn
, S_IRUGO
| S_IWUSR
,\
2179 lpfc_soft_wwnn_show
, lpfc_soft_wwnn_store
);
2182 static int lpfc_poll
= 0;
2183 module_param(lpfc_poll
, int, S_IRUGO
);
2184 MODULE_PARM_DESC(lpfc_poll
, "FCP ring polling mode control:"
2186 " 1 - poll with interrupts enabled"
2187 " 3 - poll and disable FCP ring interrupts");
2189 static DEVICE_ATTR(lpfc_poll
, S_IRUGO
| S_IWUSR
,
2190 lpfc_poll_show
, lpfc_poll_store
);
2192 int lpfc_sli_mode
= 0;
2193 module_param(lpfc_sli_mode
, int, S_IRUGO
);
2194 MODULE_PARM_DESC(lpfc_sli_mode
, "SLI mode selector:"
2195 " 0 - auto (SLI-3 if supported),"
2196 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2197 " 3 - select SLI-3");
2199 int lpfc_enable_npiv
= 1;
2200 module_param(lpfc_enable_npiv
, int, S_IRUGO
);
2201 MODULE_PARM_DESC(lpfc_enable_npiv
, "Enable NPIV functionality");
2202 lpfc_param_show(enable_npiv
);
2203 lpfc_param_init(enable_npiv
, 1, 0, 1);
2204 static DEVICE_ATTR(lpfc_enable_npiv
, S_IRUGO
, lpfc_enable_npiv_show
, NULL
);
2206 LPFC_ATTR_R(fcf_failover_policy
, 1, 1, 2,
2207 "FCF Fast failover=1 Priority failover=2");
2209 int lpfc_enable_rrq
;
2210 module_param(lpfc_enable_rrq
, int, S_IRUGO
);
2211 MODULE_PARM_DESC(lpfc_enable_rrq
, "Enable RRQ functionality");
2212 lpfc_param_show(enable_rrq
);
2213 lpfc_param_init(enable_rrq
, 0, 0, 1);
2214 static DEVICE_ATTR(lpfc_enable_rrq
, S_IRUGO
, lpfc_enable_rrq_show
, NULL
);
2217 # lpfc_suppress_link_up: Bring link up at initialization
2218 # 0x0 = bring link up (issue MBX_INIT_LINK)
2219 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2220 # 0x2 = never bring up link
2221 # Default value is 0.
2223 LPFC_ATTR_R(suppress_link_up
, LPFC_INITIALIZE_LINK
, LPFC_INITIALIZE_LINK
,
2224 LPFC_DELAY_INIT_LINK_INDEFINITELY
,
2225 "Suppress Link Up at initialization");
2227 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2235 lpfc_iocb_hw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2237 struct Scsi_Host
*shost
= class_to_shost(dev
);
2238 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
2240 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->iocb_max
);
2243 static DEVICE_ATTR(iocb_hw
, S_IRUGO
,
2244 lpfc_iocb_hw_show
, NULL
);
2246 lpfc_txq_hw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2248 struct Scsi_Host
*shost
= class_to_shost(dev
);
2249 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
2251 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2252 phba
->sli
.ring
[LPFC_ELS_RING
].txq_max
);
2255 static DEVICE_ATTR(txq_hw
, S_IRUGO
,
2256 lpfc_txq_hw_show
, NULL
);
2258 lpfc_txcmplq_hw_show(struct device
*dev
, struct device_attribute
*attr
,
2261 struct Scsi_Host
*shost
= class_to_shost(dev
);
2262 struct lpfc_hba
*phba
= ((struct lpfc_vport
*) shost
->hostdata
)->phba
;
2264 return snprintf(buf
, PAGE_SIZE
, "%d\n",
2265 phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_max
);
2268 static DEVICE_ATTR(txcmplq_hw
, S_IRUGO
,
2269 lpfc_txcmplq_hw_show
, NULL
);
2271 int lpfc_iocb_cnt
= 2;
2272 module_param(lpfc_iocb_cnt
, int, S_IRUGO
);
2273 MODULE_PARM_DESC(lpfc_iocb_cnt
,
2274 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2275 lpfc_param_show(iocb_cnt
);
2276 lpfc_param_init(iocb_cnt
, 2, 1, 5);
2277 static DEVICE_ATTR(lpfc_iocb_cnt
, S_IRUGO
,
2278 lpfc_iocb_cnt_show
, NULL
);
2281 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2282 # until the timer expires. Value range is [0,255]. Default value is 30.
2284 static int lpfc_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
2285 static int lpfc_devloss_tmo
= LPFC_DEF_DEVLOSS_TMO
;
2286 module_param(lpfc_nodev_tmo
, int, 0);
2287 MODULE_PARM_DESC(lpfc_nodev_tmo
,
2288 "Seconds driver will hold I/O waiting "
2289 "for a device to come back");
2292 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2293 * @dev: class converted to a Scsi_host structure.
2294 * @attr: device attribute, not used.
2295 * @buf: on return contains the dev loss timeout in decimal.
2297 * Returns: size of formatted string.
2300 lpfc_nodev_tmo_show(struct device
*dev
, struct device_attribute
*attr
,
2303 struct Scsi_Host
*shost
= class_to_shost(dev
);
2304 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2306 return snprintf(buf
, PAGE_SIZE
, "%d\n", vport
->cfg_devloss_tmo
);
2310 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2311 * @vport: lpfc vport structure pointer.
2312 * @val: contains the nodev timeout value.
2315 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2316 * a kernel error message is printed and zero is returned.
2317 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2318 * Otherwise nodev tmo is set to the default value.
2321 * zero if already set or if val is in range
2322 * -EINVAL val out of range
2325 lpfc_nodev_tmo_init(struct lpfc_vport
*vport
, int val
)
2327 if (vport
->cfg_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
) {
2328 vport
->cfg_nodev_tmo
= vport
->cfg_devloss_tmo
;
2329 if (val
!= LPFC_DEF_DEVLOSS_TMO
)
2330 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2331 "0407 Ignoring nodev_tmo module "
2332 "parameter because devloss_tmo is "
2337 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
2338 vport
->cfg_nodev_tmo
= val
;
2339 vport
->cfg_devloss_tmo
= val
;
2342 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2343 "0400 lpfc_nodev_tmo attribute cannot be set to"
2344 " %d, allowed range is [%d, %d]\n",
2345 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
2346 vport
->cfg_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
2351 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2352 * @vport: lpfc vport structure pointer.
2355 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2358 lpfc_update_rport_devloss_tmo(struct lpfc_vport
*vport
)
2360 struct Scsi_Host
*shost
;
2361 struct lpfc_nodelist
*ndlp
;
2363 shost
= lpfc_shost_from_vport(vport
);
2364 spin_lock_irq(shost
->host_lock
);
2365 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
)
2366 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
)
2367 ndlp
->rport
->dev_loss_tmo
= vport
->cfg_devloss_tmo
;
2368 spin_unlock_irq(shost
->host_lock
);
2372 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2373 * @vport: lpfc vport structure pointer.
2374 * @val: contains the tmo value.
2377 * If the devloss tmo is already set or the vport dev loss tmo has changed
2378 * then a kernel error message is printed and zero is returned.
2379 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2380 * Otherwise nodev tmo is set to the default value.
2383 * zero if already set or if val is in range
2384 * -EINVAL val out of range
2387 lpfc_nodev_tmo_set(struct lpfc_vport
*vport
, int val
)
2389 if (vport
->dev_loss_tmo_changed
||
2390 (lpfc_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
)) {
2391 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2392 "0401 Ignoring change to nodev_tmo "
2393 "because devloss_tmo is set.\n");
2396 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
2397 vport
->cfg_nodev_tmo
= val
;
2398 vport
->cfg_devloss_tmo
= val
;
2400 * For compat: set the fc_host dev loss so new rports
2401 * will get the value.
2403 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport
)) = val
;
2404 lpfc_update_rport_devloss_tmo(vport
);
2407 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2408 "0403 lpfc_nodev_tmo attribute cannot be set to"
2409 "%d, allowed range is [%d, %d]\n",
2410 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
2414 lpfc_vport_param_store(nodev_tmo
)
2416 static DEVICE_ATTR(lpfc_nodev_tmo
, S_IRUGO
| S_IWUSR
,
2417 lpfc_nodev_tmo_show
, lpfc_nodev_tmo_store
);
2420 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2421 # disappear until the timer expires. Value range is [0,255]. Default
2424 module_param(lpfc_devloss_tmo
, int, S_IRUGO
);
2425 MODULE_PARM_DESC(lpfc_devloss_tmo
,
2426 "Seconds driver will hold I/O waiting "
2427 "for a device to come back");
2428 lpfc_vport_param_init(devloss_tmo
, LPFC_DEF_DEVLOSS_TMO
,
2429 LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
)
2430 lpfc_vport_param_show(devloss_tmo
)
2433 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2434 * @vport: lpfc vport structure pointer.
2435 * @val: contains the tmo value.
2438 * If val is in a valid range then set the vport nodev tmo,
2439 * devloss tmo, also set the vport dev loss tmo changed flag.
2440 * Else a kernel error message is printed.
2443 * zero if val is in range
2444 * -EINVAL val out of range
2447 lpfc_devloss_tmo_set(struct lpfc_vport
*vport
, int val
)
2449 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
2450 vport
->cfg_nodev_tmo
= val
;
2451 vport
->cfg_devloss_tmo
= val
;
2452 vport
->dev_loss_tmo_changed
= 1;
2453 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport
)) = val
;
2454 lpfc_update_rport_devloss_tmo(vport
);
2458 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2459 "0404 lpfc_devloss_tmo attribute cannot be set to"
2460 " %d, allowed range is [%d, %d]\n",
2461 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
2465 lpfc_vport_param_store(devloss_tmo
)
2466 static DEVICE_ATTR(lpfc_devloss_tmo
, S_IRUGO
| S_IWUSR
,
2467 lpfc_devloss_tmo_show
, lpfc_devloss_tmo_store
);
2470 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2471 # deluged with LOTS of information.
2472 # You can set a bit mask to record specific types of verbose messages:
2473 # See lpfc_logmsh.h for definitions.
2475 LPFC_VPORT_ATTR_HEX_RW(log_verbose
, 0x0, 0x0, 0xffffffff,
2476 "Verbose logging bit-mask");
2479 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2480 # objects that have been registered with the nameserver after login.
2482 LPFC_VPORT_ATTR_R(enable_da_id
, 0, 0, 1,
2483 "Deregister nameserver objects before LOGO");
2486 # lun_queue_depth: This parameter is used to limit the number of outstanding
2487 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2489 LPFC_VPORT_ATTR_R(lun_queue_depth
, 30, 1, 128,
2490 "Max number of FCP commands we can queue to a specific LUN");
2493 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2494 # commands per target port. Value range is [10,65535]. Default value is 65535.
2496 LPFC_VPORT_ATTR_R(tgt_queue_depth
, 65535, 10, 65535,
2497 "Max number of FCP commands we can queue to a specific target port");
2500 # hba_queue_depth: This parameter is used to limit the number of outstanding
2501 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2502 # value is greater than the maximum number of exchanges supported by the HBA,
2503 # then maximum number of exchanges supported by the HBA is used to determine
2504 # the hba_queue_depth.
2506 LPFC_ATTR_R(hba_queue_depth
, 8192, 32, 8192,
2507 "Max number of FCP commands we can queue to a lpfc HBA");
2510 # peer_port_login: This parameter allows/prevents logins
2511 # between peer ports hosted on the same physical port.
2512 # When this parameter is set 0 peer ports of same physical port
2513 # are not allowed to login to each other.
2514 # When this parameter is set 1 peer ports of same physical port
2515 # are allowed to login to each other.
2516 # Default value of this parameter is 0.
2518 LPFC_VPORT_ATTR_R(peer_port_login
, 0, 0, 1,
2519 "Allow peer ports on the same physical port to login to each "
2523 # restrict_login: This parameter allows/prevents logins
2524 # between Virtual Ports and remote initiators.
2525 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2526 # other initiators and will attempt to PLOGI all remote ports.
2527 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2528 # remote ports and will not attempt to PLOGI to other initiators.
2529 # This parameter does not restrict to the physical port.
2530 # This parameter does not restrict logins to Fabric resident remote ports.
2531 # Default value of this parameter is 1.
2533 static int lpfc_restrict_login
= 1;
2534 module_param(lpfc_restrict_login
, int, S_IRUGO
);
2535 MODULE_PARM_DESC(lpfc_restrict_login
,
2536 "Restrict virtual ports login to remote initiators.");
2537 lpfc_vport_param_show(restrict_login
);
2540 * lpfc_restrict_login_init - Set the vport restrict login flag
2541 * @vport: lpfc vport structure pointer.
2542 * @val: contains the restrict login value.
2545 * If val is not in a valid range then log a kernel error message and set
2546 * the vport restrict login to one.
2547 * If the port type is physical clear the restrict login flag and return.
2548 * Else set the restrict login flag to val.
2551 * zero if val is in range
2552 * -EINVAL val out of range
2555 lpfc_restrict_login_init(struct lpfc_vport
*vport
, int val
)
2557 if (val
< 0 || val
> 1) {
2558 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2559 "0422 lpfc_restrict_login attribute cannot "
2560 "be set to %d, allowed range is [0, 1]\n",
2562 vport
->cfg_restrict_login
= 1;
2565 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
2566 vport
->cfg_restrict_login
= 0;
2569 vport
->cfg_restrict_login
= val
;
2574 * lpfc_restrict_login_set - Set the vport restrict login flag
2575 * @vport: lpfc vport structure pointer.
2576 * @val: contains the restrict login value.
2579 * If val is not in a valid range then log a kernel error message and set
2580 * the vport restrict login to one.
2581 * If the port type is physical and the val is not zero log a kernel
2582 * error message, clear the restrict login flag and return zero.
2583 * Else set the restrict login flag to val.
2586 * zero if val is in range
2587 * -EINVAL val out of range
2590 lpfc_restrict_login_set(struct lpfc_vport
*vport
, int val
)
2592 if (val
< 0 || val
> 1) {
2593 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2594 "0425 lpfc_restrict_login attribute cannot "
2595 "be set to %d, allowed range is [0, 1]\n",
2597 vport
->cfg_restrict_login
= 1;
2600 if (vport
->port_type
== LPFC_PHYSICAL_PORT
&& val
!= 0) {
2601 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2602 "0468 lpfc_restrict_login must be 0 for "
2603 "Physical ports.\n");
2604 vport
->cfg_restrict_login
= 0;
2607 vport
->cfg_restrict_login
= val
;
2610 lpfc_vport_param_store(restrict_login
);
2611 static DEVICE_ATTR(lpfc_restrict_login
, S_IRUGO
| S_IWUSR
,
2612 lpfc_restrict_login_show
, lpfc_restrict_login_store
);
2615 # Some disk devices have a "select ID" or "select Target" capability.
2616 # From a protocol standpoint "select ID" usually means select the
2617 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2618 # annex" which contains a table that maps a "select ID" (a number
2619 # between 0 and 7F) to an ALPA. By default, for compatibility with
2620 # older drivers, the lpfc driver scans this table from low ALPA to high
2623 # Turning on the scan-down variable (on = 1, off = 0) will
2624 # cause the lpfc driver to use an inverted table, effectively
2625 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2627 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2628 # and will not work across a fabric. Also this parameter will take
2629 # effect only in the case when ALPA map is not available.)
2631 LPFC_VPORT_ATTR_R(scan_down
, 1, 0, 1,
2632 "Start scanning for devices from highest ALPA to lowest");
2635 # lpfc_topology: link topology for init link
2636 # 0x0 = attempt loop mode then point-to-point
2637 # 0x01 = internal loopback mode
2638 # 0x02 = attempt point-to-point mode only
2639 # 0x04 = attempt loop mode only
2640 # 0x06 = attempt point-to-point mode then loop
2641 # Set point-to-point mode if you want to run as an N_Port.
2642 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2643 # Default value is 0.
2647 * lpfc_topology_set - Set the adapters topology field
2648 * @phba: lpfc_hba pointer.
2649 * @val: topology value.
2652 * If val is in a valid range then set the adapter's topology field and
2653 * issue a lip; if the lip fails reset the topology to the old value.
2655 * If the value is not in range log a kernel error message and return an error.
2658 * zero if val is in range and lip okay
2659 * non-zero return value from lpfc_issue_lip()
2660 * -EINVAL val out of range
2663 lpfc_topology_store(struct device
*dev
, struct device_attribute
*attr
,
2664 const char *buf
, size_t count
)
2666 struct Scsi_Host
*shost
= class_to_shost(dev
);
2667 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2668 struct lpfc_hba
*phba
= vport
->phba
;
2671 const char *val_buf
= buf
;
2675 if (!strncmp(buf
, "nolip ", strlen("nolip "))) {
2677 val_buf
= &buf
[strlen("nolip ")];
2680 if (!isdigit(val_buf
[0]))
2682 if (sscanf(val_buf
, "%i", &val
) != 1)
2685 if (val
>= 0 && val
<= 6) {
2686 prev_val
= phba
->cfg_topology
;
2687 phba
->cfg_topology
= val
;
2691 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2692 "3054 lpfc_topology changed from %d to %d\n",
2694 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
2696 phba
->cfg_topology
= prev_val
;
2701 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2702 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2703 "allowed range is [0, 6]\n",
2707 static int lpfc_topology
= 0;
2708 module_param(lpfc_topology
, int, S_IRUGO
);
2709 MODULE_PARM_DESC(lpfc_topology
, "Select Fibre Channel topology");
2710 lpfc_param_show(topology
)
2711 lpfc_param_init(topology
, 0, 0, 6)
2712 static DEVICE_ATTR(lpfc_topology
, S_IRUGO
| S_IWUSR
,
2713 lpfc_topology_show
, lpfc_topology_store
);
2716 * lpfc_static_vport_show: Read callback function for
2717 * lpfc_static_vport sysfs file.
2718 * @dev: Pointer to class device object.
2719 * @attr: device attribute structure.
2720 * @buf: Data buffer.
2722 * This function is the read call back function for
2723 * lpfc_static_vport sysfs file. The lpfc_static_vport
2724 * sysfs file report the mageability of the vport.
2727 lpfc_static_vport_show(struct device
*dev
, struct device_attribute
*attr
,
2730 struct Scsi_Host
*shost
= class_to_shost(dev
);
2731 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2732 if (vport
->vport_flag
& STATIC_VPORT
)
2733 sprintf(buf
, "1\n");
2735 sprintf(buf
, "0\n");
2741 * Sysfs attribute to control the statistical data collection.
2743 static DEVICE_ATTR(lpfc_static_vport
, S_IRUGO
,
2744 lpfc_static_vport_show
, NULL
);
2747 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2748 * @dev: Pointer to class device.
2749 * @buf: Data buffer.
2750 * @count: Size of the data buffer.
2752 * This function get called when an user write to the lpfc_stat_data_ctrl
2753 * sysfs file. This function parse the command written to the sysfs file
2754 * and take appropriate action. These commands are used for controlling
2755 * driver statistical data collection.
2756 * Following are the command this function handles.
2758 * setbucket <bucket_type> <base> <step>
2759 * = Set the latency buckets.
2760 * destroybucket = destroy all the buckets.
2761 * start = start data collection
2762 * stop = stop data collection
2763 * reset = reset the collected data
2766 lpfc_stat_data_ctrl_store(struct device
*dev
, struct device_attribute
*attr
,
2767 const char *buf
, size_t count
)
2769 struct Scsi_Host
*shost
= class_to_shost(dev
);
2770 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2771 struct lpfc_hba
*phba
= vport
->phba
;
2772 #define LPFC_MAX_DATA_CTRL_LEN 1024
2773 static char bucket_data
[LPFC_MAX_DATA_CTRL_LEN
];
2775 char *str_ptr
, *token
;
2776 struct lpfc_vport
**vports
;
2777 struct Scsi_Host
*v_shost
;
2778 char *bucket_type_str
, *base_str
, *step_str
;
2779 unsigned long base
, step
, bucket_type
;
2781 if (!strncmp(buf
, "setbucket", strlen("setbucket"))) {
2782 if (strlen(buf
) > (LPFC_MAX_DATA_CTRL_LEN
- 1))
2785 strcpy(bucket_data
, buf
);
2786 str_ptr
= &bucket_data
[0];
2787 /* Ignore this token - this is command token */
2788 token
= strsep(&str_ptr
, "\t ");
2792 bucket_type_str
= strsep(&str_ptr
, "\t ");
2793 if (!bucket_type_str
)
2796 if (!strncmp(bucket_type_str
, "linear", strlen("linear")))
2797 bucket_type
= LPFC_LINEAR_BUCKET
;
2798 else if (!strncmp(bucket_type_str
, "power2", strlen("power2")))
2799 bucket_type
= LPFC_POWER2_BUCKET
;
2803 base_str
= strsep(&str_ptr
, "\t ");
2806 base
= simple_strtoul(base_str
, NULL
, 0);
2808 step_str
= strsep(&str_ptr
, "\t ");
2811 step
= simple_strtoul(step_str
, NULL
, 0);
2815 /* Block the data collection for every vport */
2816 vports
= lpfc_create_vport_work_array(phba
);
2820 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2821 v_shost
= lpfc_shost_from_vport(vports
[i
]);
2822 spin_lock_irq(v_shost
->host_lock
);
2823 /* Block and reset data collection */
2824 vports
[i
]->stat_data_blocked
= 1;
2825 if (vports
[i
]->stat_data_enabled
)
2826 lpfc_vport_reset_stat_data(vports
[i
]);
2827 spin_unlock_irq(v_shost
->host_lock
);
2830 /* Set the bucket attributes */
2831 phba
->bucket_type
= bucket_type
;
2832 phba
->bucket_base
= base
;
2833 phba
->bucket_step
= step
;
2835 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2836 v_shost
= lpfc_shost_from_vport(vports
[i
]);
2838 /* Unblock data collection */
2839 spin_lock_irq(v_shost
->host_lock
);
2840 vports
[i
]->stat_data_blocked
= 0;
2841 spin_unlock_irq(v_shost
->host_lock
);
2843 lpfc_destroy_vport_work_array(phba
, vports
);
2847 if (!strncmp(buf
, "destroybucket", strlen("destroybucket"))) {
2848 vports
= lpfc_create_vport_work_array(phba
);
2852 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2853 v_shost
= lpfc_shost_from_vport(vports
[i
]);
2854 spin_lock_irq(shost
->host_lock
);
2855 vports
[i
]->stat_data_blocked
= 1;
2856 lpfc_free_bucket(vport
);
2857 vport
->stat_data_enabled
= 0;
2858 vports
[i
]->stat_data_blocked
= 0;
2859 spin_unlock_irq(shost
->host_lock
);
2861 lpfc_destroy_vport_work_array(phba
, vports
);
2862 phba
->bucket_type
= LPFC_NO_BUCKET
;
2863 phba
->bucket_base
= 0;
2864 phba
->bucket_step
= 0;
2868 if (!strncmp(buf
, "start", strlen("start"))) {
2869 /* If no buckets configured return error */
2870 if (phba
->bucket_type
== LPFC_NO_BUCKET
)
2872 spin_lock_irq(shost
->host_lock
);
2873 if (vport
->stat_data_enabled
) {
2874 spin_unlock_irq(shost
->host_lock
);
2877 lpfc_alloc_bucket(vport
);
2878 vport
->stat_data_enabled
= 1;
2879 spin_unlock_irq(shost
->host_lock
);
2883 if (!strncmp(buf
, "stop", strlen("stop"))) {
2884 spin_lock_irq(shost
->host_lock
);
2885 if (vport
->stat_data_enabled
== 0) {
2886 spin_unlock_irq(shost
->host_lock
);
2889 lpfc_free_bucket(vport
);
2890 vport
->stat_data_enabled
= 0;
2891 spin_unlock_irq(shost
->host_lock
);
2895 if (!strncmp(buf
, "reset", strlen("reset"))) {
2896 if ((phba
->bucket_type
== LPFC_NO_BUCKET
)
2897 || !vport
->stat_data_enabled
)
2899 spin_lock_irq(shost
->host_lock
);
2900 vport
->stat_data_blocked
= 1;
2901 lpfc_vport_reset_stat_data(vport
);
2902 vport
->stat_data_blocked
= 0;
2903 spin_unlock_irq(shost
->host_lock
);
2911 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2912 * @dev: Pointer to class device object.
2913 * @buf: Data buffer.
2915 * This function is the read call back function for
2916 * lpfc_stat_data_ctrl sysfs file. This function report the
2917 * current statistical data collection state.
2920 lpfc_stat_data_ctrl_show(struct device
*dev
, struct device_attribute
*attr
,
2923 struct Scsi_Host
*shost
= class_to_shost(dev
);
2924 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2925 struct lpfc_hba
*phba
= vport
->phba
;
2929 unsigned long bucket_value
;
2931 switch (phba
->bucket_type
) {
2932 case LPFC_LINEAR_BUCKET
:
2933 bucket_type
= "linear";
2935 case LPFC_POWER2_BUCKET
:
2936 bucket_type
= "power2";
2939 bucket_type
= "No Bucket";
2943 sprintf(&buf
[index
], "Statistical Data enabled :%d, "
2944 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2945 " Bucket step :%d\nLatency Ranges :",
2946 vport
->stat_data_enabled
, vport
->stat_data_blocked
,
2947 bucket_type
, phba
->bucket_base
, phba
->bucket_step
);
2948 index
= strlen(buf
);
2949 if (phba
->bucket_type
!= LPFC_NO_BUCKET
) {
2950 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
; i
++) {
2951 if (phba
->bucket_type
== LPFC_LINEAR_BUCKET
)
2952 bucket_value
= phba
->bucket_base
+
2953 phba
->bucket_step
* i
;
2955 bucket_value
= phba
->bucket_base
+
2956 (1 << i
) * phba
->bucket_step
;
2958 if (index
+ 10 > PAGE_SIZE
)
2960 sprintf(&buf
[index
], "%08ld ", bucket_value
);
2961 index
= strlen(buf
);
2964 sprintf(&buf
[index
], "\n");
2969 * Sysfs attribute to control the statistical data collection.
2971 static DEVICE_ATTR(lpfc_stat_data_ctrl
, S_IRUGO
| S_IWUSR
,
2972 lpfc_stat_data_ctrl_show
, lpfc_stat_data_ctrl_store
);
2975 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2979 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2982 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2983 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2984 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2988 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2990 * @kobj: Pointer to the kernel object
2991 * @bin_attr: Attribute object
2992 * @buff: Buffer pointer
2994 * @count: Buffer size
2996 * This function is the read call back function for lpfc_drvr_stat_data
2997 * sysfs file. This function export the statistical data to user
3001 sysfs_drvr_stat_data_read(struct file
*filp
, struct kobject
*kobj
,
3002 struct bin_attribute
*bin_attr
,
3003 char *buf
, loff_t off
, size_t count
)
3005 struct device
*dev
= container_of(kobj
, struct device
,
3007 struct Scsi_Host
*shost
= class_to_shost(dev
);
3008 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3009 struct lpfc_hba
*phba
= vport
->phba
;
3010 int i
= 0, index
= 0;
3011 unsigned long nport_index
;
3012 struct lpfc_nodelist
*ndlp
= NULL
;
3013 nport_index
= (unsigned long)off
/
3014 MAX_STAT_DATA_SIZE_PER_TARGET
;
3016 if (!vport
->stat_data_enabled
|| vport
->stat_data_blocked
3017 || (phba
->bucket_type
== LPFC_NO_BUCKET
))
3020 spin_lock_irq(shost
->host_lock
);
3021 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3022 if (!NLP_CHK_NODE_ACT(ndlp
) || !ndlp
->lat_data
)
3025 if (nport_index
> 0) {
3030 if ((index
+ MAX_STAT_DATA_SIZE_PER_TARGET
)
3034 if (!ndlp
->lat_data
)
3038 sprintf(&buf
[index
], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3039 ndlp
->nlp_portname
.u
.wwn
[0],
3040 ndlp
->nlp_portname
.u
.wwn
[1],
3041 ndlp
->nlp_portname
.u
.wwn
[2],
3042 ndlp
->nlp_portname
.u
.wwn
[3],
3043 ndlp
->nlp_portname
.u
.wwn
[4],
3044 ndlp
->nlp_portname
.u
.wwn
[5],
3045 ndlp
->nlp_portname
.u
.wwn
[6],
3046 ndlp
->nlp_portname
.u
.wwn
[7]);
3048 index
= strlen(buf
);
3050 for (i
= 0; i
< LPFC_MAX_BUCKET_COUNT
; i
++) {
3051 sprintf(&buf
[index
], "%010u,",
3052 ndlp
->lat_data
[i
].cmd_count
);
3053 index
= strlen(buf
);
3055 sprintf(&buf
[index
], "\n");
3056 index
= strlen(buf
);
3058 spin_unlock_irq(shost
->host_lock
);
3062 static struct bin_attribute sysfs_drvr_stat_data_attr
= {
3064 .name
= "lpfc_drvr_stat_data",
3067 .size
= LPFC_MAX_TARGET
* MAX_STAT_DATA_SIZE_PER_TARGET
,
3068 .read
= sysfs_drvr_stat_data_read
,
3073 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3075 # Value range is [0,16]. Default value is 0.
3078 * lpfc_link_speed_set - Set the adapters link speed
3079 * @phba: lpfc_hba pointer.
3080 * @val: link speed value.
3083 * If val is in a valid range then set the adapter's link speed field and
3084 * issue a lip; if the lip fails reset the link speed to the old value.
3087 * If the value is not in range log a kernel error message and return an error.
3090 * zero if val is in range and lip okay.
3091 * non-zero return value from lpfc_issue_lip()
3092 * -EINVAL val out of range
3095 lpfc_link_speed_store(struct device
*dev
, struct device_attribute
*attr
,
3096 const char *buf
, size_t count
)
3098 struct Scsi_Host
*shost
= class_to_shost(dev
);
3099 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3100 struct lpfc_hba
*phba
= vport
->phba
;
3101 int val
= LPFC_USER_LINK_SPEED_AUTO
;
3103 const char *val_buf
= buf
;
3107 if (!strncmp(buf
, "nolip ", strlen("nolip "))) {
3109 val_buf
= &buf
[strlen("nolip ")];
3112 if (!isdigit(val_buf
[0]))
3114 if (sscanf(val_buf
, "%i", &val
) != 1)
3117 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
3118 "3055 lpfc_link_speed changed from %d to %d %s\n",
3119 phba
->cfg_link_speed
, val
, nolip
? "(nolip)" : "(lip)");
3121 if (((val
== LPFC_USER_LINK_SPEED_1G
) && !(phba
->lmt
& LMT_1Gb
)) ||
3122 ((val
== LPFC_USER_LINK_SPEED_2G
) && !(phba
->lmt
& LMT_2Gb
)) ||
3123 ((val
== LPFC_USER_LINK_SPEED_4G
) && !(phba
->lmt
& LMT_4Gb
)) ||
3124 ((val
== LPFC_USER_LINK_SPEED_8G
) && !(phba
->lmt
& LMT_8Gb
)) ||
3125 ((val
== LPFC_USER_LINK_SPEED_10G
) && !(phba
->lmt
& LMT_10Gb
)) ||
3126 ((val
== LPFC_USER_LINK_SPEED_16G
) && !(phba
->lmt
& LMT_16Gb
))) {
3127 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3128 "2879 lpfc_link_speed attribute cannot be set "
3129 "to %d. Speed is not supported by this port.\n",
3133 if ((val
>= 0) && (val
<= LPFC_USER_LINK_SPEED_MAX
) &&
3134 (LPFC_USER_LINK_SPEED_BITMAP
& (1 << val
))) {
3135 prev_val
= phba
->cfg_link_speed
;
3136 phba
->cfg_link_speed
= val
;
3140 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
3142 phba
->cfg_link_speed
= prev_val
;
3147 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3148 "0469 lpfc_link_speed attribute cannot be set to %d, "
3149 "allowed values are ["LPFC_LINK_SPEED_STRING
"]\n", val
);
3153 static int lpfc_link_speed
= 0;
3154 module_param(lpfc_link_speed
, int, S_IRUGO
);
3155 MODULE_PARM_DESC(lpfc_link_speed
, "Select link speed");
3156 lpfc_param_show(link_speed
)
3159 * lpfc_link_speed_init - Set the adapters link speed
3160 * @phba: lpfc_hba pointer.
3161 * @val: link speed value.
3164 * If val is in a valid range then set the adapter's link speed field.
3167 * If the value is not in range log a kernel error message, clear the link
3168 * speed and return an error.
3171 * zero if val saved.
3172 * -EINVAL val out of range
3175 lpfc_link_speed_init(struct lpfc_hba
*phba
, int val
)
3177 if ((val
>= 0) && (val
<= LPFC_USER_LINK_SPEED_MAX
) &&
3178 (LPFC_USER_LINK_SPEED_BITMAP
& (1 << val
))) {
3179 phba
->cfg_link_speed
= val
;
3182 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3183 "0405 lpfc_link_speed attribute cannot "
3184 "be set to %d, allowed values are "
3185 "["LPFC_LINK_SPEED_STRING
"]\n", val
);
3186 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
3190 static DEVICE_ATTR(lpfc_link_speed
, S_IRUGO
| S_IWUSR
,
3191 lpfc_link_speed_show
, lpfc_link_speed_store
);
3194 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3195 # 0 = aer disabled or not supported
3196 # 1 = aer supported and enabled (default)
3197 # Value range is [0,1]. Default value is 1.
3201 * lpfc_aer_support_store - Set the adapter for aer support
3203 * @dev: class device that is converted into a Scsi_host.
3204 * @attr: device attribute, not used.
3205 * @buf: containing enable or disable aer flag.
3206 * @count: unused variable.
3209 * If the val is 1 and currently the device's AER capability was not
3210 * enabled, invoke the kernel's enable AER helper routine, trying to
3211 * enable the device's AER capability. If the helper routine enabling
3212 * AER returns success, update the device's cfg_aer_support flag to
3213 * indicate AER is supported by the device; otherwise, if the device
3214 * AER capability is already enabled to support AER, then do nothing.
3216 * If the val is 0 and currently the device's AER support was enabled,
3217 * invoke the kernel's disable AER helper routine. After that, update
3218 * the device's cfg_aer_support flag to indicate AER is not supported
3219 * by the device; otherwise, if the device AER capability is already
3220 * disabled from supporting AER, then do nothing.
3223 * length of the buf on success if val is in range the intended mode
3225 * -EINVAL if val out of range or intended mode is not supported.
3228 lpfc_aer_support_store(struct device
*dev
, struct device_attribute
*attr
,
3229 const char *buf
, size_t count
)
3231 struct Scsi_Host
*shost
= class_to_shost(dev
);
3232 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
3233 struct lpfc_hba
*phba
= vport
->phba
;
3234 int val
= 0, rc
= -EINVAL
;
3236 if (!isdigit(buf
[0]))
3238 if (sscanf(buf
, "%i", &val
) != 1)
3243 if (phba
->hba_flag
& HBA_AER_ENABLED
) {
3244 rc
= pci_disable_pcie_error_reporting(phba
->pcidev
);
3246 spin_lock_irq(&phba
->hbalock
);
3247 phba
->hba_flag
&= ~HBA_AER_ENABLED
;
3248 spin_unlock_irq(&phba
->hbalock
);
3249 phba
->cfg_aer_support
= 0;
3254 phba
->cfg_aer_support
= 0;
3259 if (!(phba
->hba_flag
& HBA_AER_ENABLED
)) {
3260 rc
= pci_enable_pcie_error_reporting(phba
->pcidev
);
3262 spin_lock_irq(&phba
->hbalock
);
3263 phba
->hba_flag
|= HBA_AER_ENABLED
;
3264 spin_unlock_irq(&phba
->hbalock
);
3265 phba
->cfg_aer_support
= 1;
3270 phba
->cfg_aer_support
= 1;
3281 static int lpfc_aer_support
= 1;
3282 module_param(lpfc_aer_support
, int, S_IRUGO
);
3283 MODULE_PARM_DESC(lpfc_aer_support
, "Enable PCIe device AER support");
3284 lpfc_param_show(aer_support
)
3287 * lpfc_aer_support_init - Set the initial adapters aer support flag
3288 * @phba: lpfc_hba pointer.
3289 * @val: enable aer or disable aer flag.
3292 * If val is in a valid range [0,1], then set the adapter's initial
3293 * cfg_aer_support field. It will be up to the driver's probe_one
3294 * routine to determine whether the device's AER support can be set
3298 * If the value is not in range log a kernel error message, and
3299 * choose the default value of setting AER support and return.
3302 * zero if val saved.
3303 * -EINVAL val out of range
3306 lpfc_aer_support_init(struct lpfc_hba
*phba
, int val
)
3308 if (val
== 0 || val
== 1) {
3309 phba
->cfg_aer_support
= val
;
3312 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3313 "2712 lpfc_aer_support attribute value %d out "
3314 "of range, allowed values are 0|1, setting it "
3315 "to default value of 1\n", val
);
3316 /* By default, try to enable AER on a device */
3317 phba
->cfg_aer_support
= 1;
3321 static DEVICE_ATTR(lpfc_aer_support
, S_IRUGO
| S_IWUSR
,
3322 lpfc_aer_support_show
, lpfc_aer_support_store
);
3325 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3326 * @dev: class device that is converted into a Scsi_host.
3327 * @attr: device attribute, not used.
3328 * @buf: containing flag 1 for aer cleanup state.
3329 * @count: unused variable.
3332 * If the @buf contains 1 and the device currently has the AER support
3333 * enabled, then invokes the kernel AER helper routine
3334 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3335 * error status register.
3340 * -EINVAL if the buf does not contain the 1 or the device is not currently
3341 * enabled with the AER support.
3344 lpfc_aer_cleanup_state(struct device
*dev
, struct device_attribute
*attr
,
3345 const char *buf
, size_t count
)
3347 struct Scsi_Host
*shost
= class_to_shost(dev
);
3348 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3349 struct lpfc_hba
*phba
= vport
->phba
;
3352 if (!isdigit(buf
[0]))
3354 if (sscanf(buf
, "%i", &val
) != 1)
3359 if (phba
->hba_flag
& HBA_AER_ENABLED
)
3360 rc
= pci_cleanup_aer_uncorrect_error_status(phba
->pcidev
);
3368 static DEVICE_ATTR(lpfc_aer_state_cleanup
, S_IWUSR
, NULL
,
3369 lpfc_aer_cleanup_state
);
3372 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3374 * @dev: class device that is converted into a Scsi_host.
3375 * @attr: device attribute, not used.
3376 * @buf: containing the string the number of vfs to be enabled.
3377 * @count: unused variable.
3380 * When this api is called either through user sysfs, the driver shall
3381 * try to enable or disable SR-IOV virtual functions according to the
3384 * If zero virtual function has been enabled to the physical function,
3385 * the driver shall invoke the pci enable virtual function api trying
3386 * to enable the virtual functions. If the nr_vfn provided is greater
3387 * than the maximum supported, the maximum virtual function number will
3388 * be used for invoking the api; otherwise, the nr_vfn provided shall
3389 * be used for invoking the api. If the api call returned success, the
3390 * actual number of virtual functions enabled will be set to the driver
3391 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3392 * cfg_sriov_nr_virtfn remains zero.
3394 * If none-zero virtual functions have already been enabled to the
3395 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3396 * -EINVAL will be returned and the driver does nothing;
3398 * If the nr_vfn provided is zero and none-zero virtual functions have
3399 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3400 * disabling virtual function api shall be invoded to disable all the
3401 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3402 * zero. Otherwise, if zero virtual function has been enabled, do
3406 * length of the buf on success if val is in range the intended mode
3408 * -EINVAL if val out of range or intended mode is not supported.
3411 lpfc_sriov_nr_virtfn_store(struct device
*dev
, struct device_attribute
*attr
,
3412 const char *buf
, size_t count
)
3414 struct Scsi_Host
*shost
= class_to_shost(dev
);
3415 struct lpfc_vport
*vport
= (struct lpfc_vport
*)shost
->hostdata
;
3416 struct lpfc_hba
*phba
= vport
->phba
;
3417 struct pci_dev
*pdev
= phba
->pcidev
;
3418 int val
= 0, rc
= -EINVAL
;
3420 /* Sanity check on user data */
3421 if (!isdigit(buf
[0]))
3423 if (sscanf(buf
, "%i", &val
) != 1)
3428 /* Request disabling virtual functions */
3430 if (phba
->cfg_sriov_nr_virtfn
> 0) {
3431 pci_disable_sriov(pdev
);
3432 phba
->cfg_sriov_nr_virtfn
= 0;
3437 /* Request enabling virtual functions */
3438 if (phba
->cfg_sriov_nr_virtfn
> 0) {
3439 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3440 "3018 There are %d virtual functions "
3441 "enabled on physical function.\n",
3442 phba
->cfg_sriov_nr_virtfn
);
3446 if (val
<= LPFC_MAX_VFN_PER_PFN
)
3447 phba
->cfg_sriov_nr_virtfn
= val
;
3449 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3450 "3019 Enabling %d virtual functions is not "
3455 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
, phba
->cfg_sriov_nr_virtfn
);
3457 phba
->cfg_sriov_nr_virtfn
= 0;
3465 static int lpfc_sriov_nr_virtfn
= LPFC_DEF_VFN_PER_PFN
;
3466 module_param(lpfc_sriov_nr_virtfn
, int, S_IRUGO
|S_IWUSR
);
3467 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn
, "Enable PCIe device SR-IOV virtual fn");
3468 lpfc_param_show(sriov_nr_virtfn
)
3471 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3472 * @phba: lpfc_hba pointer.
3473 * @val: link speed value.
3476 * If val is in a valid range [0,255], then set the adapter's initial
3477 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3478 * number shall be used instead. It will be up to the driver's probe_one
3479 * routine to determine whether the device's SR-IOV is supported or not.
3482 * zero if val saved.
3483 * -EINVAL val out of range
3486 lpfc_sriov_nr_virtfn_init(struct lpfc_hba
*phba
, int val
)
3488 if (val
>= 0 && val
<= LPFC_MAX_VFN_PER_PFN
) {
3489 phba
->cfg_sriov_nr_virtfn
= val
;
3493 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3494 "3017 Enabling %d virtual functions is not "
3498 static DEVICE_ATTR(lpfc_sriov_nr_virtfn
, S_IRUGO
| S_IWUSR
,
3499 lpfc_sriov_nr_virtfn_show
, lpfc_sriov_nr_virtfn_store
);
3502 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3503 # Value range is [2,3]. Default value is 3.
3505 LPFC_VPORT_ATTR_R(fcp_class
, 3, 2, 3,
3506 "Select Fibre Channel class of service for FCP sequences");
3509 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3510 # is [0,1]. Default value is 0.
3512 LPFC_VPORT_ATTR_RW(use_adisc
, 0, 0, 1,
3513 "Use ADISC on rediscovery to authenticate FCP devices");
3516 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3517 # depth. Default value is 0. When the value of this parameter is zero the
3518 # SCSI command completion time is not used for controlling I/O queue depth. When
3519 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3520 # to limit the I/O completion time to the parameter value.
3521 # The value is set in milliseconds.
3523 static int lpfc_max_scsicmpl_time
;
3524 module_param(lpfc_max_scsicmpl_time
, int, S_IRUGO
);
3525 MODULE_PARM_DESC(lpfc_max_scsicmpl_time
,
3526 "Use command completion time to control queue depth");
3527 lpfc_vport_param_show(max_scsicmpl_time
);
3528 lpfc_vport_param_init(max_scsicmpl_time
, 0, 0, 60000);
3530 lpfc_max_scsicmpl_time_set(struct lpfc_vport
*vport
, int val
)
3532 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3533 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3535 if (val
== vport
->cfg_max_scsicmpl_time
)
3537 if ((val
< 0) || (val
> 60000))
3539 vport
->cfg_max_scsicmpl_time
= val
;
3541 spin_lock_irq(shost
->host_lock
);
3542 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3543 if (!NLP_CHK_NODE_ACT(ndlp
))
3545 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
3547 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
3549 spin_unlock_irq(shost
->host_lock
);
3552 lpfc_vport_param_store(max_scsicmpl_time
);
3553 static DEVICE_ATTR(lpfc_max_scsicmpl_time
, S_IRUGO
| S_IWUSR
,
3554 lpfc_max_scsicmpl_time_show
,
3555 lpfc_max_scsicmpl_time_store
);
3558 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3559 # range is [0,1]. Default value is 0.
3561 LPFC_ATTR_R(ack0
, 0, 0, 1, "Enable ACK0 support");
3564 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3565 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3566 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3567 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3568 # cr_delay is set to 0.
3570 LPFC_ATTR_RW(cr_delay
, 0, 0, 63, "A count of milliseconds after which an "
3571 "interrupt response is generated");
3573 LPFC_ATTR_RW(cr_count
, 1, 1, 255, "A count of I/O completions after which an "
3574 "interrupt response is generated");
3577 # lpfc_multi_ring_support: Determines how many rings to spread available
3578 # cmd/rsp IOCB entries across.
3579 # Value range is [1,2]. Default value is 1.
3581 LPFC_ATTR_R(multi_ring_support
, 1, 1, 2, "Determines number of primary "
3582 "SLI rings to spread IOCB entries across");
3585 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3586 # identifies what rctl value to configure the additional ring for.
3587 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3589 LPFC_ATTR_R(multi_ring_rctl
, FC_RCTL_DD_UNSOL_DATA
, 1,
3590 255, "Identifies RCTL for additional ring configuration");
3593 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3594 # identifies what type value to configure the additional ring for.
3595 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3597 LPFC_ATTR_R(multi_ring_type
, FC_TYPE_IP
, 1,
3598 255, "Identifies TYPE for additional ring configuration");
3601 # lpfc_fdmi_on: controls FDMI support.
3602 # 0 = no FDMI support
3603 # 1 = support FDMI without attribute of hostname
3604 # 2 = support FDMI with attribute of hostname
3605 # Value range [0,2]. Default value is 0.
3607 LPFC_VPORT_ATTR_RW(fdmi_on
, 0, 0, 2, "Enable FDMI support");
3610 # Specifies the maximum number of ELS cmds we can have outstanding (for
3611 # discovery). Value range is [1,64]. Default value = 32.
3613 LPFC_VPORT_ATTR(discovery_threads
, 32, 1, 64, "Maximum number of ELS commands "
3614 "during discovery");
3617 # lpfc_max_luns: maximum allowed LUN.
3618 # Value range is [0,65535]. Default value is 255.
3619 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3621 LPFC_VPORT_ATTR_R(max_luns
, 255, 0, 65535, "Maximum allowed LUN");
3624 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3625 # Value range is [1,255], default value is 10.
3627 LPFC_ATTR_RW(poll_tmo
, 10, 1, 255,
3628 "Milliseconds driver will wait between polling FCP ring");
3631 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3632 # support this feature
3635 # 2 = MSI-X enabled (default)
3636 # Value range is [0,2]. Default value is 2.
3638 LPFC_ATTR_R(use_msi
, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3639 "MSI-X (2), if possible");
3642 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3644 # Value range is [636,651042]. Default value is 10000.
3646 LPFC_ATTR_R(fcp_imax
, LPFC_FP_DEF_IMAX
, LPFC_MIM_IMAX
, LPFC_DMULT_CONST
,
3647 "Set the maximum number of fast-path FCP interrupts per second");
3650 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3652 # Value range is [1,31]. Default value is 4.
3654 LPFC_ATTR_R(fcp_wq_count
, LPFC_FP_WQN_DEF
, LPFC_FP_WQN_MIN
, LPFC_FP_WQN_MAX
,
3655 "Set the number of fast-path FCP work queues, if possible");
3658 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3660 # Value range is [1,7]. Default value is 1.
3662 LPFC_ATTR_R(fcp_eq_count
, LPFC_FP_EQN_DEF
, LPFC_FP_EQN_MIN
, LPFC_FP_EQN_MAX
,
3663 "Set the number of fast-path FCP event queues, if possible");
3666 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3667 # 0 = HBA resets disabled
3668 # 1 = HBA resets enabled (default)
3669 # Value range is [0,1]. Default value is 1.
3671 LPFC_ATTR_R(enable_hba_reset
, 1, 0, 1, "Enable HBA resets from the driver.");
3674 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3675 # 0 = HBA Heartbeat disabled
3676 # 1 = HBA Heartbeat enabled (default)
3677 # Value range is [0,1]. Default value is 1.
3679 LPFC_ATTR_R(enable_hba_heartbeat
, 0, 0, 1, "Enable HBA Heartbeat.");
3682 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3683 # 0 = BlockGuard disabled (default)
3684 # 1 = BlockGuard enabled
3685 # Value range is [0,1]. Default value is 0.
3687 LPFC_ATTR_R(enable_bg
, 0, 0, 1, "Enable BlockGuard Support");
3691 # - Bit mask of host protection capabilities used to register with the
3693 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3694 # - Allows you to ultimately specify which profiles to use
3695 # - Default will result in registering capabilities for all profiles.
3698 unsigned int lpfc_prot_mask
= SHOST_DIF_TYPE1_PROTECTION
|
3699 SHOST_DIX_TYPE0_PROTECTION
|
3700 SHOST_DIX_TYPE1_PROTECTION
;
3702 module_param(lpfc_prot_mask
, uint
, S_IRUGO
);
3703 MODULE_PARM_DESC(lpfc_prot_mask
, "host protection mask");
3706 # lpfc_prot_guard: i
3707 # - Bit mask of protection guard types to register with the SCSI mid-layer
3708 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3709 # - Allows you to ultimately specify which profiles to use
3710 # - Default will result in registering capabilities for all guard types
3713 unsigned char lpfc_prot_guard
= SHOST_DIX_GUARD_IP
;
3714 module_param(lpfc_prot_guard
, byte
, S_IRUGO
);
3715 MODULE_PARM_DESC(lpfc_prot_guard
, "host protection guard type");
3718 * Delay initial NPort discovery when Clean Address bit is cleared in
3719 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3720 * This parameter can have value 0 or 1.
3721 * When this parameter is set to 0, no delay is added to the initial
3723 * When this parameter is set to non-zero value, initial Nport discovery is
3724 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3725 * accept and FCID/Fabric name/Fabric portname is changed.
3726 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3727 * when Clean Address bit is cleared in FLOGI/FDISC
3728 * accept and FCID/Fabric name/Fabric portname is changed.
3729 * Default value is 0.
3731 int lpfc_delay_discovery
;
3732 module_param(lpfc_delay_discovery
, int, S_IRUGO
);
3733 MODULE_PARM_DESC(lpfc_delay_discovery
,
3734 "Delay NPort discovery when Clean Address bit is cleared. "
3735 "Allowed values: 0,1.");
3738 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3739 * This value can be set to values between 64 and 256. The default value is
3740 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3741 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3743 LPFC_ATTR_R(sg_seg_cnt
, LPFC_DEFAULT_SG_SEG_CNT
, LPFC_DEFAULT_SG_SEG_CNT
,
3744 LPFC_MAX_SG_SEG_CNT
, "Max Scatter Gather Segment Count");
3746 LPFC_ATTR_R(prot_sg_seg_cnt
, LPFC_DEFAULT_PROT_SG_SEG_CNT
,
3747 LPFC_DEFAULT_PROT_SG_SEG_CNT
, LPFC_MAX_PROT_SG_SEG_CNT
,
3748 "Max Protection Scatter Gather Segment Count");
3750 struct device_attribute
*lpfc_hba_attrs
[] = {
3752 &dev_attr_bg_guard_err
,
3753 &dev_attr_bg_apptag_err
,
3754 &dev_attr_bg_reftag_err
,
3756 &dev_attr_serialnum
,
3757 &dev_attr_modeldesc
,
3758 &dev_attr_modelname
,
3759 &dev_attr_programtype
,
3763 &dev_attr_option_rom_version
,
3764 &dev_attr_link_state
,
3765 &dev_attr_num_discovered_ports
,
3766 &dev_attr_menlo_mgmt_mode
,
3767 &dev_attr_lpfc_drvr_version
,
3768 &dev_attr_lpfc_enable_fip
,
3769 &dev_attr_lpfc_temp_sensor
,
3770 &dev_attr_lpfc_log_verbose
,
3771 &dev_attr_lpfc_lun_queue_depth
,
3772 &dev_attr_lpfc_tgt_queue_depth
,
3773 &dev_attr_lpfc_hba_queue_depth
,
3774 &dev_attr_lpfc_peer_port_login
,
3775 &dev_attr_lpfc_nodev_tmo
,
3776 &dev_attr_lpfc_devloss_tmo
,
3777 &dev_attr_lpfc_fcp_class
,
3778 &dev_attr_lpfc_use_adisc
,
3779 &dev_attr_lpfc_ack0
,
3780 &dev_attr_lpfc_topology
,
3781 &dev_attr_lpfc_scan_down
,
3782 &dev_attr_lpfc_link_speed
,
3783 &dev_attr_lpfc_cr_delay
,
3784 &dev_attr_lpfc_cr_count
,
3785 &dev_attr_lpfc_multi_ring_support
,
3786 &dev_attr_lpfc_multi_ring_rctl
,
3787 &dev_attr_lpfc_multi_ring_type
,
3788 &dev_attr_lpfc_fdmi_on
,
3789 &dev_attr_lpfc_max_luns
,
3790 &dev_attr_lpfc_enable_npiv
,
3791 &dev_attr_lpfc_fcf_failover_policy
,
3792 &dev_attr_lpfc_enable_rrq
,
3793 &dev_attr_nport_evt_cnt
,
3794 &dev_attr_board_mode
,
3801 &dev_attr_npiv_info
,
3802 &dev_attr_issue_reset
,
3803 &dev_attr_lpfc_poll
,
3804 &dev_attr_lpfc_poll_tmo
,
3805 &dev_attr_lpfc_use_msi
,
3806 &dev_attr_lpfc_fcp_imax
,
3807 &dev_attr_lpfc_fcp_wq_count
,
3808 &dev_attr_lpfc_fcp_eq_count
,
3809 &dev_attr_lpfc_enable_bg
,
3810 &dev_attr_lpfc_soft_wwnn
,
3811 &dev_attr_lpfc_soft_wwpn
,
3812 &dev_attr_lpfc_soft_wwn_enable
,
3813 &dev_attr_lpfc_enable_hba_reset
,
3814 &dev_attr_lpfc_enable_hba_heartbeat
,
3815 &dev_attr_lpfc_sg_seg_cnt
,
3816 &dev_attr_lpfc_max_scsicmpl_time
,
3817 &dev_attr_lpfc_stat_data_ctrl
,
3818 &dev_attr_lpfc_prot_sg_seg_cnt
,
3819 &dev_attr_lpfc_aer_support
,
3820 &dev_attr_lpfc_aer_state_cleanup
,
3821 &dev_attr_lpfc_sriov_nr_virtfn
,
3822 &dev_attr_lpfc_suppress_link_up
,
3823 &dev_attr_lpfc_iocb_cnt
,
3826 &dev_attr_txcmplq_hw
,
3827 &dev_attr_lpfc_fips_level
,
3828 &dev_attr_lpfc_fips_rev
,
3830 &dev_attr_lpfc_sriov_hw_max_virtfn
,
3834 struct device_attribute
*lpfc_vport_attrs
[] = {
3836 &dev_attr_link_state
,
3837 &dev_attr_num_discovered_ports
,
3838 &dev_attr_lpfc_drvr_version
,
3839 &dev_attr_lpfc_log_verbose
,
3840 &dev_attr_lpfc_lun_queue_depth
,
3841 &dev_attr_lpfc_tgt_queue_depth
,
3842 &dev_attr_lpfc_nodev_tmo
,
3843 &dev_attr_lpfc_devloss_tmo
,
3844 &dev_attr_lpfc_hba_queue_depth
,
3845 &dev_attr_lpfc_peer_port_login
,
3846 &dev_attr_lpfc_restrict_login
,
3847 &dev_attr_lpfc_fcp_class
,
3848 &dev_attr_lpfc_use_adisc
,
3849 &dev_attr_lpfc_fdmi_on
,
3850 &dev_attr_lpfc_max_luns
,
3851 &dev_attr_nport_evt_cnt
,
3852 &dev_attr_npiv_info
,
3853 &dev_attr_lpfc_enable_da_id
,
3854 &dev_attr_lpfc_max_scsicmpl_time
,
3855 &dev_attr_lpfc_stat_data_ctrl
,
3856 &dev_attr_lpfc_static_vport
,
3857 &dev_attr_lpfc_fips_level
,
3858 &dev_attr_lpfc_fips_rev
,
3863 * sysfs_ctlreg_write - Write method for writing to ctlreg
3864 * @filp: open sysfs file
3865 * @kobj: kernel kobject that contains the kernel class device.
3866 * @bin_attr: kernel attributes passed to us.
3867 * @buf: contains the data to be written to the adapter IOREG space.
3868 * @off: offset into buffer to beginning of data.
3869 * @count: bytes to transfer.
3872 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3873 * Uses the adapter io control registers to send buf contents to the adapter.
3876 * -ERANGE off and count combo out of range
3877 * -EINVAL off, count or buff address invalid
3878 * -EPERM adapter is offline
3879 * value of count, buf contents written
3882 sysfs_ctlreg_write(struct file
*filp
, struct kobject
*kobj
,
3883 struct bin_attribute
*bin_attr
,
3884 char *buf
, loff_t off
, size_t count
)
3887 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3888 struct Scsi_Host
*shost
= class_to_shost(dev
);
3889 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3890 struct lpfc_hba
*phba
= vport
->phba
;
3892 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
3895 if ((off
+ count
) > FF_REG_AREA_SIZE
)
3898 if (count
<= LPFC_REG_WRITE_KEY_SIZE
)
3901 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
3904 /* This is to protect HBA registers from accidental writes. */
3905 if (memcmp(buf
, LPFC_REG_WRITE_KEY
, LPFC_REG_WRITE_KEY_SIZE
))
3908 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
3911 spin_lock_irq(&phba
->hbalock
);
3912 for (buf_off
= 0; buf_off
< count
- LPFC_REG_WRITE_KEY_SIZE
;
3913 buf_off
+= sizeof(uint32_t))
3914 writel(*((uint32_t *)(buf
+ buf_off
+ LPFC_REG_WRITE_KEY_SIZE
)),
3915 phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
3917 spin_unlock_irq(&phba
->hbalock
);
3923 * sysfs_ctlreg_read - Read method for reading from ctlreg
3924 * @filp: open sysfs file
3925 * @kobj: kernel kobject that contains the kernel class device.
3926 * @bin_attr: kernel attributes passed to us.
3927 * @buf: if successful contains the data from the adapter IOREG space.
3928 * @off: offset into buffer to beginning of data.
3929 * @count: bytes to transfer.
3932 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3933 * Uses the adapter io control registers to read data into buf.
3936 * -ERANGE off and count combo out of range
3937 * -EINVAL off, count or buff address invalid
3938 * value of count, buf contents read
3941 sysfs_ctlreg_read(struct file
*filp
, struct kobject
*kobj
,
3942 struct bin_attribute
*bin_attr
,
3943 char *buf
, loff_t off
, size_t count
)
3947 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3948 struct Scsi_Host
*shost
= class_to_shost(dev
);
3949 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3950 struct lpfc_hba
*phba
= vport
->phba
;
3952 if (phba
->sli_rev
>= LPFC_SLI_REV4
)
3955 if (off
> FF_REG_AREA_SIZE
)
3958 if ((off
+ count
) > FF_REG_AREA_SIZE
)
3959 count
= FF_REG_AREA_SIZE
- off
;
3961 if (count
== 0) return 0;
3963 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
3966 spin_lock_irq(&phba
->hbalock
);
3968 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t)) {
3969 tmp_ptr
= (uint32_t *)(buf
+ buf_off
);
3970 *tmp_ptr
= readl(phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
3973 spin_unlock_irq(&phba
->hbalock
);
3978 static struct bin_attribute sysfs_ctlreg_attr
= {
3981 .mode
= S_IRUSR
| S_IWUSR
,
3984 .read
= sysfs_ctlreg_read
,
3985 .write
= sysfs_ctlreg_write
,
3989 * sysfs_mbox_idle - frees the sysfs mailbox
3990 * @phba: lpfc_hba pointer
3993 sysfs_mbox_idle(struct lpfc_hba
*phba
)
3995 phba
->sysfs_mbox
.state
= SMBOX_IDLE
;
3996 phba
->sysfs_mbox
.offset
= 0;
3998 if (phba
->sysfs_mbox
.mbox
) {
3999 mempool_free(phba
->sysfs_mbox
.mbox
,
4000 phba
->mbox_mem_pool
);
4001 phba
->sysfs_mbox
.mbox
= NULL
;
4006 * sysfs_mbox_write - Write method for writing information via mbox
4007 * @filp: open sysfs file
4008 * @kobj: kernel kobject that contains the kernel class device.
4009 * @bin_attr: kernel attributes passed to us.
4010 * @buf: contains the data to be written to sysfs mbox.
4011 * @off: offset into buffer to beginning of data.
4012 * @count: bytes to transfer.
4015 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4016 * Uses the sysfs mbox to send buf contents to the adapter.
4019 * -ERANGE off and count combo out of range
4020 * -EINVAL off, count or buff address invalid
4021 * zero if count is zero
4022 * -EPERM adapter is offline
4023 * -ENOMEM failed to allocate memory for the mail box
4024 * -EAGAIN offset, state or mbox is NULL
4025 * count number of bytes transferred
4028 sysfs_mbox_write(struct file
*filp
, struct kobject
*kobj
,
4029 struct bin_attribute
*bin_attr
,
4030 char *buf
, loff_t off
, size_t count
)
4032 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4033 struct Scsi_Host
*shost
= class_to_shost(dev
);
4034 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4035 struct lpfc_hba
*phba
= vport
->phba
;
4036 struct lpfcMboxq
*mbox
= NULL
;
4038 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
4041 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
4048 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4051 memset(mbox
, 0, sizeof (LPFC_MBOXQ_t
));
4054 spin_lock_irq(&phba
->hbalock
);
4057 if (phba
->sysfs_mbox
.mbox
)
4058 mempool_free(mbox
, phba
->mbox_mem_pool
);
4060 phba
->sysfs_mbox
.mbox
= mbox
;
4061 phba
->sysfs_mbox
.state
= SMBOX_WRITING
;
4063 if (phba
->sysfs_mbox
.state
!= SMBOX_WRITING
||
4064 phba
->sysfs_mbox
.offset
!= off
||
4065 phba
->sysfs_mbox
.mbox
== NULL
) {
4066 sysfs_mbox_idle(phba
);
4067 spin_unlock_irq(&phba
->hbalock
);
4072 memcpy((uint8_t *) &phba
->sysfs_mbox
.mbox
->u
.mb
+ off
,
4075 phba
->sysfs_mbox
.offset
= off
+ count
;
4077 spin_unlock_irq(&phba
->hbalock
);
4083 * sysfs_mbox_read - Read method for reading information via mbox
4084 * @filp: open sysfs file
4085 * @kobj: kernel kobject that contains the kernel class device.
4086 * @bin_attr: kernel attributes passed to us.
4087 * @buf: contains the data to be read from sysfs mbox.
4088 * @off: offset into buffer to beginning of data.
4089 * @count: bytes to transfer.
4092 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4093 * Uses the sysfs mbox to receive data from to the adapter.
4096 * -ERANGE off greater than mailbox command size
4097 * -EINVAL off, count or buff address invalid
4098 * zero if off and count are zero
4099 * -EACCES adapter over temp
4100 * -EPERM garbage can value to catch a multitude of errors
4101 * -EAGAIN management IO not permitted, state or off error
4102 * -ETIME mailbox timeout
4103 * -ENODEV mailbox error
4104 * count number of bytes transferred
4107 sysfs_mbox_read(struct file
*filp
, struct kobject
*kobj
,
4108 struct bin_attribute
*bin_attr
,
4109 char *buf
, loff_t off
, size_t count
)
4111 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4112 struct Scsi_Host
*shost
= class_to_shost(dev
);
4113 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4114 struct lpfc_hba
*phba
= vport
->phba
;
4118 if (off
> MAILBOX_CMD_SIZE
)
4121 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
4122 count
= MAILBOX_CMD_SIZE
- off
;
4124 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
4127 if (off
&& count
== 0)
4130 spin_lock_irq(&phba
->hbalock
);
4132 if (phba
->over_temp_state
== HBA_OVER_TEMP
) {
4133 sysfs_mbox_idle(phba
);
4134 spin_unlock_irq(&phba
->hbalock
);
4139 phba
->sysfs_mbox
.state
== SMBOX_WRITING
&&
4140 phba
->sysfs_mbox
.offset
>= 2 * sizeof(uint32_t)) {
4141 pmb
= &phba
->sysfs_mbox
.mbox
->u
.mb
;
4142 switch (pmb
->mbxCommand
) {
4146 case MBX_CONFIG_LINK
:
4147 case MBX_CONFIG_RING
:
4148 case MBX_RESET_RING
:
4149 case MBX_UNREG_LOGIN
:
4151 case MBX_DUMP_CONTEXT
:
4156 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
4157 printk(KERN_WARNING
"mbox_read:Command 0x%x "
4158 "is illegal in on-line state\n",
4160 sysfs_mbox_idle(phba
);
4161 spin_unlock_irq(&phba
->hbalock
);
4165 case MBX_WRITE_VPARMS
:
4168 case MBX_READ_CONFIG
:
4169 case MBX_READ_RCONFIG
:
4170 case MBX_READ_STATUS
:
4173 case MBX_READ_LNK_STAT
:
4174 case MBX_DUMP_MEMORY
:
4176 case MBX_UPDATE_CFG
:
4177 case MBX_KILL_BOARD
:
4179 case MBX_LOAD_EXP_ROM
:
4181 case MBX_DEL_LD_ENTRY
:
4182 case MBX_SET_VARIABLE
:
4184 case MBX_PORT_CAPABILITIES
:
4185 case MBX_PORT_IOV_CONTROL
:
4187 case MBX_SECURITY_MGMT
:
4189 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
4190 printk(KERN_WARNING
"mbox_read:Command 0x%x "
4191 "is not permitted\n", pmb
->mbxCommand
);
4192 sysfs_mbox_idle(phba
);
4193 spin_unlock_irq(&phba
->hbalock
);
4197 case MBX_READ_SPARM64
:
4198 case MBX_READ_TOPOLOGY
:
4200 case MBX_REG_LOGIN64
:
4201 case MBX_CONFIG_PORT
:
4202 case MBX_RUN_BIU_DIAG
:
4203 printk(KERN_WARNING
"mbox_read: Illegal Command 0x%x\n",
4205 sysfs_mbox_idle(phba
);
4206 spin_unlock_irq(&phba
->hbalock
);
4209 printk(KERN_WARNING
"mbox_read: Unknown Command 0x%x\n",
4211 sysfs_mbox_idle(phba
);
4212 spin_unlock_irq(&phba
->hbalock
);
4216 /* If HBA encountered an error attention, allow only DUMP
4217 * or RESTART mailbox commands until the HBA is restarted.
4219 if (phba
->pport
->stopped
&&
4220 pmb
->mbxCommand
!= MBX_DUMP_MEMORY
&&
4221 pmb
->mbxCommand
!= MBX_RESTART
&&
4222 pmb
->mbxCommand
!= MBX_WRITE_VPARMS
&&
4223 pmb
->mbxCommand
!= MBX_WRITE_WWN
)
4224 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
4225 "1259 mbox: Issued mailbox cmd "
4226 "0x%x while in stopped state.\n",
4229 phba
->sysfs_mbox
.mbox
->vport
= vport
;
4231 /* Don't allow mailbox commands to be sent when blocked
4232 * or when in the middle of discovery
4234 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
4235 sysfs_mbox_idle(phba
);
4236 spin_unlock_irq(&phba
->hbalock
);
4240 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4241 (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))) {
4243 spin_unlock_irq(&phba
->hbalock
);
4244 rc
= lpfc_sli_issue_mbox (phba
,
4245 phba
->sysfs_mbox
.mbox
,
4247 spin_lock_irq(&phba
->hbalock
);
4250 spin_unlock_irq(&phba
->hbalock
);
4251 rc
= lpfc_sli_issue_mbox_wait (phba
,
4252 phba
->sysfs_mbox
.mbox
,
4253 lpfc_mbox_tmo_val(phba
, pmb
->mbxCommand
) * HZ
);
4254 spin_lock_irq(&phba
->hbalock
);
4257 if (rc
!= MBX_SUCCESS
) {
4258 if (rc
== MBX_TIMEOUT
) {
4259 phba
->sysfs_mbox
.mbox
= NULL
;
4261 sysfs_mbox_idle(phba
);
4262 spin_unlock_irq(&phba
->hbalock
);
4263 return (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
4265 phba
->sysfs_mbox
.state
= SMBOX_READING
;
4267 else if (phba
->sysfs_mbox
.offset
!= off
||
4268 phba
->sysfs_mbox
.state
!= SMBOX_READING
) {
4269 printk(KERN_WARNING
"mbox_read: Bad State\n");
4270 sysfs_mbox_idle(phba
);
4271 spin_unlock_irq(&phba
->hbalock
);
4275 memcpy(buf
, (uint8_t *) &pmb
+ off
, count
);
4277 phba
->sysfs_mbox
.offset
= off
+ count
;
4279 if (phba
->sysfs_mbox
.offset
== MAILBOX_CMD_SIZE
)
4280 sysfs_mbox_idle(phba
);
4282 spin_unlock_irq(&phba
->hbalock
);
4287 static struct bin_attribute sysfs_mbox_attr
= {
4290 .mode
= S_IRUSR
| S_IWUSR
,
4292 .size
= MAILBOX_SYSFS_MAX
,
4293 .read
= sysfs_mbox_read
,
4294 .write
= sysfs_mbox_write
,
4298 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
4299 * @vport: address of lpfc vport structure.
4303 * error return code from sysfs_create_bin_file()
4306 lpfc_alloc_sysfs_attr(struct lpfc_vport
*vport
)
4308 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4311 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
4312 &sysfs_drvr_stat_data_attr
);
4314 /* Virtual ports do not need ctrl_reg and mbox */
4315 if (error
|| vport
->port_type
== LPFC_NPIV_PORT
)
4318 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
4319 &sysfs_ctlreg_attr
);
4321 goto out_remove_stat_attr
;
4323 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
4326 goto out_remove_ctlreg_attr
;
4329 out_remove_ctlreg_attr
:
4330 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
4331 out_remove_stat_attr
:
4332 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
,
4333 &sysfs_drvr_stat_data_attr
);
4339 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4340 * @vport: address of lpfc vport structure.
4343 lpfc_free_sysfs_attr(struct lpfc_vport
*vport
)
4345 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4346 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
,
4347 &sysfs_drvr_stat_data_attr
);
4348 /* Virtual ports do not need ctrl_reg and mbox */
4349 if (vport
->port_type
== LPFC_NPIV_PORT
)
4351 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_mbox_attr
);
4352 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
4357 * Dynamic FC Host Attributes Support
4361 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4362 * @shost: kernel scsi host pointer.
4365 lpfc_get_host_port_id(struct Scsi_Host
*shost
)
4367 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4369 /* note: fc_myDID already in cpu endianness */
4370 fc_host_port_id(shost
) = vport
->fc_myDID
;
4374 * lpfc_get_host_port_type - Set the value of the scsi host port type
4375 * @shost: kernel scsi host pointer.
4378 lpfc_get_host_port_type(struct Scsi_Host
*shost
)
4380 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4381 struct lpfc_hba
*phba
= vport
->phba
;
4383 spin_lock_irq(shost
->host_lock
);
4385 if (vport
->port_type
== LPFC_NPIV_PORT
) {
4386 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
4387 } else if (lpfc_is_link_up(phba
)) {
4388 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4389 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
4390 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
4392 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
4394 if (vport
->fc_flag
& FC_FABRIC
)
4395 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
4397 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
4400 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
4402 spin_unlock_irq(shost
->host_lock
);
4406 * lpfc_get_host_port_state - Set the value of the scsi host port state
4407 * @shost: kernel scsi host pointer.
4410 lpfc_get_host_port_state(struct Scsi_Host
*shost
)
4412 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4413 struct lpfc_hba
*phba
= vport
->phba
;
4415 spin_lock_irq(shost
->host_lock
);
4417 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
4418 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
4420 switch (phba
->link_state
) {
4421 case LPFC_LINK_UNKNOWN
:
4422 case LPFC_LINK_DOWN
:
4423 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
4427 case LPFC_HBA_READY
:
4428 /* Links up, beyond this port_type reports state */
4429 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
4431 case LPFC_HBA_ERROR
:
4432 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
4435 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
4440 spin_unlock_irq(shost
->host_lock
);
4444 * lpfc_get_host_speed - Set the value of the scsi host speed
4445 * @shost: kernel scsi host pointer.
4448 lpfc_get_host_speed(struct Scsi_Host
*shost
)
4450 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4451 struct lpfc_hba
*phba
= vport
->phba
;
4453 spin_lock_irq(shost
->host_lock
);
4455 if (lpfc_is_link_up(phba
)) {
4456 switch(phba
->fc_linkspeed
) {
4457 case LPFC_LINK_SPEED_1GHZ
:
4458 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
4460 case LPFC_LINK_SPEED_2GHZ
:
4461 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
4463 case LPFC_LINK_SPEED_4GHZ
:
4464 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
4466 case LPFC_LINK_SPEED_8GHZ
:
4467 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
4469 case LPFC_LINK_SPEED_10GHZ
:
4470 fc_host_speed(shost
) = FC_PORTSPEED_10GBIT
;
4472 case LPFC_LINK_SPEED_16GHZ
:
4473 fc_host_speed(shost
) = FC_PORTSPEED_16GBIT
;
4476 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
4480 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
4482 spin_unlock_irq(shost
->host_lock
);
4486 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4487 * @shost: kernel scsi host pointer.
4490 lpfc_get_host_fabric_name (struct Scsi_Host
*shost
)
4492 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4493 struct lpfc_hba
*phba
= vport
->phba
;
4496 spin_lock_irq(shost
->host_lock
);
4498 if ((vport
->fc_flag
& FC_FABRIC
) ||
4499 ((phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) &&
4500 (vport
->fc_flag
& FC_PUBLIC_LOOP
)))
4501 node_name
= wwn_to_u64(phba
->fc_fabparam
.nodeName
.u
.wwn
);
4503 /* fabric is local port if there is no F/FL_Port */
4506 spin_unlock_irq(shost
->host_lock
);
4508 fc_host_fabric_name(shost
) = node_name
;
4512 * lpfc_get_stats - Return statistical information about the adapter
4513 * @shost: kernel scsi host pointer.
4516 * NULL on error for link down, no mbox pool, sli2 active,
4517 * management not allowed, memory allocation error, or mbox error.
4521 * address of the adapter host statistics
4523 static struct fc_host_statistics
*
4524 lpfc_get_stats(struct Scsi_Host
*shost
)
4526 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4527 struct lpfc_hba
*phba
= vport
->phba
;
4528 struct lpfc_sli
*psli
= &phba
->sli
;
4529 struct fc_host_statistics
*hs
= &phba
->link_stats
;
4530 struct lpfc_lnk_stat
* lso
= &psli
->lnk_stat_offsets
;
4531 LPFC_MBOXQ_t
*pmboxq
;
4533 unsigned long seconds
;
4537 * prevent udev from issuing mailbox commands until the port is
4540 if (phba
->link_state
< LPFC_LINK_DOWN
||
4541 !phba
->mbox_mem_pool
||
4542 (phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
) == 0)
4545 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
4548 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4551 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
4553 pmb
= &pmboxq
->u
.mb
;
4554 pmb
->mbxCommand
= MBX_READ_STATUS
;
4555 pmb
->mbxOwner
= OWN_HOST
;
4556 pmboxq
->context1
= NULL
;
4557 pmboxq
->vport
= vport
;
4559 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
4560 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4562 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4564 if (rc
!= MBX_SUCCESS
) {
4565 if (rc
!= MBX_TIMEOUT
)
4566 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4570 memset(hs
, 0, sizeof (struct fc_host_statistics
));
4572 hs
->tx_frames
= pmb
->un
.varRdStatus
.xmitFrameCnt
;
4573 hs
->tx_words
= (pmb
->un
.varRdStatus
.xmitByteCnt
* 256);
4574 hs
->rx_frames
= pmb
->un
.varRdStatus
.rcvFrameCnt
;
4575 hs
->rx_words
= (pmb
->un
.varRdStatus
.rcvByteCnt
* 256);
4577 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
4578 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
4579 pmb
->mbxOwner
= OWN_HOST
;
4580 pmboxq
->context1
= NULL
;
4581 pmboxq
->vport
= vport
;
4583 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
4584 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4586 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4588 if (rc
!= MBX_SUCCESS
) {
4589 if (rc
!= MBX_TIMEOUT
)
4590 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4594 hs
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
4595 hs
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
4596 hs
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
4597 hs
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
4598 hs
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
4599 hs
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
4600 hs
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
4602 hs
->link_failure_count
-= lso
->link_failure_count
;
4603 hs
->loss_of_sync_count
-= lso
->loss_of_sync_count
;
4604 hs
->loss_of_signal_count
-= lso
->loss_of_signal_count
;
4605 hs
->prim_seq_protocol_err_count
-= lso
->prim_seq_protocol_err_count
;
4606 hs
->invalid_tx_word_count
-= lso
->invalid_tx_word_count
;
4607 hs
->invalid_crc_count
-= lso
->invalid_crc_count
;
4608 hs
->error_frames
-= lso
->error_frames
;
4610 if (phba
->hba_flag
& HBA_FCOE_MODE
) {
4612 hs
->nos_count
= (phba
->link_events
>> 1);
4613 hs
->nos_count
-= lso
->link_events
;
4614 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4615 hs
->lip_count
= (phba
->fc_eventTag
>> 1);
4616 hs
->lip_count
-= lso
->link_events
;
4620 hs
->nos_count
= (phba
->fc_eventTag
>> 1);
4621 hs
->nos_count
-= lso
->link_events
;
4624 hs
->dumped_frames
= -1;
4626 seconds
= get_seconds();
4627 if (seconds
< psli
->stats_start
)
4628 hs
->seconds_since_last_reset
= seconds
+
4629 ((unsigned long)-1 - psli
->stats_start
);
4631 hs
->seconds_since_last_reset
= seconds
- psli
->stats_start
;
4633 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4639 * lpfc_reset_stats - Copy the adapter link stats information
4640 * @shost: kernel scsi host pointer.
4643 lpfc_reset_stats(struct Scsi_Host
*shost
)
4645 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4646 struct lpfc_hba
*phba
= vport
->phba
;
4647 struct lpfc_sli
*psli
= &phba
->sli
;
4648 struct lpfc_lnk_stat
*lso
= &psli
->lnk_stat_offsets
;
4649 LPFC_MBOXQ_t
*pmboxq
;
4653 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
4656 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4659 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4661 pmb
= &pmboxq
->u
.mb
;
4662 pmb
->mbxCommand
= MBX_READ_STATUS
;
4663 pmb
->mbxOwner
= OWN_HOST
;
4664 pmb
->un
.varWords
[0] = 0x1; /* reset request */
4665 pmboxq
->context1
= NULL
;
4666 pmboxq
->vport
= vport
;
4668 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4669 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
4670 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4672 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4674 if (rc
!= MBX_SUCCESS
) {
4675 if (rc
!= MBX_TIMEOUT
)
4676 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4680 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
4681 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
4682 pmb
->mbxOwner
= OWN_HOST
;
4683 pmboxq
->context1
= NULL
;
4684 pmboxq
->vport
= vport
;
4686 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
4687 (!(psli
->sli_flag
& LPFC_SLI_ACTIVE
)))
4688 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
4690 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
4692 if (rc
!= MBX_SUCCESS
) {
4693 if (rc
!= MBX_TIMEOUT
)
4694 mempool_free( pmboxq
, phba
->mbox_mem_pool
);
4698 lso
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
4699 lso
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
4700 lso
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
4701 lso
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
4702 lso
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
4703 lso
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
4704 lso
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
4705 if (phba
->hba_flag
& HBA_FCOE_MODE
)
4706 lso
->link_events
= (phba
->link_events
>> 1);
4708 lso
->link_events
= (phba
->fc_eventTag
>> 1);
4710 psli
->stats_start
= get_seconds();
4712 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
4718 * The LPFC driver treats linkdown handling as target loss events so there
4719 * are no sysfs handlers for link_down_tmo.
4723 * lpfc_get_node_by_target - Return the nodelist for a target
4724 * @starget: kernel scsi target pointer.
4727 * address of the node list if found
4728 * NULL target not found
4730 static struct lpfc_nodelist
*
4731 lpfc_get_node_by_target(struct scsi_target
*starget
)
4733 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
4734 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
4735 struct lpfc_nodelist
*ndlp
;
4737 spin_lock_irq(shost
->host_lock
);
4738 /* Search for this, mapped, target ID */
4739 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4740 if (NLP_CHK_NODE_ACT(ndlp
) &&
4741 ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
4742 starget
->id
== ndlp
->nlp_sid
) {
4743 spin_unlock_irq(shost
->host_lock
);
4747 spin_unlock_irq(shost
->host_lock
);
4752 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4753 * @starget: kernel scsi target pointer.
4756 lpfc_get_starget_port_id(struct scsi_target
*starget
)
4758 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
4760 fc_starget_port_id(starget
) = ndlp
? ndlp
->nlp_DID
: -1;
4764 * lpfc_get_starget_node_name - Set the target node name
4765 * @starget: kernel scsi target pointer.
4767 * Description: Set the target node name to the ndlp node name wwn or zero.
4770 lpfc_get_starget_node_name(struct scsi_target
*starget
)
4772 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
4774 fc_starget_node_name(starget
) =
4775 ndlp
? wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
) : 0;
4779 * lpfc_get_starget_port_name - Set the target port name
4780 * @starget: kernel scsi target pointer.
4782 * Description: set the target port name to the ndlp port name wwn or zero.
4785 lpfc_get_starget_port_name(struct scsi_target
*starget
)
4787 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
4789 fc_starget_port_name(starget
) =
4790 ndlp
? wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
) : 0;
4794 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4795 * @rport: fc rport address.
4796 * @timeout: new value for dev loss tmo.
4799 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4800 * dev_loss_tmo to one.
4803 lpfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
4806 rport
->dev_loss_tmo
= timeout
;
4808 rport
->dev_loss_tmo
= 1;
4812 * lpfc_rport_show_function - Return rport target information
4815 * Macro that uses field to generate a function with the name lpfc_show_rport_
4817 * lpfc_show_rport_##field: returns the bytes formatted in buf
4818 * @cdev: class converted to an fc_rport.
4819 * @buf: on return contains the target_field or zero.
4821 * Returns: size of formatted string.
4823 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4825 lpfc_show_rport_##field (struct device *dev, \
4826 struct device_attribute *attr, \
4829 struct fc_rport *rport = transport_class_to_rport(dev); \
4830 struct lpfc_rport_data *rdata = rport->hostdata; \
4831 return snprintf(buf, sz, format_string, \
4832 (rdata->target) ? cast rdata->target->field : 0); \
4835 #define lpfc_rport_rd_attr(field, format_string, sz) \
4836 lpfc_rport_show_function(field, format_string, sz, ) \
4837 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4840 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4841 * @fc_vport: The fc_vport who's symbolic name has been changed.
4844 * This function is called by the transport after the @fc_vport's symbolic name
4845 * has been changed. This function re-registers the symbolic name with the
4846 * switch to propagate the change into the fabric if the vport is active.
4849 lpfc_set_vport_symbolic_name(struct fc_vport
*fc_vport
)
4851 struct lpfc_vport
*vport
= *(struct lpfc_vport
**)fc_vport
->dd_data
;
4853 if (vport
->port_state
== LPFC_VPORT_READY
)
4854 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
4858 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4859 * @phba: Pointer to lpfc_hba struct.
4861 * This function is called by the lpfc_get_cfgparam() routine to set the
4862 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4863 * log message according to the module's lpfc_log_verbose parameter setting
4864 * before hba port or vport created.
4867 lpfc_hba_log_verbose_init(struct lpfc_hba
*phba
, uint32_t verbose
)
4869 phba
->cfg_log_verbose
= verbose
;
4872 struct fc_function_template lpfc_transport_functions
= {
4873 /* fixed attributes the driver supports */
4874 .show_host_node_name
= 1,
4875 .show_host_port_name
= 1,
4876 .show_host_supported_classes
= 1,
4877 .show_host_supported_fc4s
= 1,
4878 .show_host_supported_speeds
= 1,
4879 .show_host_maxframe_size
= 1,
4880 .show_host_symbolic_name
= 1,
4882 /* dynamic attributes the driver supports */
4883 .get_host_port_id
= lpfc_get_host_port_id
,
4884 .show_host_port_id
= 1,
4886 .get_host_port_type
= lpfc_get_host_port_type
,
4887 .show_host_port_type
= 1,
4889 .get_host_port_state
= lpfc_get_host_port_state
,
4890 .show_host_port_state
= 1,
4892 /* active_fc4s is shown but doesn't change (thus no get function) */
4893 .show_host_active_fc4s
= 1,
4895 .get_host_speed
= lpfc_get_host_speed
,
4896 .show_host_speed
= 1,
4898 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
4899 .show_host_fabric_name
= 1,
4902 * The LPFC driver treats linkdown handling as target loss events
4903 * so there are no sysfs handlers for link_down_tmo.
4906 .get_fc_host_stats
= lpfc_get_stats
,
4907 .reset_fc_host_stats
= lpfc_reset_stats
,
4909 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
4910 .show_rport_maxframe_size
= 1,
4911 .show_rport_supported_classes
= 1,
4913 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
4914 .show_rport_dev_loss_tmo
= 1,
4916 .get_starget_port_id
= lpfc_get_starget_port_id
,
4917 .show_starget_port_id
= 1,
4919 .get_starget_node_name
= lpfc_get_starget_node_name
,
4920 .show_starget_node_name
= 1,
4922 .get_starget_port_name
= lpfc_get_starget_port_name
,
4923 .show_starget_port_name
= 1,
4925 .issue_fc_host_lip
= lpfc_issue_lip
,
4926 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
4927 .terminate_rport_io
= lpfc_terminate_rport_io
,
4929 .dd_fcvport_size
= sizeof(struct lpfc_vport
*),
4931 .vport_disable
= lpfc_vport_disable
,
4933 .set_vport_symbolic_name
= lpfc_set_vport_symbolic_name
,
4935 .bsg_request
= lpfc_bsg_request
,
4936 .bsg_timeout
= lpfc_bsg_timeout
,
4939 struct fc_function_template lpfc_vport_transport_functions
= {
4940 /* fixed attributes the driver supports */
4941 .show_host_node_name
= 1,
4942 .show_host_port_name
= 1,
4943 .show_host_supported_classes
= 1,
4944 .show_host_supported_fc4s
= 1,
4945 .show_host_supported_speeds
= 1,
4946 .show_host_maxframe_size
= 1,
4947 .show_host_symbolic_name
= 1,
4949 /* dynamic attributes the driver supports */
4950 .get_host_port_id
= lpfc_get_host_port_id
,
4951 .show_host_port_id
= 1,
4953 .get_host_port_type
= lpfc_get_host_port_type
,
4954 .show_host_port_type
= 1,
4956 .get_host_port_state
= lpfc_get_host_port_state
,
4957 .show_host_port_state
= 1,
4959 /* active_fc4s is shown but doesn't change (thus no get function) */
4960 .show_host_active_fc4s
= 1,
4962 .get_host_speed
= lpfc_get_host_speed
,
4963 .show_host_speed
= 1,
4965 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
4966 .show_host_fabric_name
= 1,
4969 * The LPFC driver treats linkdown handling as target loss events
4970 * so there are no sysfs handlers for link_down_tmo.
4973 .get_fc_host_stats
= lpfc_get_stats
,
4974 .reset_fc_host_stats
= lpfc_reset_stats
,
4976 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
4977 .show_rport_maxframe_size
= 1,
4978 .show_rport_supported_classes
= 1,
4980 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
4981 .show_rport_dev_loss_tmo
= 1,
4983 .get_starget_port_id
= lpfc_get_starget_port_id
,
4984 .show_starget_port_id
= 1,
4986 .get_starget_node_name
= lpfc_get_starget_node_name
,
4987 .show_starget_node_name
= 1,
4989 .get_starget_port_name
= lpfc_get_starget_port_name
,
4990 .show_starget_port_name
= 1,
4992 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
4993 .terminate_rport_io
= lpfc_terminate_rport_io
,
4995 .vport_disable
= lpfc_vport_disable
,
4997 .set_vport_symbolic_name
= lpfc_set_vport_symbolic_name
,
5001 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
5002 * @phba: lpfc_hba pointer.
5005 lpfc_get_cfgparam(struct lpfc_hba
*phba
)
5007 lpfc_cr_delay_init(phba
, lpfc_cr_delay
);
5008 lpfc_cr_count_init(phba
, lpfc_cr_count
);
5009 lpfc_multi_ring_support_init(phba
, lpfc_multi_ring_support
);
5010 lpfc_multi_ring_rctl_init(phba
, lpfc_multi_ring_rctl
);
5011 lpfc_multi_ring_type_init(phba
, lpfc_multi_ring_type
);
5012 lpfc_ack0_init(phba
, lpfc_ack0
);
5013 lpfc_topology_init(phba
, lpfc_topology
);
5014 lpfc_link_speed_init(phba
, lpfc_link_speed
);
5015 lpfc_poll_tmo_init(phba
, lpfc_poll_tmo
);
5016 lpfc_enable_npiv_init(phba
, lpfc_enable_npiv
);
5017 lpfc_fcf_failover_policy_init(phba
, lpfc_fcf_failover_policy
);
5018 lpfc_enable_rrq_init(phba
, lpfc_enable_rrq
);
5019 lpfc_use_msi_init(phba
, lpfc_use_msi
);
5020 lpfc_fcp_imax_init(phba
, lpfc_fcp_imax
);
5021 lpfc_fcp_wq_count_init(phba
, lpfc_fcp_wq_count
);
5022 lpfc_fcp_eq_count_init(phba
, lpfc_fcp_eq_count
);
5023 lpfc_enable_hba_reset_init(phba
, lpfc_enable_hba_reset
);
5024 lpfc_enable_hba_heartbeat_init(phba
, lpfc_enable_hba_heartbeat
);
5025 lpfc_enable_bg_init(phba
, lpfc_enable_bg
);
5026 if (phba
->sli_rev
== LPFC_SLI_REV4
)
5029 phba
->cfg_poll
= lpfc_poll
;
5030 phba
->cfg_soft_wwnn
= 0L;
5031 phba
->cfg_soft_wwpn
= 0L;
5032 lpfc_sg_seg_cnt_init(phba
, lpfc_sg_seg_cnt
);
5033 lpfc_prot_sg_seg_cnt_init(phba
, lpfc_prot_sg_seg_cnt
);
5034 lpfc_hba_queue_depth_init(phba
, lpfc_hba_queue_depth
);
5035 lpfc_hba_log_verbose_init(phba
, lpfc_log_verbose
);
5036 lpfc_aer_support_init(phba
, lpfc_aer_support
);
5037 lpfc_sriov_nr_virtfn_init(phba
, lpfc_sriov_nr_virtfn
);
5038 lpfc_suppress_link_up_init(phba
, lpfc_suppress_link_up
);
5039 lpfc_iocb_cnt_init(phba
, lpfc_iocb_cnt
);
5040 phba
->cfg_enable_dss
= 1;
5045 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5046 * @vport: lpfc_vport pointer.
5049 lpfc_get_vport_cfgparam(struct lpfc_vport
*vport
)
5051 lpfc_log_verbose_init(vport
, lpfc_log_verbose
);
5052 lpfc_lun_queue_depth_init(vport
, lpfc_lun_queue_depth
);
5053 lpfc_tgt_queue_depth_init(vport
, lpfc_tgt_queue_depth
);
5054 lpfc_devloss_tmo_init(vport
, lpfc_devloss_tmo
);
5055 lpfc_nodev_tmo_init(vport
, lpfc_nodev_tmo
);
5056 lpfc_peer_port_login_init(vport
, lpfc_peer_port_login
);
5057 lpfc_restrict_login_init(vport
, lpfc_restrict_login
);
5058 lpfc_fcp_class_init(vport
, lpfc_fcp_class
);
5059 lpfc_use_adisc_init(vport
, lpfc_use_adisc
);
5060 lpfc_max_scsicmpl_time_init(vport
, lpfc_max_scsicmpl_time
);
5061 lpfc_fdmi_on_init(vport
, lpfc_fdmi_on
);
5062 lpfc_discovery_threads_init(vport
, lpfc_discovery_threads
);
5063 lpfc_max_luns_init(vport
, lpfc_max_luns
);
5064 lpfc_scan_down_init(vport
, lpfc_scan_down
);
5065 lpfc_enable_da_id_init(vport
, lpfc_enable_da_id
);