1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_tcq.h>
31 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_logmsg.h"
39 #include "lpfc_version.h"
40 #include "lpfc_compat.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
44 #define LPFC_DEF_DEVLOSS_TMO 30
45 #define LPFC_MIN_DEVLOSS_TMO 1
46 #define LPFC_MAX_DEVLOSS_TMO 255
48 #define LPFC_MAX_LINK_SPEED 8
49 #define LPFC_LINK_SPEED_BITMAP 0x00000117
50 #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
53 * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules.
54 * @incr: integer to convert.
55 * @hdw: ascii string holding converted integer plus a string terminator.
58 * JEDEC Joint Electron Device Engineering Council.
59 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
60 * character string. The string is then terminated with a NULL in byte 9.
61 * Hex 0-9 becomes ascii '0' to '9'.
62 * Hex a-f becomes ascii '=' to 'B' capital B.
65 * Coded for 32 bit integers only.
68 lpfc_jedec_to_ascii(int incr
, char hdw
[])
71 for (i
= 0; i
< 8; i
++) {
74 hdw
[7 - i
] = 0x30 + j
;
76 hdw
[7 - i
] = 0x61 + j
- 10;
84 * lpfc_drvr_version_show: Return the Emulex driver string with version number.
85 * @dev: class unused variable.
86 * @attr: device attribute, not used.
87 * @buf: on return contains the module description text.
89 * Returns: size of formatted string.
92 lpfc_drvr_version_show(struct device
*dev
, struct device_attribute
*attr
,
95 return snprintf(buf
, PAGE_SIZE
, LPFC_MODULE_DESC
"\n");
99 * lpfc_info_show: Return some pci info about the host in ascii.
100 * @dev: class converted to a Scsi_host structure.
101 * @attr: device attribute, not used.
102 * @buf: on return contains the formatted text from lpfc_info().
104 * Returns: size of formatted string.
107 lpfc_info_show(struct device
*dev
, struct device_attribute
*attr
,
110 struct Scsi_Host
*host
= class_to_shost(dev
);
112 return snprintf(buf
, PAGE_SIZE
, "%s\n",lpfc_info(host
));
116 * lpfc_serialnum_show: Return the hba serial number in ascii.
117 * @dev: class converted to a Scsi_host structure.
118 * @attr: device attribute, not used.
119 * @buf: on return contains the formatted text serial number.
121 * Returns: size of formatted string.
124 lpfc_serialnum_show(struct device
*dev
, struct device_attribute
*attr
,
127 struct Scsi_Host
*shost
= class_to_shost(dev
);
128 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
129 struct lpfc_hba
*phba
= vport
->phba
;
131 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->SerialNumber
);
135 * lpfc_temp_sensor_show: Return the temperature sensor level.
136 * @dev: class converted to a Scsi_host structure.
137 * @attr: device attribute, not used.
138 * @buf: on return contains the formatted support level.
141 * Returns a number indicating the temperature sensor level currently
142 * supported, zero or one in ascii.
144 * Returns: size of formatted string.
147 lpfc_temp_sensor_show(struct device
*dev
, struct device_attribute
*attr
,
150 struct Scsi_Host
*shost
= class_to_shost(dev
);
151 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
152 struct lpfc_hba
*phba
= vport
->phba
;
153 return snprintf(buf
, PAGE_SIZE
, "%d\n",phba
->temp_sensor_support
);
157 * lpfc_modeldesc_show: Return the model description of the hba.
158 * @dev: class converted to a Scsi_host structure.
159 * @attr: device attribute, not used.
160 * @buf: on return contains the scsi vpd model description.
162 * Returns: size of formatted string.
165 lpfc_modeldesc_show(struct device
*dev
, struct device_attribute
*attr
,
168 struct Scsi_Host
*shost
= class_to_shost(dev
);
169 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
170 struct lpfc_hba
*phba
= vport
->phba
;
172 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelDesc
);
176 * lpfc_modelname_show: Return the model name of the hba.
177 * @dev: class converted to a Scsi_host structure.
178 * @attr: device attribute, not used.
179 * @buf: on return contains the scsi vpd model name.
181 * Returns: size of formatted string.
184 lpfc_modelname_show(struct device
*dev
, struct device_attribute
*attr
,
187 struct Scsi_Host
*shost
= class_to_shost(dev
);
188 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
189 struct lpfc_hba
*phba
= vport
->phba
;
191 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ModelName
);
195 * lpfc_programtype_show: Return the program type of the hba.
196 * @dev: class converted to a Scsi_host structure.
197 * @attr: device attribute, not used.
198 * @buf: on return contains the scsi vpd program type.
200 * Returns: size of formatted string.
203 lpfc_programtype_show(struct device
*dev
, struct device_attribute
*attr
,
206 struct Scsi_Host
*shost
= class_to_shost(dev
);
207 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
208 struct lpfc_hba
*phba
= vport
->phba
;
210 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->ProgramType
);
214 * lpfc_vportnum_show: Return the port number in ascii of the hba.
215 * @dev: class converted to a Scsi_host structure.
216 * @attr: device attribute, not used.
217 * @buf: on return contains scsi vpd program type.
219 * Returns: size of formatted string.
222 lpfc_vportnum_show(struct device
*dev
, struct device_attribute
*attr
,
225 struct Scsi_Host
*shost
= class_to_shost(dev
);
226 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
227 struct lpfc_hba
*phba
= vport
->phba
;
229 return snprintf(buf
, PAGE_SIZE
, "%s\n",phba
->Port
);
233 * lpfc_fwrev_show: Return the firmware rev running in the hba.
234 * @dev: class converted to a Scsi_host structure.
235 * @attr: device attribute, not used.
236 * @buf: on return contains the scsi vpd program type.
238 * Returns: size of formatted string.
241 lpfc_fwrev_show(struct device
*dev
, struct device_attribute
*attr
,
244 struct Scsi_Host
*shost
= class_to_shost(dev
);
245 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
246 struct lpfc_hba
*phba
= vport
->phba
;
249 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
250 return snprintf(buf
, PAGE_SIZE
, "%s, sli-%d\n", fwrev
, phba
->sli_rev
);
254 * lpfc_hdw_show: Return the jedec information about the hba.
255 * @dev: class converted to a Scsi_host structure.
256 * @attr: device attribute, not used.
257 * @buf: on return contains the scsi vpd program type.
259 * Returns: size of formatted string.
262 lpfc_hdw_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
265 struct Scsi_Host
*shost
= class_to_shost(dev
);
266 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
267 struct lpfc_hba
*phba
= vport
->phba
;
268 lpfc_vpd_t
*vp
= &phba
->vpd
;
270 lpfc_jedec_to_ascii(vp
->rev
.biuRev
, hdw
);
271 return snprintf(buf
, PAGE_SIZE
, "%s\n", hdw
);
275 * lpfc_option_rom_version_show: Return the adapter ROM FCode version.
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the ROM and FCode ascii strings.
280 * Returns: size of formatted string.
283 lpfc_option_rom_version_show(struct device
*dev
, struct device_attribute
*attr
,
286 struct Scsi_Host
*shost
= class_to_shost(dev
);
287 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
288 struct lpfc_hba
*phba
= vport
->phba
;
290 return snprintf(buf
, PAGE_SIZE
, "%s\n", phba
->OptionROMVersion
);
294 * lpfc_state_show: Return the link state of the port.
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains text describing the state of the link.
300 * The switch statement has no default so zero will be returned.
302 * Returns: size of formatted string.
305 lpfc_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
308 struct Scsi_Host
*shost
= class_to_shost(dev
);
309 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
310 struct lpfc_hba
*phba
= vport
->phba
;
313 switch (phba
->link_state
) {
314 case LPFC_LINK_UNKNOWN
:
315 case LPFC_WARM_START
:
316 case LPFC_INIT_START
:
317 case LPFC_INIT_MBX_CMDS
:
320 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Down\n");
325 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Link Up - ");
327 switch (vport
->port_state
) {
328 case LPFC_LOCAL_CFG_LINK
:
329 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
330 "Configuring Link\n");
334 case LPFC_FABRIC_CFG_LINK
:
337 case LPFC_BUILD_DISC_LIST
:
339 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
342 case LPFC_VPORT_READY
:
343 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Ready\n");
346 case LPFC_VPORT_FAILED
:
347 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "Failed\n");
350 case LPFC_VPORT_UNKNOWN
:
351 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
356 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
357 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
358 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
361 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
364 if (vport
->fc_flag
& FC_FABRIC
)
365 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
368 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
377 * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports.
378 * @dev: class device that is converted into a Scsi_host.
379 * @attr: device attribute, not used.
380 * @buf: on return contains the sum of fc mapped and unmapped.
383 * Returns the ascii text number of the sum of the fc mapped and unmapped
386 * Returns: size of formatted string.
389 lpfc_num_discovered_ports_show(struct device
*dev
,
390 struct device_attribute
*attr
, char *buf
)
392 struct Scsi_Host
*shost
= class_to_shost(dev
);
393 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
395 return snprintf(buf
, PAGE_SIZE
, "%d\n",
396 vport
->fc_map_cnt
+ vport
->fc_unmap_cnt
);
400 * lpfc_issue_lip: Misnomer, name carried over from long ago.
401 * @shost: Scsi_Host pointer.
404 * Bring the link down gracefully then re-init the link. The firmware will
405 * re-init the fiber channel interface as required. Does not issue a LIP.
408 * -EPERM port offline or management commands are being blocked
409 * -ENOMEM cannot allocate memory for the mailbox command
410 * -EIO error sending the mailbox command
414 lpfc_issue_lip(struct Scsi_Host
*shost
)
416 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
417 struct lpfc_hba
*phba
= vport
->phba
;
418 LPFC_MBOXQ_t
*pmboxq
;
419 int mbxstatus
= MBXERR_ERROR
;
421 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
422 (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
))
425 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
430 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
431 pmboxq
->mb
.mbxCommand
= MBX_DOWN_LINK
;
432 pmboxq
->mb
.mbxOwner
= OWN_HOST
;
434 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, LPFC_MBOX_TMO
* 2);
436 if ((mbxstatus
== MBX_SUCCESS
) && (pmboxq
->mb
.mbxStatus
== 0)) {
437 memset((void *)pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
438 lpfc_init_link(phba
, pmboxq
, phba
->cfg_topology
,
439 phba
->cfg_link_speed
);
440 mbxstatus
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
,
444 lpfc_set_loopback_flag(phba
);
445 if (mbxstatus
!= MBX_TIMEOUT
)
446 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
448 if (mbxstatus
== MBXERR_ERROR
)
455 * lpfc_do_offline: Issues a mailbox command to bring the link down.
456 * @phba: lpfc_hba pointer.
457 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
460 * Assumes any error from lpfc_do_offline() will be negative.
461 * Can wait up to 5 seconds for the port ring buffers count
462 * to reach zero, prints a warning if it is not zero and continues.
463 * lpfc_workq_post_event() returns a non-zero return coce if call fails.
466 * -EIO error posting the event
470 lpfc_do_offline(struct lpfc_hba
*phba
, uint32_t type
)
472 struct completion online_compl
;
473 struct lpfc_sli_ring
*pring
;
474 struct lpfc_sli
*psli
;
479 init_completion(&online_compl
);
480 lpfc_workq_post_event(phba
, &status
, &online_compl
,
481 LPFC_EVT_OFFLINE_PREP
);
482 wait_for_completion(&online_compl
);
489 /* Wait a little for things to settle down, but not
490 * long enough for dev loss timeout to expire.
492 for (i
= 0; i
< psli
->num_rings
; i
++) {
493 pring
= &psli
->ring
[i
];
494 while (pring
->txcmplq_cnt
) {
496 if (cnt
++ > 500) { /* 5 secs */
497 lpfc_printf_log(phba
,
498 KERN_WARNING
, LOG_INIT
,
499 "0466 Outstanding IO when "
500 "bringing Adapter offline\n");
506 init_completion(&online_compl
);
507 lpfc_workq_post_event(phba
, &status
, &online_compl
, type
);
508 wait_for_completion(&online_compl
);
517 * lpfc_selective_reset: Offline then onlines the port.
518 * @phba: lpfc_hba pointer.
521 * If the port is configured to allow a reset then the hba is brought
522 * offline then online.
525 * Assumes any error from lpfc_do_offline() will be negative.
528 * lpfc_do_offline() return code if not zero
529 * -EIO reset not configured or error posting the event
533 lpfc_selective_reset(struct lpfc_hba
*phba
)
535 struct completion online_compl
;
538 if (!phba
->cfg_enable_hba_reset
)
541 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
546 init_completion(&online_compl
);
547 lpfc_workq_post_event(phba
, &status
, &online_compl
,
549 wait_for_completion(&online_compl
);
558 * lpfc_issue_reset: Selectively resets an adapter.
559 * @dev: class device that is converted into a Scsi_host.
560 * @attr: device attribute, not used.
561 * @buf: containing the string "selective".
562 * @count: unused variable.
565 * If the buf contains the string "selective" then lpfc_selective_reset()
566 * is called to perform the reset.
569 * Assumes any error from lpfc_selective_reset() will be negative.
570 * If lpfc_selective_reset() returns zero then the length of the buffer
571 * is returned which indicates succcess
574 * -EINVAL if the buffer does not contain the string "selective"
575 * length of buf if lpfc-selective_reset() if the call succeeds
576 * return value of lpfc_selective_reset() if the call fails
579 lpfc_issue_reset(struct device
*dev
, struct device_attribute
*attr
,
580 const char *buf
, size_t count
)
582 struct Scsi_Host
*shost
= class_to_shost(dev
);
583 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
584 struct lpfc_hba
*phba
= vport
->phba
;
586 int status
= -EINVAL
;
588 if (strncmp(buf
, "selective", sizeof("selective") - 1) == 0)
589 status
= lpfc_selective_reset(phba
);
598 * lpfc_nport_evt_cnt_show: Return the number of nport events.
599 * @dev: class device that is converted into a Scsi_host.
600 * @attr: device attribute, not used.
601 * @buf: on return contains the ascii number of nport events.
603 * Returns: size of formatted string.
606 lpfc_nport_evt_cnt_show(struct device
*dev
, struct device_attribute
*attr
,
609 struct Scsi_Host
*shost
= class_to_shost(dev
);
610 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
611 struct lpfc_hba
*phba
= vport
->phba
;
613 return snprintf(buf
, PAGE_SIZE
, "%d\n", phba
->nport_event_cnt
);
617 * lpfc_board_mode_show: Return the state of the board.
618 * @dev: class device that is converted into a Scsi_host.
619 * @attr: device attribute, not used.
620 * @buf: on return contains the state of the adapter.
622 * Returns: size of formatted string.
625 lpfc_board_mode_show(struct device
*dev
, struct device_attribute
*attr
,
628 struct Scsi_Host
*shost
= class_to_shost(dev
);
629 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
630 struct lpfc_hba
*phba
= vport
->phba
;
633 if (phba
->link_state
== LPFC_HBA_ERROR
)
635 else if (phba
->link_state
== LPFC_WARM_START
)
636 state
= "warm start";
637 else if (phba
->link_state
== LPFC_INIT_START
)
642 return snprintf(buf
, PAGE_SIZE
, "%s\n", state
);
646 * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state.
647 * @dev: class device that is converted into a Scsi_host.
648 * @attr: device attribute, not used.
649 * @buf: containing one of the strings "online", "offline", "warm" or "error".
650 * @count: unused variable.
653 * -EACCES if enable hba reset not enabled
654 * -EINVAL if the buffer does not contain a valid string (see above)
655 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
656 * buf length greater than zero indicates success
659 lpfc_board_mode_store(struct device
*dev
, struct device_attribute
*attr
,
660 const char *buf
, size_t count
)
662 struct Scsi_Host
*shost
= class_to_shost(dev
);
663 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
664 struct lpfc_hba
*phba
= vport
->phba
;
665 struct completion online_compl
;
668 if (!phba
->cfg_enable_hba_reset
)
670 init_completion(&online_compl
);
672 if(strncmp(buf
, "online", sizeof("online") - 1) == 0) {
673 lpfc_workq_post_event(phba
, &status
, &online_compl
,
675 wait_for_completion(&online_compl
);
676 } else if (strncmp(buf
, "offline", sizeof("offline") - 1) == 0)
677 status
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
678 else if (strncmp(buf
, "warm", sizeof("warm") - 1) == 0)
679 status
= lpfc_do_offline(phba
, LPFC_EVT_WARM_START
);
680 else if (strncmp(buf
, "error", sizeof("error") - 1) == 0)
681 status
= lpfc_do_offline(phba
, LPFC_EVT_KILL
);
692 * lpfc_get_hba_info: Return various bits of informaton about the adapter.
693 * @phba: pointer to the adapter structure.
694 * @mxri max xri count.
695 * @axri available xri count.
696 * @mrpi max rpi count.
697 * @arpi available rpi count.
698 * @mvpi max vpi count.
699 * @avpi available vpi count.
702 * If an integer pointer for an count is not null then the value for the
710 lpfc_get_hba_info(struct lpfc_hba
*phba
,
711 uint32_t *mxri
, uint32_t *axri
,
712 uint32_t *mrpi
, uint32_t *arpi
,
713 uint32_t *mvpi
, uint32_t *avpi
)
715 struct lpfc_sli
*psli
= &phba
->sli
;
716 LPFC_MBOXQ_t
*pmboxq
;
721 * prevent udev from issuing mailbox commands until the port is
724 if (phba
->link_state
< LPFC_LINK_DOWN
||
725 !phba
->mbox_mem_pool
||
726 (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
) == 0)
729 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
732 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
735 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
738 pmb
->mbxCommand
= MBX_READ_CONFIG
;
739 pmb
->mbxOwner
= OWN_HOST
;
740 pmboxq
->context1
= NULL
;
742 if ((phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) ||
743 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
744 rc
= MBX_NOT_FINISHED
;
746 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
748 if (rc
!= MBX_SUCCESS
) {
749 if (rc
!= MBX_TIMEOUT
)
750 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
755 *mrpi
= pmb
->un
.varRdConfig
.max_rpi
;
757 *arpi
= pmb
->un
.varRdConfig
.avail_rpi
;
759 *mxri
= pmb
->un
.varRdConfig
.max_xri
;
761 *axri
= pmb
->un
.varRdConfig
.avail_xri
;
763 *mvpi
= pmb
->un
.varRdConfig
.max_vpi
;
765 *avpi
= pmb
->un
.varRdConfig
.avail_vpi
;
767 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
772 * lpfc_max_rpi_show: Return maximum rpi.
773 * @dev: class device that is converted into a Scsi_host.
774 * @attr: device attribute, not used.
775 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
778 * Calls lpfc_get_hba_info() asking for just the mrpi count.
779 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
780 * to "Unknown" and the buffer length is returned, therefore the caller
781 * must check for "Unknown" in the buffer to detect a failure.
783 * Returns: size of formatted string.
786 lpfc_max_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
789 struct Scsi_Host
*shost
= class_to_shost(dev
);
790 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
791 struct lpfc_hba
*phba
= vport
->phba
;
794 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, NULL
, NULL
, NULL
))
795 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
796 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
800 * lpfc_used_rpi_show: Return maximum rpi minus available rpi.
801 * @dev: class device that is converted into a Scsi_host.
802 * @attr: device attribute, not used.
803 * @buf: containing the used rpi count in decimal or "Unknown".
806 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
807 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
808 * to "Unknown" and the buffer length is returned, therefore the caller
809 * must check for "Unknown" in the buffer to detect a failure.
811 * Returns: size of formatted string.
814 lpfc_used_rpi_show(struct device
*dev
, struct device_attribute
*attr
,
817 struct Scsi_Host
*shost
= class_to_shost(dev
);
818 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
819 struct lpfc_hba
*phba
= vport
->phba
;
822 if (lpfc_get_hba_info(phba
, NULL
, NULL
, &cnt
, &acnt
, NULL
, NULL
))
823 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
824 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
828 * lpfc_max_xri_show: Return maximum xri.
829 * @dev: class device that is converted into a Scsi_host.
830 * @attr: device attribute, not used.
831 * @buf: on return contains the maximum xri count in decimal or "Unknown".
834 * Calls lpfc_get_hba_info() asking for just the mrpi count.
835 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
836 * to "Unknown" and the buffer length is returned, therefore the caller
837 * must check for "Unknown" in the buffer to detect a failure.
839 * Returns: size of formatted string.
842 lpfc_max_xri_show(struct device
*dev
, struct device_attribute
*attr
,
845 struct Scsi_Host
*shost
= class_to_shost(dev
);
846 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
847 struct lpfc_hba
*phba
= vport
->phba
;
850 if (lpfc_get_hba_info(phba
, &cnt
, NULL
, NULL
, NULL
, NULL
, NULL
))
851 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
852 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
856 * lpfc_used_xri_show: Return maximum xpi minus the available xpi.
857 * @dev: class device that is converted into a Scsi_host.
858 * @attr: device attribute, not used.
859 * @buf: on return contains the used xri count in decimal or "Unknown".
862 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
863 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
864 * to "Unknown" and the buffer length is returned, therefore the caller
865 * must check for "Unknown" in the buffer to detect a failure.
867 * Returns: size of formatted string.
870 lpfc_used_xri_show(struct device
*dev
, struct device_attribute
*attr
,
873 struct Scsi_Host
*shost
= class_to_shost(dev
);
874 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
875 struct lpfc_hba
*phba
= vport
->phba
;
878 if (lpfc_get_hba_info(phba
, &cnt
, &acnt
, NULL
, NULL
, NULL
, NULL
))
879 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
880 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
884 * lpfc_max_vpi_show: Return maximum vpi.
885 * @dev: class device that is converted into a Scsi_host.
886 * @attr: device attribute, not used.
887 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
890 * Calls lpfc_get_hba_info() asking for just the mvpi count.
891 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
892 * to "Unknown" and the buffer length is returned, therefore the caller
893 * must check for "Unknown" in the buffer to detect a failure.
895 * Returns: size of formatted string.
898 lpfc_max_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
901 struct Scsi_Host
*shost
= class_to_shost(dev
);
902 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
903 struct lpfc_hba
*phba
= vport
->phba
;
906 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, NULL
))
907 return snprintf(buf
, PAGE_SIZE
, "%d\n", cnt
);
908 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
912 * lpfc_used_vpi_show: Return maximum vpi minus the available vpi.
913 * @dev: class device that is converted into a Scsi_host.
914 * @attr: device attribute, not used.
915 * @buf: on return contains the used vpi count in decimal or "Unknown".
918 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
919 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
920 * to "Unknown" and the buffer length is returned, therefore the caller
921 * must check for "Unknown" in the buffer to detect a failure.
923 * Returns: size of formatted string.
926 lpfc_used_vpi_show(struct device
*dev
, struct device_attribute
*attr
,
929 struct Scsi_Host
*shost
= class_to_shost(dev
);
930 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
931 struct lpfc_hba
*phba
= vport
->phba
;
934 if (lpfc_get_hba_info(phba
, NULL
, NULL
, NULL
, NULL
, &cnt
, &acnt
))
935 return snprintf(buf
, PAGE_SIZE
, "%d\n", (cnt
- acnt
));
936 return snprintf(buf
, PAGE_SIZE
, "Unknown\n");
940 * lpfc_npiv_info_show: Return text about NPIV support for the adapter.
941 * @dev: class device that is converted into a Scsi_host.
942 * @attr: device attribute, not used.
943 * @buf: text that must be interpreted to determine if npiv is supported.
946 * Buffer will contain text indicating npiv is not suppoerted on the port,
947 * the port is an NPIV physical port, or it is an npiv virtual port with
948 * the id of the vport.
950 * Returns: size of formatted string.
953 lpfc_npiv_info_show(struct device
*dev
, struct device_attribute
*attr
,
956 struct Scsi_Host
*shost
= class_to_shost(dev
);
957 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
958 struct lpfc_hba
*phba
= vport
->phba
;
960 if (!(phba
->max_vpi
))
961 return snprintf(buf
, PAGE_SIZE
, "NPIV Not Supported\n");
962 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
963 return snprintf(buf
, PAGE_SIZE
, "NPIV Physical\n");
964 return snprintf(buf
, PAGE_SIZE
, "NPIV Virtual (VPI %d)\n", vport
->vpi
);
968 * lpfc_poll_show: Return text about poll support for the adapter.
969 * @dev: class device that is converted into a Scsi_host.
970 * @attr: device attribute, not used.
971 * @buf: on return contains the cfg_poll in hex.
974 * cfg_poll should be a lpfc_polling_flags type.
976 * Returns: size of formatted string.
979 lpfc_poll_show(struct device
*dev
, struct device_attribute
*attr
,
982 struct Scsi_Host
*shost
= class_to_shost(dev
);
983 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
984 struct lpfc_hba
*phba
= vport
->phba
;
986 return snprintf(buf
, PAGE_SIZE
, "%#x\n", phba
->cfg_poll
);
990 * lpfc_poll_store: Set the value of cfg_poll for the adapter.
991 * @dev: class device that is converted into a Scsi_host.
992 * @attr: device attribute, not used.
993 * @buf: one or more lpfc_polling_flags values.
997 * buf contents converted to integer and checked for a valid value.
1000 * -EINVAL if the buffer connot be converted or is out of range
1001 * length of the buf on success
1004 lpfc_poll_store(struct device
*dev
, struct device_attribute
*attr
,
1005 const char *buf
, size_t count
)
1007 struct Scsi_Host
*shost
= class_to_shost(dev
);
1008 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1009 struct lpfc_hba
*phba
= vport
->phba
;
1014 if (!isdigit(buf
[0]))
1017 if (sscanf(buf
, "%i", &val
) != 1)
1020 if ((val
& 0x3) != val
)
1023 spin_lock_irq(&phba
->hbalock
);
1025 old_val
= phba
->cfg_poll
;
1027 if (val
& ENABLE_FCP_RING_POLLING
) {
1028 if ((val
& DISABLE_FCP_RING_INT
) &&
1029 !(old_val
& DISABLE_FCP_RING_INT
)) {
1030 creg_val
= readl(phba
->HCregaddr
);
1031 creg_val
&= ~(HC_R0INT_ENA
<< LPFC_FCP_RING
);
1032 writel(creg_val
, phba
->HCregaddr
);
1033 readl(phba
->HCregaddr
); /* flush */
1035 lpfc_poll_start_timer(phba
);
1037 } else if (val
!= 0x0) {
1038 spin_unlock_irq(&phba
->hbalock
);
1042 if (!(val
& DISABLE_FCP_RING_INT
) &&
1043 (old_val
& DISABLE_FCP_RING_INT
))
1045 spin_unlock_irq(&phba
->hbalock
);
1046 del_timer(&phba
->fcp_poll_timer
);
1047 spin_lock_irq(&phba
->hbalock
);
1048 creg_val
= readl(phba
->HCregaddr
);
1049 creg_val
|= (HC_R0INT_ENA
<< LPFC_FCP_RING
);
1050 writel(creg_val
, phba
->HCregaddr
);
1051 readl(phba
->HCregaddr
); /* flush */
1054 phba
->cfg_poll
= val
;
1056 spin_unlock_irq(&phba
->hbalock
);
1062 * lpfc_param_show: Return a cfg attribute value in decimal.
1065 * Macro that given an attr e.g. hba_queue_depth expands
1066 * into a function with the name lpfc_hba_queue_depth_show.
1068 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1069 * @dev: class device that is converted into a Scsi_host.
1070 * @attr: device attribute, not used.
1071 * @buf: on return contains the attribute value in decimal.
1073 * Returns: size of formatted string.
1075 #define lpfc_param_show(attr) \
1077 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1080 struct Scsi_Host *shost = class_to_shost(dev);\
1081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1082 struct lpfc_hba *phba = vport->phba;\
1084 val = phba->cfg_##attr;\
1085 return snprintf(buf, PAGE_SIZE, "%d\n",\
1090 * lpfc_param_hex_show: Return a cfg attribute value in hex.
1093 * Macro that given an attr e.g. hba_queue_depth expands
1094 * into a function with the name lpfc_hba_queue_depth_show
1096 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1097 * @dev: class device that is converted into a Scsi_host.
1098 * @attr: device attribute, not used.
1099 * @buf: on return contains the attribute value in hexidecimal.
1101 * Returns: size of formatted string.
1103 #define lpfc_param_hex_show(attr) \
1105 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1108 struct Scsi_Host *shost = class_to_shost(dev);\
1109 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1110 struct lpfc_hba *phba = vport->phba;\
1112 val = phba->cfg_##attr;\
1113 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1118 * lpfc_param_init: Intializes a cfg attribute.
1121 * Macro that given an attr e.g. hba_queue_depth expands
1122 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1123 * takes a default argument, a minimum and maximum argument.
1125 * lpfc_##attr##_init: Initializes an attribute.
1126 * @phba: pointer the the adapter structure.
1127 * @val: integer attribute value.
1129 * Validates the min and max values then sets the adapter config field
1130 * accordingly, or uses the default if out of range and prints an error message.
1134 * -EINVAL if default used
1136 #define lpfc_param_init(attr, default, minval, maxval) \
1138 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1140 if (val >= minval && val <= maxval) {\
1141 phba->cfg_##attr = val;\
1144 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1145 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1146 "allowed range is ["#minval", "#maxval"]\n", val); \
1147 phba->cfg_##attr = default;\
1152 * lpfc_param_set: Set a cfg attribute value.
1155 * Macro that given an attr e.g. hba_queue_depth expands
1156 * into a function with the name lpfc_hba_queue_depth_set
1158 * lpfc_##attr##_set: Sets an attribute value.
1159 * @phba: pointer the the adapter structure.
1160 * @val: integer attribute value.
1163 * Validates the min and max values then sets the
1164 * adapter config field if in the valid range. prints error message
1165 * and does not set the parameter if invalid.
1169 * -EINVAL if val is invalid
1171 #define lpfc_param_set(attr, default, minval, maxval) \
1173 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
1175 if (val >= minval && val <= maxval) {\
1176 phba->cfg_##attr = val;\
1179 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1180 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1181 "allowed range is ["#minval", "#maxval"]\n", val); \
1186 * lpfc_param_store: Set a vport attribute value.
1189 * Macro that given an attr e.g. hba_queue_depth expands
1190 * into a function with the name lpfc_hba_queue_depth_store.
1192 * lpfc_##attr##_store: Set an sttribute value.
1193 * @dev: class device that is converted into a Scsi_host.
1194 * @attr: device attribute, not used.
1195 * @buf: contains the attribute value in ascii.
1199 * Convert the ascii text number to an integer, then
1200 * use the lpfc_##attr##_set function to set the value.
1203 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1204 * length of buffer upon success.
1206 #define lpfc_param_store(attr) \
1208 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1209 const char *buf, size_t count) \
1211 struct Scsi_Host *shost = class_to_shost(dev);\
1212 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1213 struct lpfc_hba *phba = vport->phba;\
1215 if (!isdigit(buf[0]))\
1217 if (sscanf(buf, "%i", &val) != 1)\
1219 if (lpfc_##attr##_set(phba, val) == 0) \
1220 return strlen(buf);\
1226 * lpfc_vport_param_show: Return decimal formatted cfg attribute value.
1229 * Macro that given an attr e.g. hba_queue_depth expands
1230 * into a function with the name lpfc_hba_queue_depth_show
1232 * lpfc_##attr##_show: prints the attribute value in decimal.
1233 * @dev: class device that is converted into a Scsi_host.
1234 * @attr: device attribute, not used.
1235 * @buf: on return contains the attribute value in decimal.
1237 * Returns: length of formatted string.
1239 #define lpfc_vport_param_show(attr) \
1241 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1244 struct Scsi_Host *shost = class_to_shost(dev);\
1245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1247 val = vport->cfg_##attr;\
1248 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1252 * lpfc_vport_param_hex_show: Return hex formatted attribute value.
1255 * Macro that given an attr e.g.
1256 * hba_queue_depth expands into a function with the name
1257 * lpfc_hba_queue_depth_show
1259 * lpfc_##attr##_show: prints the attribute value in hexidecimal.
1260 * @dev: class device that is converted into a Scsi_host.
1261 * @attr: device attribute, not used.
1262 * @buf: on return contains the attribute value in hexidecimal.
1264 * Returns: length of formatted string.
1266 #define lpfc_vport_param_hex_show(attr) \
1268 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1271 struct Scsi_Host *shost = class_to_shost(dev);\
1272 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1274 val = vport->cfg_##attr;\
1275 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1279 * lpfc_vport_param_init: Initialize a vport cfg attribute.
1282 * Macro that given an attr e.g. hba_queue_depth expands
1283 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1284 * takes a default argument, a minimum and maximum argument.
1286 * lpfc_##attr##_init: validates the min and max values then sets the
1287 * adapter config field accordingly, or uses the default if out of range
1288 * and prints an error message.
1289 * @phba: pointer the the adapter structure.
1290 * @val: integer attribute value.
1294 * -EINVAL if default used
1296 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1298 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1300 if (val >= minval && val <= maxval) {\
1301 vport->cfg_##attr = val;\
1304 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1305 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1306 "allowed range is ["#minval", "#maxval"]\n", val); \
1307 vport->cfg_##attr = default;\
1312 * lpfc_vport_param_set: Set a vport cfg attribute.
1315 * Macro that given an attr e.g. hba_queue_depth expands
1316 * into a function with the name lpfc_hba_queue_depth_set
1318 * lpfc_##attr##_set: validates the min and max values then sets the
1319 * adapter config field if in the valid range. prints error message
1320 * and does not set the parameter if invalid.
1321 * @phba: pointer the the adapter structure.
1322 * @val: integer attribute value.
1326 * -EINVAL if val is invalid
1328 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1330 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
1332 if (val >= minval && val <= maxval) {\
1333 vport->cfg_##attr = val;\
1336 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1337 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1338 "allowed range is ["#minval", "#maxval"]\n", val); \
1343 * lpfc_vport_param_store: Set a vport attribute.
1346 * Macro that given an attr e.g. hba_queue_depth
1347 * expands into a function with the name lpfc_hba_queue_depth_store
1349 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1350 * use the lpfc_##attr##_set function to set the value.
1351 * @cdev: class device that is converted into a Scsi_host.
1352 * @buf: contains the attribute value in decimal.
1356 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1357 * length of buffer upon success.
1359 #define lpfc_vport_param_store(attr) \
1361 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1362 const char *buf, size_t count) \
1364 struct Scsi_Host *shost = class_to_shost(dev);\
1365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1367 if (!isdigit(buf[0]))\
1369 if (sscanf(buf, "%i", &val) != 1)\
1371 if (lpfc_##attr##_set(vport, val) == 0) \
1372 return strlen(buf);\
1378 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1379 static int lpfc_##name = defval;\
1380 module_param(lpfc_##name, int, 0);\
1381 MODULE_PARM_DESC(lpfc_##name, desc);\
1382 lpfc_param_init(name, defval, minval, maxval)
1384 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1385 static int lpfc_##name = defval;\
1386 module_param(lpfc_##name, int, 0);\
1387 MODULE_PARM_DESC(lpfc_##name, desc);\
1388 lpfc_param_show(name)\
1389 lpfc_param_init(name, defval, minval, maxval)\
1390 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1392 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1393 static int lpfc_##name = defval;\
1394 module_param(lpfc_##name, int, 0);\
1395 MODULE_PARM_DESC(lpfc_##name, desc);\
1396 lpfc_param_show(name)\
1397 lpfc_param_init(name, defval, minval, maxval)\
1398 lpfc_param_set(name, defval, minval, maxval)\
1399 lpfc_param_store(name)\
1400 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1401 lpfc_##name##_show, lpfc_##name##_store)
1403 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1404 static int lpfc_##name = defval;\
1405 module_param(lpfc_##name, int, 0);\
1406 MODULE_PARM_DESC(lpfc_##name, desc);\
1407 lpfc_param_hex_show(name)\
1408 lpfc_param_init(name, defval, minval, maxval)\
1409 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1411 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1412 static int lpfc_##name = defval;\
1413 module_param(lpfc_##name, int, 0);\
1414 MODULE_PARM_DESC(lpfc_##name, desc);\
1415 lpfc_param_hex_show(name)\
1416 lpfc_param_init(name, defval, minval, maxval)\
1417 lpfc_param_set(name, defval, minval, maxval)\
1418 lpfc_param_store(name)\
1419 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1420 lpfc_##name##_show, lpfc_##name##_store)
1422 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1423 static int lpfc_##name = defval;\
1424 module_param(lpfc_##name, int, 0);\
1425 MODULE_PARM_DESC(lpfc_##name, desc);\
1426 lpfc_vport_param_init(name, defval, minval, maxval)
1428 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1429 static int lpfc_##name = defval;\
1430 module_param(lpfc_##name, int, 0);\
1431 MODULE_PARM_DESC(lpfc_##name, desc);\
1432 lpfc_vport_param_show(name)\
1433 lpfc_vport_param_init(name, defval, minval, maxval)\
1434 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1436 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1437 static int lpfc_##name = defval;\
1438 module_param(lpfc_##name, int, 0);\
1439 MODULE_PARM_DESC(lpfc_##name, desc);\
1440 lpfc_vport_param_show(name)\
1441 lpfc_vport_param_init(name, defval, minval, maxval)\
1442 lpfc_vport_param_set(name, defval, minval, maxval)\
1443 lpfc_vport_param_store(name)\
1444 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1445 lpfc_##name##_show, lpfc_##name##_store)
1447 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1448 static int lpfc_##name = defval;\
1449 module_param(lpfc_##name, int, 0);\
1450 MODULE_PARM_DESC(lpfc_##name, desc);\
1451 lpfc_vport_param_hex_show(name)\
1452 lpfc_vport_param_init(name, defval, minval, maxval)\
1453 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1455 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1456 static int lpfc_##name = defval;\
1457 module_param(lpfc_##name, int, 0);\
1458 MODULE_PARM_DESC(lpfc_##name, desc);\
1459 lpfc_vport_param_hex_show(name)\
1460 lpfc_vport_param_init(name, defval, minval, maxval)\
1461 lpfc_vport_param_set(name, defval, minval, maxval)\
1462 lpfc_vport_param_store(name)\
1463 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1464 lpfc_##name##_show, lpfc_##name##_store)
1466 static DEVICE_ATTR(info
, S_IRUGO
, lpfc_info_show
, NULL
);
1467 static DEVICE_ATTR(serialnum
, S_IRUGO
, lpfc_serialnum_show
, NULL
);
1468 static DEVICE_ATTR(modeldesc
, S_IRUGO
, lpfc_modeldesc_show
, NULL
);
1469 static DEVICE_ATTR(modelname
, S_IRUGO
, lpfc_modelname_show
, NULL
);
1470 static DEVICE_ATTR(programtype
, S_IRUGO
, lpfc_programtype_show
, NULL
);
1471 static DEVICE_ATTR(portnum
, S_IRUGO
, lpfc_vportnum_show
, NULL
);
1472 static DEVICE_ATTR(fwrev
, S_IRUGO
, lpfc_fwrev_show
, NULL
);
1473 static DEVICE_ATTR(hdw
, S_IRUGO
, lpfc_hdw_show
, NULL
);
1474 static DEVICE_ATTR(link_state
, S_IRUGO
, lpfc_link_state_show
, NULL
);
1475 static DEVICE_ATTR(option_rom_version
, S_IRUGO
,
1476 lpfc_option_rom_version_show
, NULL
);
1477 static DEVICE_ATTR(num_discovered_ports
, S_IRUGO
,
1478 lpfc_num_discovered_ports_show
, NULL
);
1479 static DEVICE_ATTR(nport_evt_cnt
, S_IRUGO
, lpfc_nport_evt_cnt_show
, NULL
);
1480 static DEVICE_ATTR(lpfc_drvr_version
, S_IRUGO
, lpfc_drvr_version_show
, NULL
);
1481 static DEVICE_ATTR(board_mode
, S_IRUGO
| S_IWUSR
,
1482 lpfc_board_mode_show
, lpfc_board_mode_store
);
1483 static DEVICE_ATTR(issue_reset
, S_IWUSR
, NULL
, lpfc_issue_reset
);
1484 static DEVICE_ATTR(max_vpi
, S_IRUGO
, lpfc_max_vpi_show
, NULL
);
1485 static DEVICE_ATTR(used_vpi
, S_IRUGO
, lpfc_used_vpi_show
, NULL
);
1486 static DEVICE_ATTR(max_rpi
, S_IRUGO
, lpfc_max_rpi_show
, NULL
);
1487 static DEVICE_ATTR(used_rpi
, S_IRUGO
, lpfc_used_rpi_show
, NULL
);
1488 static DEVICE_ATTR(max_xri
, S_IRUGO
, lpfc_max_xri_show
, NULL
);
1489 static DEVICE_ATTR(used_xri
, S_IRUGO
, lpfc_used_xri_show
, NULL
);
1490 static DEVICE_ATTR(npiv_info
, S_IRUGO
, lpfc_npiv_info_show
, NULL
);
1491 static DEVICE_ATTR(lpfc_temp_sensor
, S_IRUGO
, lpfc_temp_sensor_show
, NULL
);
1494 static char *lpfc_soft_wwn_key
= "C99G71SL8032A";
1497 * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid.
1498 * @dev: class device that is converted into a Scsi_host.
1499 * @attr: device attribute, not used.
1500 * @buf: containing the string lpfc_soft_wwn_key.
1501 * @count: must be size of lpfc_soft_wwn_key.
1504 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1505 * length of buf indicates success
1508 lpfc_soft_wwn_enable_store(struct device
*dev
, struct device_attribute
*attr
,
1509 const char *buf
, size_t count
)
1511 struct Scsi_Host
*shost
= class_to_shost(dev
);
1512 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1513 struct lpfc_hba
*phba
= vport
->phba
;
1514 unsigned int cnt
= count
;
1517 * We're doing a simple sanity check for soft_wwpn setting.
1518 * We require that the user write a specific key to enable
1519 * the soft_wwpn attribute to be settable. Once the attribute
1520 * is written, the enable key resets. If further updates are
1521 * desired, the key must be written again to re-enable the
1524 * The "key" is not secret - it is a hardcoded string shown
1525 * here. The intent is to protect against the random user or
1526 * application that is just writing attributes.
1529 /* count may include a LF at end of string */
1530 if (buf
[cnt
-1] == '\n')
1533 if ((cnt
!= strlen(lpfc_soft_wwn_key
)) ||
1534 (strncmp(buf
, lpfc_soft_wwn_key
, strlen(lpfc_soft_wwn_key
)) != 0))
1537 phba
->soft_wwn_enable
= 1;
1540 static DEVICE_ATTR(lpfc_soft_wwn_enable
, S_IWUSR
, NULL
,
1541 lpfc_soft_wwn_enable_store
);
1544 * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter.
1545 * @dev: class device that is converted into a Scsi_host.
1546 * @attr: device attribute, not used.
1547 * @buf: on return contains the wwpn in hexidecimal.
1549 * Returns: size of formatted string.
1552 lpfc_soft_wwpn_show(struct device
*dev
, struct device_attribute
*attr
,
1555 struct Scsi_Host
*shost
= class_to_shost(dev
);
1556 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1557 struct lpfc_hba
*phba
= vport
->phba
;
1559 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
1560 (unsigned long long)phba
->cfg_soft_wwpn
);
1564 * lpfc_soft_wwpn_store: Set the ww port name of the adapter.
1565 * @dev class device that is converted into a Scsi_host.
1566 * @attr: device attribute, not used.
1567 * @buf: contains the wwpn in hexidecimal.
1568 * @count: number of wwpn bytes in buf
1571 * -EACCES hba reset not enabled, adapter over temp
1572 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1573 * -EIO error taking adapter offline or online
1574 * value of count on success
1577 lpfc_soft_wwpn_store(struct device
*dev
, struct device_attribute
*attr
,
1578 const char *buf
, size_t count
)
1580 struct Scsi_Host
*shost
= class_to_shost(dev
);
1581 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1582 struct lpfc_hba
*phba
= vport
->phba
;
1583 struct completion online_compl
;
1584 int stat1
=0, stat2
=0;
1585 unsigned int i
, j
, cnt
=count
;
1588 if (!phba
->cfg_enable_hba_reset
)
1590 spin_lock_irq(&phba
->hbalock
);
1591 if (phba
->over_temp_state
== HBA_OVER_TEMP
) {
1592 spin_unlock_irq(&phba
->hbalock
);
1595 spin_unlock_irq(&phba
->hbalock
);
1596 /* count may include a LF at end of string */
1597 if (buf
[cnt
-1] == '\n')
1600 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
1601 ((cnt
== 17) && (*buf
++ != 'x')) ||
1602 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
1605 phba
->soft_wwn_enable
= 0;
1607 memset(wwpn
, 0, sizeof(wwpn
));
1609 /* Validate and store the new name */
1610 for (i
=0, j
=0; i
< 16; i
++) {
1611 if ((*buf
>= 'a') && (*buf
<= 'f'))
1612 j
= ((j
<< 4) | ((*buf
++ -'a') + 10));
1613 else if ((*buf
>= 'A') && (*buf
<= 'F'))
1614 j
= ((j
<< 4) | ((*buf
++ -'A') + 10));
1615 else if ((*buf
>= '0') && (*buf
<= '9'))
1616 j
= ((j
<< 4) | (*buf
++ -'0'));
1620 wwpn
[i
/2] = j
& 0xff;
1624 phba
->cfg_soft_wwpn
= wwn_to_u64(wwpn
);
1625 fc_host_port_name(shost
) = phba
->cfg_soft_wwpn
;
1626 if (phba
->cfg_soft_wwnn
)
1627 fc_host_node_name(shost
) = phba
->cfg_soft_wwnn
;
1629 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
1630 "lpfc%d: Reinitializing to use soft_wwpn\n", phba
->brd_no
);
1632 stat1
= lpfc_do_offline(phba
, LPFC_EVT_OFFLINE
);
1634 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1635 "0463 lpfc_soft_wwpn attribute set failed to "
1636 "reinit adapter - %d\n", stat1
);
1637 init_completion(&online_compl
);
1638 lpfc_workq_post_event(phba
, &stat2
, &online_compl
, LPFC_EVT_ONLINE
);
1639 wait_for_completion(&online_compl
);
1641 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1642 "0464 lpfc_soft_wwpn attribute set failed to "
1643 "reinit adapter - %d\n", stat2
);
1644 return (stat1
|| stat2
) ? -EIO
: count
;
1646 static DEVICE_ATTR(lpfc_soft_wwpn
, S_IRUGO
| S_IWUSR
,\
1647 lpfc_soft_wwpn_show
, lpfc_soft_wwpn_store
);
1650 * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter.
1651 * @dev: class device that is converted into a Scsi_host.
1652 * @attr: device attribute, not used.
1653 * @buf: on return contains the wwnn in hexidecimal.
1655 * Returns: size of formatted string.
1658 lpfc_soft_wwnn_show(struct device
*dev
, struct device_attribute
*attr
,
1661 struct Scsi_Host
*shost
= class_to_shost(dev
);
1662 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
1663 return snprintf(buf
, PAGE_SIZE
, "0x%llx\n",
1664 (unsigned long long)phba
->cfg_soft_wwnn
);
1668 * lpfc_soft_wwnn_store: sets the ww node name of the adapter.
1669 * @cdev: class device that is converted into a Scsi_host.
1670 * @buf: contains the ww node name in hexidecimal.
1671 * @count: number of wwnn bytes in buf.
1674 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1675 * value of count on success
1678 lpfc_soft_wwnn_store(struct device
*dev
, struct device_attribute
*attr
,
1679 const char *buf
, size_t count
)
1681 struct Scsi_Host
*shost
= class_to_shost(dev
);
1682 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
1683 unsigned int i
, j
, cnt
=count
;
1686 /* count may include a LF at end of string */
1687 if (buf
[cnt
-1] == '\n')
1690 if (!phba
->soft_wwn_enable
|| (cnt
< 16) || (cnt
> 18) ||
1691 ((cnt
== 17) && (*buf
++ != 'x')) ||
1692 ((cnt
== 18) && ((*buf
++ != '0') || (*buf
++ != 'x'))))
1696 * Allow wwnn to be set many times, as long as the enable is set.
1697 * However, once the wwpn is set, everything locks.
1700 memset(wwnn
, 0, sizeof(wwnn
));
1702 /* Validate and store the new name */
1703 for (i
=0, j
=0; i
< 16; i
++) {
1704 if ((*buf
>= 'a') && (*buf
<= 'f'))
1705 j
= ((j
<< 4) | ((*buf
++ -'a') + 10));
1706 else if ((*buf
>= 'A') && (*buf
<= 'F'))
1707 j
= ((j
<< 4) | ((*buf
++ -'A') + 10));
1708 else if ((*buf
>= '0') && (*buf
<= '9'))
1709 j
= ((j
<< 4) | (*buf
++ -'0'));
1713 wwnn
[i
/2] = j
& 0xff;
1717 phba
->cfg_soft_wwnn
= wwn_to_u64(wwnn
);
1719 dev_printk(KERN_NOTICE
, &phba
->pcidev
->dev
,
1720 "lpfc%d: soft_wwnn set. Value will take effect upon "
1721 "setting of the soft_wwpn\n", phba
->brd_no
);
1725 static DEVICE_ATTR(lpfc_soft_wwnn
, S_IRUGO
| S_IWUSR
,\
1726 lpfc_soft_wwnn_show
, lpfc_soft_wwnn_store
);
1729 static int lpfc_poll
= 0;
1730 module_param(lpfc_poll
, int, 0);
1731 MODULE_PARM_DESC(lpfc_poll
, "FCP ring polling mode control:"
1733 " 1 - poll with interrupts enabled"
1734 " 3 - poll and disable FCP ring interrupts");
1736 static DEVICE_ATTR(lpfc_poll
, S_IRUGO
| S_IWUSR
,
1737 lpfc_poll_show
, lpfc_poll_store
);
1739 int lpfc_sli_mode
= 0;
1740 module_param(lpfc_sli_mode
, int, 0);
1741 MODULE_PARM_DESC(lpfc_sli_mode
, "SLI mode selector:"
1742 " 0 - auto (SLI-3 if supported),"
1743 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1744 " 3 - select SLI-3");
1746 int lpfc_enable_npiv
= 0;
1747 module_param(lpfc_enable_npiv
, int, 0);
1748 MODULE_PARM_DESC(lpfc_enable_npiv
, "Enable NPIV functionality");
1749 lpfc_param_show(enable_npiv
);
1750 lpfc_param_init(enable_npiv
, 0, 0, 1);
1751 static DEVICE_ATTR(lpfc_enable_npiv
, S_IRUGO
,
1752 lpfc_enable_npiv_show
, NULL
);
1755 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1756 # until the timer expires. Value range is [0,255]. Default value is 30.
1758 static int lpfc_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
1759 static int lpfc_devloss_tmo
= LPFC_DEF_DEVLOSS_TMO
;
1760 module_param(lpfc_nodev_tmo
, int, 0);
1761 MODULE_PARM_DESC(lpfc_nodev_tmo
,
1762 "Seconds driver will hold I/O waiting "
1763 "for a device to come back");
1766 * lpfc_nodev_tmo_show: Return the hba dev loss timeout value.
1767 * @dev: class converted to a Scsi_host structure.
1768 * @attr: device attribute, not used.
1769 * @buf: on return contains the dev loss timeout in decimal.
1771 * Returns: size of formatted string.
1774 lpfc_nodev_tmo_show(struct device
*dev
, struct device_attribute
*attr
,
1777 struct Scsi_Host
*shost
= class_to_shost(dev
);
1778 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
1780 val
= vport
->cfg_devloss_tmo
;
1781 return snprintf(buf
, PAGE_SIZE
, "%d\n", vport
->cfg_devloss_tmo
);
1785 * lpfc_nodev_tmo_init: Set the hba nodev timeout value.
1786 * @vport: lpfc vport structure pointer.
1787 * @val: contains the nodev timeout value.
1790 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
1791 * a kernel error message is printed and zero is returned.
1792 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1793 * Otherwise nodev tmo is set to the default value.
1796 * zero if already set or if val is in range
1797 * -EINVAL val out of range
1800 lpfc_nodev_tmo_init(struct lpfc_vport
*vport
, int val
)
1802 if (vport
->cfg_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
) {
1803 vport
->cfg_nodev_tmo
= vport
->cfg_devloss_tmo
;
1804 if (val
!= LPFC_DEF_DEVLOSS_TMO
)
1805 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1806 "0407 Ignoring nodev_tmo module "
1807 "parameter because devloss_tmo is "
1812 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
1813 vport
->cfg_nodev_tmo
= val
;
1814 vport
->cfg_devloss_tmo
= val
;
1817 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1818 "0400 lpfc_nodev_tmo attribute cannot be set to"
1819 " %d, allowed range is [%d, %d]\n",
1820 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
1821 vport
->cfg_nodev_tmo
= LPFC_DEF_DEVLOSS_TMO
;
1826 * lpfc_update_rport_devloss_tmo: Update dev loss tmo value.
1827 * @vport: lpfc vport structure pointer.
1830 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
1833 lpfc_update_rport_devloss_tmo(struct lpfc_vport
*vport
)
1835 struct Scsi_Host
*shost
;
1836 struct lpfc_nodelist
*ndlp
;
1838 shost
= lpfc_shost_from_vport(vport
);
1839 spin_lock_irq(shost
->host_lock
);
1840 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
)
1841 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
)
1842 ndlp
->rport
->dev_loss_tmo
= vport
->cfg_devloss_tmo
;
1843 spin_unlock_irq(shost
->host_lock
);
1847 * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values.
1848 * @vport: lpfc vport structure pointer.
1849 * @val: contains the tmo value.
1852 * If the devloss tmo is already set or the vport dev loss tmo has changed
1853 * then a kernel error message is printed and zero is returned.
1854 * Else if val is in range then nodev tmo and devloss tmo are set to val.
1855 * Otherwise nodev tmo is set to the default value.
1858 * zero if already set or if val is in range
1859 * -EINVAL val out of range
1862 lpfc_nodev_tmo_set(struct lpfc_vport
*vport
, int val
)
1864 if (vport
->dev_loss_tmo_changed
||
1865 (lpfc_devloss_tmo
!= LPFC_DEF_DEVLOSS_TMO
)) {
1866 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1867 "0401 Ignoring change to nodev_tmo "
1868 "because devloss_tmo is set.\n");
1871 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
1872 vport
->cfg_nodev_tmo
= val
;
1873 vport
->cfg_devloss_tmo
= val
;
1874 lpfc_update_rport_devloss_tmo(vport
);
1877 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1878 "0403 lpfc_nodev_tmo attribute cannot be set to"
1879 "%d, allowed range is [%d, %d]\n",
1880 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
1884 lpfc_vport_param_store(nodev_tmo
)
1886 static DEVICE_ATTR(lpfc_nodev_tmo
, S_IRUGO
| S_IWUSR
,
1887 lpfc_nodev_tmo_show
, lpfc_nodev_tmo_store
);
1890 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1891 # disappear until the timer expires. Value range is [0,255]. Default
1894 module_param(lpfc_devloss_tmo
, int, 0);
1895 MODULE_PARM_DESC(lpfc_devloss_tmo
,
1896 "Seconds driver will hold I/O waiting "
1897 "for a device to come back");
1898 lpfc_vport_param_init(devloss_tmo
, LPFC_DEF_DEVLOSS_TMO
,
1899 LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
)
1900 lpfc_vport_param_show(devloss_tmo
)
1903 * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit.
1904 * @vport: lpfc vport structure pointer.
1905 * @val: contains the tmo value.
1908 * If val is in a valid range then set the vport nodev tmo,
1909 * devloss tmo, also set the vport dev loss tmo changed flag.
1910 * Else a kernel error message is printed.
1913 * zero if val is in range
1914 * -EINVAL val out of range
1917 lpfc_devloss_tmo_set(struct lpfc_vport
*vport
, int val
)
1919 if (val
>= LPFC_MIN_DEVLOSS_TMO
&& val
<= LPFC_MAX_DEVLOSS_TMO
) {
1920 vport
->cfg_nodev_tmo
= val
;
1921 vport
->cfg_devloss_tmo
= val
;
1922 vport
->dev_loss_tmo_changed
= 1;
1923 lpfc_update_rport_devloss_tmo(vport
);
1927 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
1928 "0404 lpfc_devloss_tmo attribute cannot be set to"
1929 " %d, allowed range is [%d, %d]\n",
1930 val
, LPFC_MIN_DEVLOSS_TMO
, LPFC_MAX_DEVLOSS_TMO
);
1934 lpfc_vport_param_store(devloss_tmo
)
1935 static DEVICE_ATTR(lpfc_devloss_tmo
, S_IRUGO
| S_IWUSR
,
1936 lpfc_devloss_tmo_show
, lpfc_devloss_tmo_store
);
1939 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1940 # deluged with LOTS of information.
1941 # You can set a bit mask to record specific types of verbose messages:
1943 # LOG_ELS 0x1 ELS events
1944 # LOG_DISCOVERY 0x2 Link discovery events
1945 # LOG_MBOX 0x4 Mailbox events
1946 # LOG_INIT 0x8 Initialization events
1947 # LOG_LINK_EVENT 0x10 Link events
1948 # LOG_FCP 0x40 FCP traffic history
1949 # LOG_NODE 0x80 Node table events
1950 # LOG_MISC 0x400 Miscellaneous events
1951 # LOG_SLI 0x800 SLI events
1952 # LOG_FCP_ERROR 0x1000 Only log FCP errors
1953 # LOG_LIBDFC 0x2000 LIBDFC events
1954 # LOG_ALL_MSG 0xffff LOG all messages
1956 LPFC_VPORT_ATTR_HEX_RW(log_verbose
, 0x0, 0x0, 0xffff,
1957 "Verbose logging bit-mask");
1960 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1961 # objects that have been registered with the nameserver after login.
1963 LPFC_VPORT_ATTR_R(enable_da_id
, 0, 0, 1,
1964 "Deregister nameserver objects before LOGO");
1967 # lun_queue_depth: This parameter is used to limit the number of outstanding
1968 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
1970 LPFC_VPORT_ATTR_R(lun_queue_depth
, 30, 1, 128,
1971 "Max number of FCP commands we can queue to a specific LUN");
1974 # hba_queue_depth: This parameter is used to limit the number of outstanding
1975 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
1976 # value is greater than the maximum number of exchanges supported by the HBA,
1977 # then maximum number of exchanges supported by the HBA is used to determine
1978 # the hba_queue_depth.
1980 LPFC_ATTR_R(hba_queue_depth
, 8192, 32, 8192,
1981 "Max number of FCP commands we can queue to a lpfc HBA");
1984 # peer_port_login: This parameter allows/prevents logins
1985 # between peer ports hosted on the same physical port.
1986 # When this parameter is set 0 peer ports of same physical port
1987 # are not allowed to login to each other.
1988 # When this parameter is set 1 peer ports of same physical port
1989 # are allowed to login to each other.
1990 # Default value of this parameter is 0.
1992 LPFC_VPORT_ATTR_R(peer_port_login
, 0, 0, 1,
1993 "Allow peer ports on the same physical port to login to each "
1997 # restrict_login: This parameter allows/prevents logins
1998 # between Virtual Ports and remote initiators.
1999 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2000 # other initiators and will attempt to PLOGI all remote ports.
2001 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2002 # remote ports and will not attempt to PLOGI to other initiators.
2003 # This parameter does not restrict to the physical port.
2004 # This parameter does not restrict logins to Fabric resident remote ports.
2005 # Default value of this parameter is 1.
2007 static int lpfc_restrict_login
= 1;
2008 module_param(lpfc_restrict_login
, int, 0);
2009 MODULE_PARM_DESC(lpfc_restrict_login
,
2010 "Restrict virtual ports login to remote initiators.");
2011 lpfc_vport_param_show(restrict_login
);
2014 * lpfc_restrict_login_init: Set the vport restrict login flag.
2015 * @vport: lpfc vport structure pointer.
2016 * @val: contains the restrict login value.
2019 * If val is not in a valid range then log a kernel error message and set
2020 * the vport restrict login to one.
2021 * If the port type is physical clear the restrict login flag and return.
2022 * Else set the restrict login flag to val.
2025 * zero if val is in range
2026 * -EINVAL val out of range
2029 lpfc_restrict_login_init(struct lpfc_vport
*vport
, int val
)
2031 if (val
< 0 || val
> 1) {
2032 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2033 "0422 lpfc_restrict_login attribute cannot "
2034 "be set to %d, allowed range is [0, 1]\n",
2036 vport
->cfg_restrict_login
= 1;
2039 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
2040 vport
->cfg_restrict_login
= 0;
2043 vport
->cfg_restrict_login
= val
;
2048 * lpfc_restrict_login_set: Set the vport restrict login flag.
2049 * @vport: lpfc vport structure pointer.
2050 * @val: contains the restrict login value.
2053 * If val is not in a valid range then log a kernel error message and set
2054 * the vport restrict login to one.
2055 * If the port type is physical and the val is not zero log a kernel
2056 * error message, clear the restrict login flag and return zero.
2057 * Else set the restrict login flag to val.
2060 * zero if val is in range
2061 * -EINVAL val out of range
2064 lpfc_restrict_login_set(struct lpfc_vport
*vport
, int val
)
2066 if (val
< 0 || val
> 1) {
2067 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2068 "0425 lpfc_restrict_login attribute cannot "
2069 "be set to %d, allowed range is [0, 1]\n",
2071 vport
->cfg_restrict_login
= 1;
2074 if (vport
->port_type
== LPFC_PHYSICAL_PORT
&& val
!= 0) {
2075 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_INIT
,
2076 "0468 lpfc_restrict_login must be 0 for "
2077 "Physical ports.\n");
2078 vport
->cfg_restrict_login
= 0;
2081 vport
->cfg_restrict_login
= val
;
2084 lpfc_vport_param_store(restrict_login
);
2085 static DEVICE_ATTR(lpfc_restrict_login
, S_IRUGO
| S_IWUSR
,
2086 lpfc_restrict_login_show
, lpfc_restrict_login_store
);
2089 # Some disk devices have a "select ID" or "select Target" capability.
2090 # From a protocol standpoint "select ID" usually means select the
2091 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2092 # annex" which contains a table that maps a "select ID" (a number
2093 # between 0 and 7F) to an ALPA. By default, for compatibility with
2094 # older drivers, the lpfc driver scans this table from low ALPA to high
2097 # Turning on the scan-down variable (on = 1, off = 0) will
2098 # cause the lpfc driver to use an inverted table, effectively
2099 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2101 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2102 # and will not work across a fabric. Also this parameter will take
2103 # effect only in the case when ALPA map is not available.)
2105 LPFC_VPORT_ATTR_R(scan_down
, 1, 0, 1,
2106 "Start scanning for devices from highest ALPA to lowest");
2109 # lpfc_topology: link topology for init link
2110 # 0x0 = attempt loop mode then point-to-point
2111 # 0x01 = internal loopback mode
2112 # 0x02 = attempt point-to-point mode only
2113 # 0x04 = attempt loop mode only
2114 # 0x06 = attempt point-to-point mode then loop
2115 # Set point-to-point mode if you want to run as an N_Port.
2116 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2117 # Default value is 0.
2121 * lpfc_topology_set: Set the adapters topology field.
2122 * @phba: lpfc_hba pointer.
2123 * @val: topology value.
2126 * If val is in a valid range then set the adapter's topology field and
2127 * issue a lip; if the lip fails reset the topology to the old value.
2129 * If the value is not in range log a kernel error message and return an error.
2132 * zero if val is in range and lip okay
2133 * non-zero return value from lpfc_issue_lip()
2134 * -EINVAL val out of range
2137 lpfc_topology_set(struct lpfc_hba
*phba
, int val
)
2141 if (val
>= 0 && val
<= 6) {
2142 prev_val
= phba
->cfg_topology
;
2143 phba
->cfg_topology
= val
;
2144 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
2146 phba
->cfg_topology
= prev_val
;
2149 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2150 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2151 "allowed range is [0, 6]\n",
2155 static int lpfc_topology
= 0;
2156 module_param(lpfc_topology
, int, 0);
2157 MODULE_PARM_DESC(lpfc_topology
, "Select Fibre Channel topology");
2158 lpfc_param_show(topology
)
2159 lpfc_param_init(topology
, 0, 0, 6)
2160 lpfc_param_store(topology
)
2161 static DEVICE_ATTR(lpfc_topology
, S_IRUGO
| S_IWUSR
,
2162 lpfc_topology_show
, lpfc_topology_store
);
2165 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2167 # 0 = auto select (default)
2172 # Value range is [0,8]. Default value is 0.
2176 * lpfc_link_speed_set: Set the adapters link speed.
2177 * @phba: lpfc_hba pointer.
2178 * @val: link speed value.
2181 * If val is in a valid range then set the adapter's link speed field and
2182 * issue a lip; if the lip fails reset the link speed to the old value.
2185 * If the value is not in range log a kernel error message and return an error.
2188 * zero if val is in range and lip okay.
2189 * non-zero return value from lpfc_issue_lip()
2190 * -EINVAL val out of range
2193 lpfc_link_speed_set(struct lpfc_hba
*phba
, int val
)
2198 if (((val
== LINK_SPEED_1G
) && !(phba
->lmt
& LMT_1Gb
)) ||
2199 ((val
== LINK_SPEED_2G
) && !(phba
->lmt
& LMT_2Gb
)) ||
2200 ((val
== LINK_SPEED_4G
) && !(phba
->lmt
& LMT_4Gb
)) ||
2201 ((val
== LINK_SPEED_8G
) && !(phba
->lmt
& LMT_8Gb
)) ||
2202 ((val
== LINK_SPEED_10G
) && !(phba
->lmt
& LMT_10Gb
)))
2205 if ((val
>= 0 && val
<= LPFC_MAX_LINK_SPEED
)
2206 && (LPFC_LINK_SPEED_BITMAP
& (1 << val
))) {
2207 prev_val
= phba
->cfg_link_speed
;
2208 phba
->cfg_link_speed
= val
;
2209 err
= lpfc_issue_lip(lpfc_shost_from_vport(phba
->pport
));
2211 phba
->cfg_link_speed
= prev_val
;
2215 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2216 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
2217 "allowed range is [0, 8]\n",
2222 static int lpfc_link_speed
= 0;
2223 module_param(lpfc_link_speed
, int, 0);
2224 MODULE_PARM_DESC(lpfc_link_speed
, "Select link speed");
2225 lpfc_param_show(link_speed
)
2228 * lpfc_link_speed_init: Set the adapters link speed.
2229 * @phba: lpfc_hba pointer.
2230 * @val: link speed value.
2233 * If val is in a valid range then set the adapter's link speed field.
2236 * If the value is not in range log a kernel error message, clear the link
2237 * speed and return an error.
2240 * zero if val saved.
2241 * -EINVAL val out of range
2244 lpfc_link_speed_init(struct lpfc_hba
*phba
, int val
)
2246 if ((val
>= 0 && val
<= LPFC_MAX_LINK_SPEED
)
2247 && (LPFC_LINK_SPEED_BITMAP
& (1 << val
))) {
2248 phba
->cfg_link_speed
= val
;
2251 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2252 "0405 lpfc_link_speed attribute cannot "
2253 "be set to %d, allowed values are "
2254 "["LPFC_LINK_SPEED_STRING
"]\n", val
);
2255 phba
->cfg_link_speed
= 0;
2259 lpfc_param_store(link_speed
)
2260 static DEVICE_ATTR(lpfc_link_speed
, S_IRUGO
| S_IWUSR
,
2261 lpfc_link_speed_show
, lpfc_link_speed_store
);
2264 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
2265 # Value range is [2,3]. Default value is 3.
2267 LPFC_VPORT_ATTR_R(fcp_class
, 3, 2, 3,
2268 "Select Fibre Channel class of service for FCP sequences");
2271 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
2272 # is [0,1]. Default value is 0.
2274 LPFC_VPORT_ATTR_RW(use_adisc
, 0, 0, 1,
2275 "Use ADISC on rediscovery to authenticate FCP devices");
2278 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
2279 # range is [0,1]. Default value is 0.
2281 LPFC_ATTR_R(ack0
, 0, 0, 1, "Enable ACK0 support");
2284 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
2285 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
2286 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
2287 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
2288 # cr_delay is set to 0.
2290 LPFC_ATTR_RW(cr_delay
, 0, 0, 63, "A count of milliseconds after which an "
2291 "interrupt response is generated");
2293 LPFC_ATTR_RW(cr_count
, 1, 1, 255, "A count of I/O completions after which an "
2294 "interrupt response is generated");
2297 # lpfc_multi_ring_support: Determines how many rings to spread available
2298 # cmd/rsp IOCB entries across.
2299 # Value range is [1,2]. Default value is 1.
2301 LPFC_ATTR_R(multi_ring_support
, 1, 1, 2, "Determines number of primary "
2302 "SLI rings to spread IOCB entries across");
2305 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
2306 # identifies what rctl value to configure the additional ring for.
2307 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
2309 LPFC_ATTR_R(multi_ring_rctl
, FC_UNSOL_DATA
, 1,
2310 255, "Identifies RCTL for additional ring configuration");
2313 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
2314 # identifies what type value to configure the additional ring for.
2315 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
2317 LPFC_ATTR_R(multi_ring_type
, FC_LLC_SNAP
, 1,
2318 255, "Identifies TYPE for additional ring configuration");
2321 # lpfc_fdmi_on: controls FDMI support.
2322 # 0 = no FDMI support
2323 # 1 = support FDMI without attribute of hostname
2324 # 2 = support FDMI with attribute of hostname
2325 # Value range [0,2]. Default value is 0.
2327 LPFC_VPORT_ATTR_RW(fdmi_on
, 0, 0, 2, "Enable FDMI support");
2330 # Specifies the maximum number of ELS cmds we can have outstanding (for
2331 # discovery). Value range is [1,64]. Default value = 32.
2333 LPFC_VPORT_ATTR(discovery_threads
, 32, 1, 64, "Maximum number of ELS commands "
2334 "during discovery");
2337 # lpfc_max_luns: maximum allowed LUN.
2338 # Value range is [0,65535]. Default value is 255.
2339 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
2341 LPFC_VPORT_ATTR_R(max_luns
, 255, 0, 65535, "Maximum allowed LUN");
2344 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
2345 # Value range is [1,255], default value is 10.
2347 LPFC_ATTR_RW(poll_tmo
, 10, 1, 255,
2348 "Milliseconds driver will wait between polling FCP ring");
2351 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
2352 # support this feature
2353 # 0 = MSI disabled (default)
2356 # Value range is [0,2]. Default value is 0.
2358 LPFC_ATTR_R(use_msi
, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
2359 "MSI-X (2), if possible");
2362 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
2363 # 0 = HBA resets disabled
2364 # 1 = HBA resets enabled (default)
2365 # Value range is [0,1]. Default value is 1.
2367 LPFC_ATTR_R(enable_hba_reset
, 1, 0, 1, "Enable HBA resets from the driver.");
2370 # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
2371 # 0 = HBA Heartbeat disabled
2372 # 1 = HBA Heartbeat enabled (default)
2373 # Value range is [0,1]. Default value is 1.
2375 LPFC_ATTR_R(enable_hba_heartbeat
, 1, 0, 1, "Enable HBA Heartbeat.");
2378 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
2379 * This value can be set to values between 64 and 256. The default value is
2380 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
2381 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
2383 LPFC_ATTR_R(sg_seg_cnt
, LPFC_DEFAULT_SG_SEG_CNT
, LPFC_DEFAULT_SG_SEG_CNT
,
2384 LPFC_MAX_SG_SEG_CNT
, "Max Scatter Gather Segment Count");
2386 struct device_attribute
*lpfc_hba_attrs
[] = {
2388 &dev_attr_serialnum
,
2389 &dev_attr_modeldesc
,
2390 &dev_attr_modelname
,
2391 &dev_attr_programtype
,
2395 &dev_attr_option_rom_version
,
2396 &dev_attr_link_state
,
2397 &dev_attr_num_discovered_ports
,
2398 &dev_attr_lpfc_drvr_version
,
2399 &dev_attr_lpfc_temp_sensor
,
2400 &dev_attr_lpfc_log_verbose
,
2401 &dev_attr_lpfc_lun_queue_depth
,
2402 &dev_attr_lpfc_hba_queue_depth
,
2403 &dev_attr_lpfc_peer_port_login
,
2404 &dev_attr_lpfc_nodev_tmo
,
2405 &dev_attr_lpfc_devloss_tmo
,
2406 &dev_attr_lpfc_fcp_class
,
2407 &dev_attr_lpfc_use_adisc
,
2408 &dev_attr_lpfc_ack0
,
2409 &dev_attr_lpfc_topology
,
2410 &dev_attr_lpfc_scan_down
,
2411 &dev_attr_lpfc_link_speed
,
2412 &dev_attr_lpfc_cr_delay
,
2413 &dev_attr_lpfc_cr_count
,
2414 &dev_attr_lpfc_multi_ring_support
,
2415 &dev_attr_lpfc_multi_ring_rctl
,
2416 &dev_attr_lpfc_multi_ring_type
,
2417 &dev_attr_lpfc_fdmi_on
,
2418 &dev_attr_lpfc_max_luns
,
2419 &dev_attr_lpfc_enable_npiv
,
2420 &dev_attr_nport_evt_cnt
,
2421 &dev_attr_board_mode
,
2428 &dev_attr_npiv_info
,
2429 &dev_attr_issue_reset
,
2430 &dev_attr_lpfc_poll
,
2431 &dev_attr_lpfc_poll_tmo
,
2432 &dev_attr_lpfc_use_msi
,
2433 &dev_attr_lpfc_soft_wwnn
,
2434 &dev_attr_lpfc_soft_wwpn
,
2435 &dev_attr_lpfc_soft_wwn_enable
,
2436 &dev_attr_lpfc_enable_hba_reset
,
2437 &dev_attr_lpfc_enable_hba_heartbeat
,
2438 &dev_attr_lpfc_sg_seg_cnt
,
2442 struct device_attribute
*lpfc_vport_attrs
[] = {
2444 &dev_attr_link_state
,
2445 &dev_attr_num_discovered_ports
,
2446 &dev_attr_lpfc_drvr_version
,
2447 &dev_attr_lpfc_log_verbose
,
2448 &dev_attr_lpfc_lun_queue_depth
,
2449 &dev_attr_lpfc_nodev_tmo
,
2450 &dev_attr_lpfc_devloss_tmo
,
2451 &dev_attr_lpfc_hba_queue_depth
,
2452 &dev_attr_lpfc_peer_port_login
,
2453 &dev_attr_lpfc_restrict_login
,
2454 &dev_attr_lpfc_fcp_class
,
2455 &dev_attr_lpfc_use_adisc
,
2456 &dev_attr_lpfc_fdmi_on
,
2457 &dev_attr_lpfc_max_luns
,
2458 &dev_attr_nport_evt_cnt
,
2459 &dev_attr_npiv_info
,
2460 &dev_attr_lpfc_enable_da_id
,
2465 * sysfs_ctlreg_write: Write method for writing to ctlreg.
2466 * @kobj: kernel kobject that contains the kernel class device.
2467 * @bin_attr: kernel attributes passed to us.
2468 * @buf: contains the data to be written to the adapter IOREG space.
2469 * @off: offset into buffer to beginning of data.
2470 * @count: bytes to transfer.
2473 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2474 * Uses the adapter io control registers to send buf contents to the adapter.
2477 * -ERANGE off and count combo out of range
2478 * -EINVAL off, count or buff address invalid
2479 * -EPERM adapter is offline
2480 * value of count, buf contents written
2483 sysfs_ctlreg_write(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
2484 char *buf
, loff_t off
, size_t count
)
2487 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2488 struct Scsi_Host
*shost
= class_to_shost(dev
);
2489 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2490 struct lpfc_hba
*phba
= vport
->phba
;
2492 if ((off
+ count
) > FF_REG_AREA_SIZE
)
2495 if (count
== 0) return 0;
2497 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
2500 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
2504 spin_lock_irq(&phba
->hbalock
);
2505 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t))
2506 writel(*((uint32_t *)(buf
+ buf_off
)),
2507 phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
2509 spin_unlock_irq(&phba
->hbalock
);
2515 * sysfs_ctlreg_read: Read method for reading from ctlreg.
2516 * @kobj: kernel kobject that contains the kernel class device.
2517 * @bin_attr: kernel attributes passed to us.
2518 * @buf: if succesful contains the data from the adapter IOREG space.
2519 * @off: offset into buffer to beginning of data.
2520 * @count: bytes to transfer.
2523 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
2524 * Uses the adapter io control registers to read data into buf.
2527 * -ERANGE off and count combo out of range
2528 * -EINVAL off, count or buff address invalid
2529 * value of count, buf contents read
2532 sysfs_ctlreg_read(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
2533 char *buf
, loff_t off
, size_t count
)
2537 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2538 struct Scsi_Host
*shost
= class_to_shost(dev
);
2539 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2540 struct lpfc_hba
*phba
= vport
->phba
;
2542 if (off
> FF_REG_AREA_SIZE
)
2545 if ((off
+ count
) > FF_REG_AREA_SIZE
)
2546 count
= FF_REG_AREA_SIZE
- off
;
2548 if (count
== 0) return 0;
2550 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
2553 spin_lock_irq(&phba
->hbalock
);
2555 for (buf_off
= 0; buf_off
< count
; buf_off
+= sizeof(uint32_t)) {
2556 tmp_ptr
= (uint32_t *)(buf
+ buf_off
);
2557 *tmp_ptr
= readl(phba
->ctrl_regs_memmap_p
+ off
+ buf_off
);
2560 spin_unlock_irq(&phba
->hbalock
);
2565 static struct bin_attribute sysfs_ctlreg_attr
= {
2568 .mode
= S_IRUSR
| S_IWUSR
,
2571 .read
= sysfs_ctlreg_read
,
2572 .write
= sysfs_ctlreg_write
,
2576 * sysfs_mbox_idle: frees the sysfs mailbox.
2577 * @phba: lpfc_hba pointer
2580 sysfs_mbox_idle(struct lpfc_hba
*phba
)
2582 phba
->sysfs_mbox
.state
= SMBOX_IDLE
;
2583 phba
->sysfs_mbox
.offset
= 0;
2585 if (phba
->sysfs_mbox
.mbox
) {
2586 mempool_free(phba
->sysfs_mbox
.mbox
,
2587 phba
->mbox_mem_pool
);
2588 phba
->sysfs_mbox
.mbox
= NULL
;
2593 * sysfs_mbox_write: Write method for writing information via mbox.
2594 * @kobj: kernel kobject that contains the kernel class device.
2595 * @bin_attr: kernel attributes passed to us.
2596 * @buf: contains the data to be written to sysfs mbox.
2597 * @off: offset into buffer to beginning of data.
2598 * @count: bytes to transfer.
2601 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2602 * Uses the sysfs mbox to send buf contents to the adapter.
2605 * -ERANGE off and count combo out of range
2606 * -EINVAL off, count or buff address invalid
2607 * zero if count is zero
2608 * -EPERM adapter is offline
2609 * -ENOMEM failed to allocate memory for the mail box
2610 * -EAGAIN offset, state or mbox is NULL
2611 * count number of bytes transferred
2614 sysfs_mbox_write(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
2615 char *buf
, loff_t off
, size_t count
)
2617 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2618 struct Scsi_Host
*shost
= class_to_shost(dev
);
2619 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2620 struct lpfc_hba
*phba
= vport
->phba
;
2621 struct lpfcMboxq
*mbox
= NULL
;
2623 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
2626 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
2633 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2636 memset(mbox
, 0, sizeof (LPFC_MBOXQ_t
));
2639 spin_lock_irq(&phba
->hbalock
);
2642 if (phba
->sysfs_mbox
.mbox
)
2643 mempool_free(mbox
, phba
->mbox_mem_pool
);
2645 phba
->sysfs_mbox
.mbox
= mbox
;
2646 phba
->sysfs_mbox
.state
= SMBOX_WRITING
;
2648 if (phba
->sysfs_mbox
.state
!= SMBOX_WRITING
||
2649 phba
->sysfs_mbox
.offset
!= off
||
2650 phba
->sysfs_mbox
.mbox
== NULL
) {
2651 sysfs_mbox_idle(phba
);
2652 spin_unlock_irq(&phba
->hbalock
);
2657 memcpy((uint8_t *) & phba
->sysfs_mbox
.mbox
->mb
+ off
,
2660 phba
->sysfs_mbox
.offset
= off
+ count
;
2662 spin_unlock_irq(&phba
->hbalock
);
2668 * sysfs_mbox_read: Read method for reading information via mbox.
2669 * @kobj: kernel kobject that contains the kernel class device.
2670 * @bin_attr: kernel attributes passed to us.
2671 * @buf: contains the data to be read from sysfs mbox.
2672 * @off: offset into buffer to beginning of data.
2673 * @count: bytes to transfer.
2676 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
2677 * Uses the sysfs mbox to receive data from to the adapter.
2680 * -ERANGE off greater than mailbox command size
2681 * -EINVAL off, count or buff address invalid
2682 * zero if off and count are zero
2683 * -EACCES adapter over temp
2684 * -EPERM garbage can value to catch a multitude of errors
2685 * -EAGAIN management IO not permitted, state or off error
2686 * -ETIME mailbox timeout
2687 * -ENODEV mailbox error
2688 * count number of bytes transferred
2691 sysfs_mbox_read(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
2692 char *buf
, loff_t off
, size_t count
)
2694 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2695 struct Scsi_Host
*shost
= class_to_shost(dev
);
2696 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2697 struct lpfc_hba
*phba
= vport
->phba
;
2700 if (off
> MAILBOX_CMD_SIZE
)
2703 if ((count
+ off
) > MAILBOX_CMD_SIZE
)
2704 count
= MAILBOX_CMD_SIZE
- off
;
2706 if (off
% 4 || count
% 4 || (unsigned long)buf
% 4)
2709 if (off
&& count
== 0)
2712 spin_lock_irq(&phba
->hbalock
);
2714 if (phba
->over_temp_state
== HBA_OVER_TEMP
) {
2715 sysfs_mbox_idle(phba
);
2716 spin_unlock_irq(&phba
->hbalock
);
2721 phba
->sysfs_mbox
.state
== SMBOX_WRITING
&&
2722 phba
->sysfs_mbox
.offset
>= 2 * sizeof(uint32_t)) {
2724 switch (phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
) {
2728 case MBX_CONFIG_LINK
:
2729 case MBX_CONFIG_RING
:
2730 case MBX_RESET_RING
:
2731 case MBX_UNREG_LOGIN
:
2733 case MBX_DUMP_CONTEXT
:
2738 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
)) {
2739 printk(KERN_WARNING
"mbox_read:Command 0x%x "
2740 "is illegal in on-line state\n",
2741 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
2742 sysfs_mbox_idle(phba
);
2743 spin_unlock_irq(&phba
->hbalock
);
2747 case MBX_WRITE_VPARMS
:
2750 case MBX_READ_CONFIG
:
2751 case MBX_READ_RCONFIG
:
2752 case MBX_READ_STATUS
:
2755 case MBX_READ_LNK_STAT
:
2756 case MBX_DUMP_MEMORY
:
2758 case MBX_UPDATE_CFG
:
2759 case MBX_KILL_BOARD
:
2761 case MBX_LOAD_EXP_ROM
:
2763 case MBX_DEL_LD_ENTRY
:
2764 case MBX_SET_VARIABLE
:
2767 case MBX_READ_SPARM64
:
2771 case MBX_REG_LOGIN64
:
2772 case MBX_CONFIG_PORT
:
2773 case MBX_RUN_BIU_DIAG
:
2774 printk(KERN_WARNING
"mbox_read: Illegal Command 0x%x\n",
2775 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
2776 sysfs_mbox_idle(phba
);
2777 spin_unlock_irq(&phba
->hbalock
);
2780 printk(KERN_WARNING
"mbox_read: Unknown Command 0x%x\n",
2781 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
2782 sysfs_mbox_idle(phba
);
2783 spin_unlock_irq(&phba
->hbalock
);
2787 /* If HBA encountered an error attention, allow only DUMP
2788 * or RESTART mailbox commands until the HBA is restarted.
2790 if (phba
->pport
->stopped
&&
2791 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
!= MBX_DUMP_MEMORY
&&
2792 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
!= MBX_RESTART
&&
2793 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
!= MBX_WRITE_VPARMS
&&
2794 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
!= MBX_WRITE_WWN
)
2795 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2796 "1259 mbox: Issued mailbox cmd "
2797 "0x%x while in stopped state.\n",
2798 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
);
2800 phba
->sysfs_mbox
.mbox
->vport
= vport
;
2802 /* Don't allow mailbox commands to be sent when blocked
2803 * or when in the middle of discovery
2805 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
) {
2806 sysfs_mbox_idle(phba
);
2807 spin_unlock_irq(&phba
->hbalock
);
2811 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
2812 (!(phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
))){
2814 spin_unlock_irq(&phba
->hbalock
);
2815 rc
= lpfc_sli_issue_mbox (phba
,
2816 phba
->sysfs_mbox
.mbox
,
2818 spin_lock_irq(&phba
->hbalock
);
2821 spin_unlock_irq(&phba
->hbalock
);
2822 rc
= lpfc_sli_issue_mbox_wait (phba
,
2823 phba
->sysfs_mbox
.mbox
,
2824 lpfc_mbox_tmo_val(phba
,
2825 phba
->sysfs_mbox
.mbox
->mb
.mbxCommand
) * HZ
);
2826 spin_lock_irq(&phba
->hbalock
);
2829 if (rc
!= MBX_SUCCESS
) {
2830 if (rc
== MBX_TIMEOUT
) {
2831 phba
->sysfs_mbox
.mbox
= NULL
;
2833 sysfs_mbox_idle(phba
);
2834 spin_unlock_irq(&phba
->hbalock
);
2835 return (rc
== MBX_TIMEOUT
) ? -ETIME
: -ENODEV
;
2837 phba
->sysfs_mbox
.state
= SMBOX_READING
;
2839 else if (phba
->sysfs_mbox
.offset
!= off
||
2840 phba
->sysfs_mbox
.state
!= SMBOX_READING
) {
2841 printk(KERN_WARNING
"mbox_read: Bad State\n");
2842 sysfs_mbox_idle(phba
);
2843 spin_unlock_irq(&phba
->hbalock
);
2847 memcpy(buf
, (uint8_t *) & phba
->sysfs_mbox
.mbox
->mb
+ off
, count
);
2849 phba
->sysfs_mbox
.offset
= off
+ count
;
2851 if (phba
->sysfs_mbox
.offset
== MAILBOX_CMD_SIZE
)
2852 sysfs_mbox_idle(phba
);
2854 spin_unlock_irq(&phba
->hbalock
);
2859 static struct bin_attribute sysfs_mbox_attr
= {
2862 .mode
= S_IRUSR
| S_IWUSR
,
2864 .size
= MAILBOX_CMD_SIZE
,
2865 .read
= sysfs_mbox_read
,
2866 .write
= sysfs_mbox_write
,
2870 * lpfc_alloc_sysfs_attr: Creates the sysfs, ctlreg, menlo and mbox entries.
2871 * @vport: address of lpfc vport structure.
2875 * error return code from sysfs_create_bin_file()
2878 lpfc_alloc_sysfs_attr(struct lpfc_vport
*vport
)
2880 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2883 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
2884 &sysfs_ctlreg_attr
);
2888 error
= sysfs_create_bin_file(&shost
->shost_dev
.kobj
,
2891 goto out_remove_ctlreg_attr
;
2894 out_remove_ctlreg_attr
:
2895 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
2901 * lpfc_free_sysfs_attr: Removes the sysfs, ctlreg, menlo and mbox entries.
2902 * @vport: address of lpfc vport structure.
2905 lpfc_free_sysfs_attr(struct lpfc_vport
*vport
)
2907 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2909 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_mbox_attr
);
2910 sysfs_remove_bin_file(&shost
->shost_dev
.kobj
, &sysfs_ctlreg_attr
);
2915 * Dynamic FC Host Attributes Support
2919 * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id.
2920 * @shost: kernel scsi host pointer.
2923 lpfc_get_host_port_id(struct Scsi_Host
*shost
)
2925 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2927 /* note: fc_myDID already in cpu endianness */
2928 fc_host_port_id(shost
) = vport
->fc_myDID
;
2932 * lpfc_get_host_port_type: Set the value of the scsi host port type.
2933 * @shost: kernel scsi host pointer.
2936 lpfc_get_host_port_type(struct Scsi_Host
*shost
)
2938 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2939 struct lpfc_hba
*phba
= vport
->phba
;
2941 spin_lock_irq(shost
->host_lock
);
2943 if (vport
->port_type
== LPFC_NPIV_PORT
) {
2944 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
2945 } else if (lpfc_is_link_up(phba
)) {
2946 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2947 if (vport
->fc_flag
& FC_PUBLIC_LOOP
)
2948 fc_host_port_type(shost
) = FC_PORTTYPE_NLPORT
;
2950 fc_host_port_type(shost
) = FC_PORTTYPE_LPORT
;
2952 if (vport
->fc_flag
& FC_FABRIC
)
2953 fc_host_port_type(shost
) = FC_PORTTYPE_NPORT
;
2955 fc_host_port_type(shost
) = FC_PORTTYPE_PTP
;
2958 fc_host_port_type(shost
) = FC_PORTTYPE_UNKNOWN
;
2960 spin_unlock_irq(shost
->host_lock
);
2964 * lpfc_get_host_port_state: Set the value of the scsi host port state.
2965 * @shost: kernel scsi host pointer.
2968 lpfc_get_host_port_state(struct Scsi_Host
*shost
)
2970 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2971 struct lpfc_hba
*phba
= vport
->phba
;
2973 spin_lock_irq(shost
->host_lock
);
2975 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
2976 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
2978 switch (phba
->link_state
) {
2979 case LPFC_LINK_UNKNOWN
:
2980 case LPFC_LINK_DOWN
:
2981 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
2985 case LPFC_HBA_READY
:
2986 /* Links up, beyond this port_type reports state */
2987 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
2989 case LPFC_HBA_ERROR
:
2990 fc_host_port_state(shost
) = FC_PORTSTATE_ERROR
;
2993 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
2998 spin_unlock_irq(shost
->host_lock
);
3002 * lpfc_get_host_speed: Set the value of the scsi host speed.
3003 * @shost: kernel scsi host pointer.
3006 lpfc_get_host_speed(struct Scsi_Host
*shost
)
3008 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3009 struct lpfc_hba
*phba
= vport
->phba
;
3011 spin_lock_irq(shost
->host_lock
);
3013 if (lpfc_is_link_up(phba
)) {
3014 switch(phba
->fc_linkspeed
) {
3016 fc_host_speed(shost
) = FC_PORTSPEED_1GBIT
;
3019 fc_host_speed(shost
) = FC_PORTSPEED_2GBIT
;
3022 fc_host_speed(shost
) = FC_PORTSPEED_4GBIT
;
3025 fc_host_speed(shost
) = FC_PORTSPEED_8GBIT
;
3028 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
3032 fc_host_speed(shost
) = FC_PORTSPEED_UNKNOWN
;
3034 spin_unlock_irq(shost
->host_lock
);
3038 * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name.
3039 * @shost: kernel scsi host pointer.
3042 lpfc_get_host_fabric_name (struct Scsi_Host
*shost
)
3044 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3045 struct lpfc_hba
*phba
= vport
->phba
;
3048 spin_lock_irq(shost
->host_lock
);
3050 if ((vport
->fc_flag
& FC_FABRIC
) ||
3051 ((phba
->fc_topology
== TOPOLOGY_LOOP
) &&
3052 (vport
->fc_flag
& FC_PUBLIC_LOOP
)))
3053 node_name
= wwn_to_u64(phba
->fc_fabparam
.nodeName
.u
.wwn
);
3055 /* fabric is local port if there is no F/FL_Port */
3058 spin_unlock_irq(shost
->host_lock
);
3060 fc_host_fabric_name(shost
) = node_name
;
3064 * lpfc_get_stats: Return statistical information about the adapter.
3065 * @shost: kernel scsi host pointer.
3068 * NULL on error for link down, no mbox pool, sli2 active,
3069 * management not allowed, memory allocation error, or mbox error.
3073 * address of the adapter host statistics
3075 static struct fc_host_statistics
*
3076 lpfc_get_stats(struct Scsi_Host
*shost
)
3078 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3079 struct lpfc_hba
*phba
= vport
->phba
;
3080 struct lpfc_sli
*psli
= &phba
->sli
;
3081 struct fc_host_statistics
*hs
= &phba
->link_stats
;
3082 struct lpfc_lnk_stat
* lso
= &psli
->lnk_stat_offsets
;
3083 LPFC_MBOXQ_t
*pmboxq
;
3085 unsigned long seconds
;
3089 * prevent udev from issuing mailbox commands until the port is
3092 if (phba
->link_state
< LPFC_LINK_DOWN
||
3093 !phba
->mbox_mem_pool
||
3094 (phba
->sli
.sli_flag
& LPFC_SLI2_ACTIVE
) == 0)
3097 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
3100 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3103 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
3106 pmb
->mbxCommand
= MBX_READ_STATUS
;
3107 pmb
->mbxOwner
= OWN_HOST
;
3108 pmboxq
->context1
= NULL
;
3109 pmboxq
->vport
= vport
;
3111 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
3112 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
3113 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
3115 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
3117 if (rc
!= MBX_SUCCESS
) {
3118 if (rc
!= MBX_TIMEOUT
)
3119 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3123 memset(hs
, 0, sizeof (struct fc_host_statistics
));
3125 hs
->tx_frames
= pmb
->un
.varRdStatus
.xmitFrameCnt
;
3126 hs
->tx_words
= (pmb
->un
.varRdStatus
.xmitByteCnt
* 256);
3127 hs
->rx_frames
= pmb
->un
.varRdStatus
.rcvFrameCnt
;
3128 hs
->rx_words
= (pmb
->un
.varRdStatus
.rcvByteCnt
* 256);
3130 memset(pmboxq
, 0, sizeof (LPFC_MBOXQ_t
));
3131 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
3132 pmb
->mbxOwner
= OWN_HOST
;
3133 pmboxq
->context1
= NULL
;
3134 pmboxq
->vport
= vport
;
3136 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
3137 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
3138 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
3140 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
3142 if (rc
!= MBX_SUCCESS
) {
3143 if (rc
!= MBX_TIMEOUT
)
3144 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3148 hs
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
3149 hs
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
3150 hs
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
3151 hs
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
3152 hs
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
3153 hs
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
3154 hs
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
3156 hs
->link_failure_count
-= lso
->link_failure_count
;
3157 hs
->loss_of_sync_count
-= lso
->loss_of_sync_count
;
3158 hs
->loss_of_signal_count
-= lso
->loss_of_signal_count
;
3159 hs
->prim_seq_protocol_err_count
-= lso
->prim_seq_protocol_err_count
;
3160 hs
->invalid_tx_word_count
-= lso
->invalid_tx_word_count
;
3161 hs
->invalid_crc_count
-= lso
->invalid_crc_count
;
3162 hs
->error_frames
-= lso
->error_frames
;
3164 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
3165 hs
->lip_count
= (phba
->fc_eventTag
>> 1);
3166 hs
->lip_count
-= lso
->link_events
;
3170 hs
->nos_count
= (phba
->fc_eventTag
>> 1);
3171 hs
->nos_count
-= lso
->link_events
;
3174 hs
->dumped_frames
= -1;
3176 seconds
= get_seconds();
3177 if (seconds
< psli
->stats_start
)
3178 hs
->seconds_since_last_reset
= seconds
+
3179 ((unsigned long)-1 - psli
->stats_start
);
3181 hs
->seconds_since_last_reset
= seconds
- psli
->stats_start
;
3183 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3189 * lpfc_reset_stats: Copy the adapter link stats information.
3190 * @shost: kernel scsi host pointer.
3193 lpfc_reset_stats(struct Scsi_Host
*shost
)
3195 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3196 struct lpfc_hba
*phba
= vport
->phba
;
3197 struct lpfc_sli
*psli
= &phba
->sli
;
3198 struct lpfc_lnk_stat
*lso
= &psli
->lnk_stat_offsets
;
3199 LPFC_MBOXQ_t
*pmboxq
;
3203 if (phba
->sli
.sli_flag
& LPFC_BLOCK_MGMT_IO
)
3206 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3209 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3212 pmb
->mbxCommand
= MBX_READ_STATUS
;
3213 pmb
->mbxOwner
= OWN_HOST
;
3214 pmb
->un
.varWords
[0] = 0x1; /* reset request */
3215 pmboxq
->context1
= NULL
;
3216 pmboxq
->vport
= vport
;
3218 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
3219 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
3220 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
3222 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
3224 if (rc
!= MBX_SUCCESS
) {
3225 if (rc
!= MBX_TIMEOUT
)
3226 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3230 memset(pmboxq
, 0, sizeof(LPFC_MBOXQ_t
));
3231 pmb
->mbxCommand
= MBX_READ_LNK_STAT
;
3232 pmb
->mbxOwner
= OWN_HOST
;
3233 pmboxq
->context1
= NULL
;
3234 pmboxq
->vport
= vport
;
3236 if ((vport
->fc_flag
& FC_OFFLINE_MODE
) ||
3237 (!(psli
->sli_flag
& LPFC_SLI2_ACTIVE
)))
3238 rc
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_POLL
);
3240 rc
= lpfc_sli_issue_mbox_wait(phba
, pmboxq
, phba
->fc_ratov
* 2);
3242 if (rc
!= MBX_SUCCESS
) {
3243 if (rc
!= MBX_TIMEOUT
)
3244 mempool_free( pmboxq
, phba
->mbox_mem_pool
);
3248 lso
->link_failure_count
= pmb
->un
.varRdLnk
.linkFailureCnt
;
3249 lso
->loss_of_sync_count
= pmb
->un
.varRdLnk
.lossSyncCnt
;
3250 lso
->loss_of_signal_count
= pmb
->un
.varRdLnk
.lossSignalCnt
;
3251 lso
->prim_seq_protocol_err_count
= pmb
->un
.varRdLnk
.primSeqErrCnt
;
3252 lso
->invalid_tx_word_count
= pmb
->un
.varRdLnk
.invalidXmitWord
;
3253 lso
->invalid_crc_count
= pmb
->un
.varRdLnk
.crcCnt
;
3254 lso
->error_frames
= pmb
->un
.varRdLnk
.crcCnt
;
3255 lso
->link_events
= (phba
->fc_eventTag
>> 1);
3257 psli
->stats_start
= get_seconds();
3259 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
3265 * The LPFC driver treats linkdown handling as target loss events so there
3266 * are no sysfs handlers for link_down_tmo.
3270 * lpfc_get_node_by_target: Return the nodelist for a target.
3271 * @starget: kernel scsi target pointer.
3274 * address of the node list if found
3275 * NULL target not found
3277 static struct lpfc_nodelist
*
3278 lpfc_get_node_by_target(struct scsi_target
*starget
)
3280 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
3281 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3282 struct lpfc_nodelist
*ndlp
;
3284 spin_lock_irq(shost
->host_lock
);
3285 /* Search for this, mapped, target ID */
3286 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3287 if (NLP_CHK_NODE_ACT(ndlp
) &&
3288 ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
&&
3289 starget
->id
== ndlp
->nlp_sid
) {
3290 spin_unlock_irq(shost
->host_lock
);
3294 spin_unlock_irq(shost
->host_lock
);
3299 * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1.
3300 * @starget: kernel scsi target pointer.
3303 lpfc_get_starget_port_id(struct scsi_target
*starget
)
3305 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
3307 fc_starget_port_id(starget
) = ndlp
? ndlp
->nlp_DID
: -1;
3311 * lpfc_get_starget_node_name: Set the target node name.
3312 * @starget: kernel scsi target pointer.
3314 * Description: Set the target node name to the ndlp node name wwn or zero.
3317 lpfc_get_starget_node_name(struct scsi_target
*starget
)
3319 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
3321 fc_starget_node_name(starget
) =
3322 ndlp
? wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
) : 0;
3326 * lpfc_get_starget_port_name: Set the target port name.
3327 * @starget: kernel scsi target pointer.
3329 * Description: set the target port name to the ndlp port name wwn or zero.
3332 lpfc_get_starget_port_name(struct scsi_target
*starget
)
3334 struct lpfc_nodelist
*ndlp
= lpfc_get_node_by_target(starget
);
3336 fc_starget_port_name(starget
) =
3337 ndlp
? wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
) : 0;
3341 * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo.
3342 * @rport: fc rport address.
3343 * @timeout: new value for dev loss tmo.
3346 * If timeout is non zero set the dev_loss_tmo to timeout, else set
3347 * dev_loss_tmo to one.
3350 lpfc_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
3353 rport
->dev_loss_tmo
= timeout
;
3355 rport
->dev_loss_tmo
= 1;
3359 * lpfc_rport_show_function: Return rport target information.
3362 * Macro that uses field to generate a function with the name lpfc_show_rport_
3364 * lpfc_show_rport_##field: returns the bytes formatted in buf
3365 * @cdev: class converted to an fc_rport.
3366 * @buf: on return contains the target_field or zero.
3368 * Returns: size of formatted string.
3370 #define lpfc_rport_show_function(field, format_string, sz, cast) \
3372 lpfc_show_rport_##field (struct device *dev, \
3373 struct device_attribute *attr, \
3376 struct fc_rport *rport = transport_class_to_rport(dev); \
3377 struct lpfc_rport_data *rdata = rport->hostdata; \
3378 return snprintf(buf, sz, format_string, \
3379 (rdata->target) ? cast rdata->target->field : 0); \
3382 #define lpfc_rport_rd_attr(field, format_string, sz) \
3383 lpfc_rport_show_function(field, format_string, sz, ) \
3384 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
3387 struct fc_function_template lpfc_transport_functions
= {
3388 /* fixed attributes the driver supports */
3389 .show_host_node_name
= 1,
3390 .show_host_port_name
= 1,
3391 .show_host_supported_classes
= 1,
3392 .show_host_supported_fc4s
= 1,
3393 .show_host_supported_speeds
= 1,
3394 .show_host_maxframe_size
= 1,
3396 /* dynamic attributes the driver supports */
3397 .get_host_port_id
= lpfc_get_host_port_id
,
3398 .show_host_port_id
= 1,
3400 .get_host_port_type
= lpfc_get_host_port_type
,
3401 .show_host_port_type
= 1,
3403 .get_host_port_state
= lpfc_get_host_port_state
,
3404 .show_host_port_state
= 1,
3406 /* active_fc4s is shown but doesn't change (thus no get function) */
3407 .show_host_active_fc4s
= 1,
3409 .get_host_speed
= lpfc_get_host_speed
,
3410 .show_host_speed
= 1,
3412 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
3413 .show_host_fabric_name
= 1,
3416 * The LPFC driver treats linkdown handling as target loss events
3417 * so there are no sysfs handlers for link_down_tmo.
3420 .get_fc_host_stats
= lpfc_get_stats
,
3421 .reset_fc_host_stats
= lpfc_reset_stats
,
3423 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
3424 .show_rport_maxframe_size
= 1,
3425 .show_rport_supported_classes
= 1,
3427 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
3428 .show_rport_dev_loss_tmo
= 1,
3430 .get_starget_port_id
= lpfc_get_starget_port_id
,
3431 .show_starget_port_id
= 1,
3433 .get_starget_node_name
= lpfc_get_starget_node_name
,
3434 .show_starget_node_name
= 1,
3436 .get_starget_port_name
= lpfc_get_starget_port_name
,
3437 .show_starget_port_name
= 1,
3439 .issue_fc_host_lip
= lpfc_issue_lip
,
3440 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
3441 .terminate_rport_io
= lpfc_terminate_rport_io
,
3443 .dd_fcvport_size
= sizeof(struct lpfc_vport
*),
3446 struct fc_function_template lpfc_vport_transport_functions
= {
3447 /* fixed attributes the driver supports */
3448 .show_host_node_name
= 1,
3449 .show_host_port_name
= 1,
3450 .show_host_supported_classes
= 1,
3451 .show_host_supported_fc4s
= 1,
3452 .show_host_supported_speeds
= 1,
3453 .show_host_maxframe_size
= 1,
3455 /* dynamic attributes the driver supports */
3456 .get_host_port_id
= lpfc_get_host_port_id
,
3457 .show_host_port_id
= 1,
3459 .get_host_port_type
= lpfc_get_host_port_type
,
3460 .show_host_port_type
= 1,
3462 .get_host_port_state
= lpfc_get_host_port_state
,
3463 .show_host_port_state
= 1,
3465 /* active_fc4s is shown but doesn't change (thus no get function) */
3466 .show_host_active_fc4s
= 1,
3468 .get_host_speed
= lpfc_get_host_speed
,
3469 .show_host_speed
= 1,
3471 .get_host_fabric_name
= lpfc_get_host_fabric_name
,
3472 .show_host_fabric_name
= 1,
3475 * The LPFC driver treats linkdown handling as target loss events
3476 * so there are no sysfs handlers for link_down_tmo.
3479 .get_fc_host_stats
= lpfc_get_stats
,
3480 .reset_fc_host_stats
= lpfc_reset_stats
,
3482 .dd_fcrport_size
= sizeof(struct lpfc_rport_data
),
3483 .show_rport_maxframe_size
= 1,
3484 .show_rport_supported_classes
= 1,
3486 .set_rport_dev_loss_tmo
= lpfc_set_rport_loss_tmo
,
3487 .show_rport_dev_loss_tmo
= 1,
3489 .get_starget_port_id
= lpfc_get_starget_port_id
,
3490 .show_starget_port_id
= 1,
3492 .get_starget_node_name
= lpfc_get_starget_node_name
,
3493 .show_starget_node_name
= 1,
3495 .get_starget_port_name
= lpfc_get_starget_port_name
,
3496 .show_starget_port_name
= 1,
3498 .dev_loss_tmo_callbk
= lpfc_dev_loss_tmo_callbk
,
3499 .terminate_rport_io
= lpfc_terminate_rport_io
,
3501 .vport_disable
= lpfc_vport_disable
,
3505 * lpfc_get_cfgparam: Used during probe_one to init the adapter structure.
3506 * @phba: lpfc_hba pointer.
3509 lpfc_get_cfgparam(struct lpfc_hba
*phba
)
3511 lpfc_cr_delay_init(phba
, lpfc_cr_delay
);
3512 lpfc_cr_count_init(phba
, lpfc_cr_count
);
3513 lpfc_multi_ring_support_init(phba
, lpfc_multi_ring_support
);
3514 lpfc_multi_ring_rctl_init(phba
, lpfc_multi_ring_rctl
);
3515 lpfc_multi_ring_type_init(phba
, lpfc_multi_ring_type
);
3516 lpfc_ack0_init(phba
, lpfc_ack0
);
3517 lpfc_topology_init(phba
, lpfc_topology
);
3518 lpfc_link_speed_init(phba
, lpfc_link_speed
);
3519 lpfc_poll_tmo_init(phba
, lpfc_poll_tmo
);
3520 lpfc_enable_npiv_init(phba
, lpfc_enable_npiv
);
3521 lpfc_use_msi_init(phba
, lpfc_use_msi
);
3522 lpfc_enable_hba_reset_init(phba
, lpfc_enable_hba_reset
);
3523 lpfc_enable_hba_heartbeat_init(phba
, lpfc_enable_hba_heartbeat
);
3524 phba
->cfg_poll
= lpfc_poll
;
3525 phba
->cfg_soft_wwnn
= 0L;
3526 phba
->cfg_soft_wwpn
= 0L;
3527 lpfc_sg_seg_cnt_init(phba
, lpfc_sg_seg_cnt
);
3528 /* Also reinitialize the host templates with new values. */
3529 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3530 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3532 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3533 * used to create the sg_dma_buf_pool must be dynamically calculated.
3534 * 2 segments are added since the IOCB needs a command and response bde.
3536 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
3537 sizeof(struct fcp_rsp
) +
3538 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
3539 lpfc_hba_queue_depth_init(phba
, lpfc_hba_queue_depth
);
3544 * lpfc_get_vport_cfgparam: Used during port create, init the vport structure.
3545 * @vport: lpfc_vport pointer.
3548 lpfc_get_vport_cfgparam(struct lpfc_vport
*vport
)
3550 lpfc_log_verbose_init(vport
, lpfc_log_verbose
);
3551 lpfc_lun_queue_depth_init(vport
, lpfc_lun_queue_depth
);
3552 lpfc_devloss_tmo_init(vport
, lpfc_devloss_tmo
);
3553 lpfc_nodev_tmo_init(vport
, lpfc_nodev_tmo
);
3554 lpfc_peer_port_login_init(vport
, lpfc_peer_port_login
);
3555 lpfc_restrict_login_init(vport
, lpfc_restrict_login
);
3556 lpfc_fcp_class_init(vport
, lpfc_fcp_class
);
3557 lpfc_use_adisc_init(vport
, lpfc_use_adisc
);
3558 lpfc_fdmi_on_init(vport
, lpfc_fdmi_on
);
3559 lpfc_discovery_threads_init(vport
, lpfc_discovery_threads
);
3560 lpfc_max_luns_init(vport
, lpfc_max_luns
);
3561 lpfc_scan_down_init(vport
, lpfc_scan_down
);
3562 lpfc_enable_da_id_init(vport
, lpfc_enable_da_id
);