4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * NOT a DDI compliant Sun Fibre Channel port driver(fp)
28 #include <sys/types.h>
29 #include <sys/varargs.h>
30 #include <sys/param.h>
31 #include <sys/errno.h>
34 #include <sys/modctl.h>
40 #include <sys/thread.h>
42 #include <sys/cmn_err.h>
45 #include <sys/sunddi.h>
46 #include <sys/promif.h>
47 #include <sys/nvpair.h>
48 #include <sys/byteorder.h>
49 #include <sys/scsi/scsi.h>
50 #include <sys/fibre-channel/fc.h>
51 #include <sys/fibre-channel/impl/fc_ulpif.h>
52 #include <sys/fibre-channel/impl/fc_fcaif.h>
53 #include <sys/fibre-channel/impl/fctl_private.h>
54 #include <sys/fibre-channel/impl/fc_portif.h>
55 #include <sys/fibre-channel/impl/fp.h>
57 /* These are defined in fctl.c! */
58 extern int did_table_size
;
59 extern int pwwn_table_size
;
61 static struct cb_ops fp_cb_ops
= {
73 nochpoll
, /* chpoll */
74 ddi_prop_op
, /* cb_prop_op */
76 D_NEW
| D_MP
| D_HOTPLUG
, /* cb_flag */
82 static struct dev_ops fp_ops
= {
83 DEVO_REV
, /* build revision */
84 0, /* reference count */
85 fp_getinfo
, /* getinfo */
86 nulldev
, /* identify - Obsoleted */
88 fp_attach
, /* attach */
89 fp_detach
, /* detach */
91 &fp_cb_ops
, /* cb_ops */
94 ddi_quiesce_not_needed
/* quiesce */
97 #define FP_VERSION "20091123-1.101"
98 #define FP_NAME_VERSION "SunFC Port v" FP_VERSION
100 char *fp_version
= FP_NAME_VERSION
;
102 static struct modldrv modldrv
= {
103 &mod_driverops
, /* Type of Module */
104 FP_NAME_VERSION
, /* Name/Version of fp */
105 &fp_ops
/* driver ops */
108 static struct modlinkage modlinkage
= {
109 MODREV_1
, /* Rev of the loadable modules system */
110 &modldrv
, /* NULL terminated list of */
111 NULL
/* Linkage structures */
116 static uint16_t ns_reg_cmds
[] = {
130 { FC_PKT_SUCCESS
, FC_SUCCESS
},
131 { FC_PKT_REMOTE_STOP
, FC_FAILURE
},
132 { FC_PKT_LOCAL_RJT
, FC_FAILURE
},
133 { FC_PKT_NPORT_RJT
, FC_ELS_PREJECT
},
134 { FC_PKT_FABRIC_RJT
, FC_ELS_FREJECT
},
135 { FC_PKT_LOCAL_BSY
, FC_TRAN_BUSY
},
136 { FC_PKT_TRAN_BSY
, FC_TRAN_BUSY
},
137 { FC_PKT_NPORT_BSY
, FC_PBUSY
},
138 { FC_PKT_FABRIC_BSY
, FC_FBUSY
},
139 { FC_PKT_LS_RJT
, FC_FAILURE
},
140 { FC_PKT_BA_RJT
, FC_FAILURE
},
141 { FC_PKT_TIMEOUT
, FC_FAILURE
},
142 { FC_PKT_TRAN_ERROR
, FC_TRANSPORT_ERROR
},
143 { FC_PKT_FAILURE
, FC_FAILURE
},
144 { FC_PKT_PORT_OFFLINE
, FC_OFFLINE
}
147 static uchar_t fp_valid_alpas
[] = {
148 0x01, 0x02, 0x04, 0x08, 0x0F, 0x10, 0x17, 0x18, 0x1B,
149 0x1D, 0x1E, 0x1F, 0x23, 0x25, 0x26, 0x27, 0x29, 0x2A,
150 0x2B, 0x2C, 0x2D, 0x2E, 0x31, 0x32, 0x33, 0x34, 0x35,
151 0x36, 0x39, 0x3A, 0x3C, 0x43, 0x45, 0x46, 0x47, 0x49,
152 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x51, 0x52, 0x53, 0x54,
153 0x55, 0x56, 0x59, 0x5A, 0x5C, 0x63, 0x65, 0x66, 0x67,
154 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x71, 0x72, 0x73,
155 0x74, 0x75, 0x76, 0x79, 0x7A, 0x7C, 0x80, 0x81, 0x82,
156 0x84, 0x88, 0x8F, 0x90, 0x97, 0x98, 0x9B, 0x9D, 0x9E,
157 0x9F, 0xA3, 0xA5, 0xA6, 0xA7, 0xA9, 0xAA, 0xAB, 0xAC,
158 0xAD, 0xAE, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB9,
159 0xBA, 0xBC, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB,
160 0xCC, 0xCD, 0xCE, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
161 0xD9, 0xDA, 0xDC, 0xE0, 0xE1, 0xE2, 0xE4, 0xE8, 0xEF
164 static struct fp_perms
{
165 uint16_t fp_ioctl_cmd
;
166 uchar_t fp_open_flag
;
167 } fp_perm_list
[] = {
168 { FCIO_GET_NUM_DEVS
, FP_OPEN
},
169 { FCIO_GET_DEV_LIST
, FP_OPEN
},
170 { FCIO_GET_SYM_PNAME
, FP_OPEN
},
171 { FCIO_GET_SYM_NNAME
, FP_OPEN
},
172 { FCIO_SET_SYM_PNAME
, FP_EXCL
},
173 { FCIO_SET_SYM_NNAME
, FP_EXCL
},
174 { FCIO_GET_LOGI_PARAMS
, FP_OPEN
},
175 { FCIO_DEV_LOGIN
, FP_EXCL
},
176 { FCIO_DEV_LOGOUT
, FP_EXCL
},
177 { FCIO_GET_STATE
, FP_OPEN
},
178 { FCIO_DEV_REMOVE
, FP_EXCL
},
179 { FCIO_GET_FCODE_REV
, FP_OPEN
},
180 { FCIO_GET_FW_REV
, FP_OPEN
},
181 { FCIO_GET_DUMP_SIZE
, FP_OPEN
},
182 { FCIO_FORCE_DUMP
, FP_EXCL
},
183 { FCIO_GET_DUMP
, FP_OPEN
},
184 { FCIO_GET_TOPOLOGY
, FP_OPEN
},
185 { FCIO_RESET_LINK
, FP_EXCL
},
186 { FCIO_RESET_HARD
, FP_EXCL
},
187 { FCIO_RESET_HARD_CORE
, FP_EXCL
},
188 { FCIO_DIAG
, FP_OPEN
},
189 { FCIO_NS
, FP_EXCL
},
190 { FCIO_DOWNLOAD_FW
, FP_EXCL
},
191 { FCIO_DOWNLOAD_FCODE
, FP_EXCL
},
192 { FCIO_LINK_STATUS
, FP_OPEN
},
193 { FCIO_GET_HOST_PARAMS
, FP_OPEN
},
194 { FCIO_GET_NODE_ID
, FP_OPEN
},
195 { FCIO_SET_NODE_ID
, FP_EXCL
},
196 { FCIO_SEND_NODE_ID
, FP_OPEN
},
197 { FCIO_GET_ADAPTER_ATTRIBUTES
, FP_OPEN
},
198 { FCIO_GET_OTHER_ADAPTER_PORTS
, FP_OPEN
},
199 { FCIO_GET_ADAPTER_PORT_ATTRIBUTES
, FP_OPEN
},
200 { FCIO_GET_DISCOVERED_PORT_ATTRIBUTES
, FP_OPEN
},
201 { FCIO_GET_PORT_ATTRIBUTES
, FP_OPEN
},
202 { FCIO_GET_ADAPTER_PORT_STATS
, FP_OPEN
},
203 { FCIO_GET_ADAPTER_PORT_NPIV_ATTRIBUTES
, FP_OPEN
},
204 { FCIO_GET_NPIV_PORT_LIST
, FP_OPEN
},
205 { FCIO_DELETE_NPIV_PORT
, FP_OPEN
},
206 { FCIO_GET_NPIV_ATTRIBUTES
, FP_OPEN
},
207 { FCIO_CREATE_NPIV_PORT
, FP_OPEN
},
208 { FCIO_NPIV_GET_ADAPTER_ATTRIBUTES
, FP_OPEN
}
211 static char *fp_pm_comps
[] = {
218 #ifdef _LITTLE_ENDIAN
219 #define MAKE_BE_32(x) { \
221 ptr1 = (uint32_t *)(x); \
222 for (i = 0; i < sizeof (*(x)) / sizeof (uint32_t); i++) { \
223 *ptr1 = BE_32(*ptr1); \
228 #define MAKE_BE_32(x)
231 static uchar_t fp_verbosity
= (FP_WARNING_MESSAGES
| FP_FATAL_MESSAGES
);
232 static uint32_t fp_options
= 0;
234 static int fp_cmd_wait_cnt
= FP_CMDWAIT_DELAY
;
235 static int fp_retry_delay
= FP_RETRY_DELAY
; /* retry after this delay */
236 static int fp_retry_count
= FP_RETRY_COUNT
; /* number of retries */
237 unsigned int fp_offline_ticker
; /* seconds */
240 * Driver global variable to anchor the list of soft state structs for
241 * all fp driver instances. Used with the Solaris DDI soft state functions.
243 static void *fp_driver_softstate
;
245 static clock_t fp_retry_ticks
;
246 static clock_t fp_offline_ticks
;
248 static int fp_retry_ticker
;
249 static uint32_t fp_unsol_buf_count
= FP_UNSOL_BUF_COUNT
;
250 static uint32_t fp_unsol_buf_size
= FP_UNSOL_BUF_SIZE
;
252 static int fp_log_size
= FP_LOG_SIZE
;
253 static int fp_trace
= FP_TRACE_DEFAULT
;
254 static fc_trace_logq_t
*fp_logq
= NULL
;
256 int fp_get_adapter_paths(char *pathList
, int count
);
257 static void fp_log_port_event(fc_local_port_t
*port
, char *subclass
);
258 static void fp_log_target_event(fc_local_port_t
*port
, char *subclass
,
259 la_wwn_t tgt_pwwn
, uint32_t port_id
);
260 static uint32_t fp_map_remote_port_state(uint32_t rm_state
);
261 static void fp_init_symbolic_names(fc_local_port_t
*port
);
265 * Perform global initialization
272 if ((ret
= ddi_soft_state_init(&fp_driver_softstate
,
273 sizeof (struct fc_local_port
), 8)) != 0) {
277 if ((ret
= scsi_hba_init(&modlinkage
)) != 0) {
278 ddi_soft_state_fini(&fp_driver_softstate
);
282 fp_logq
= fc_trace_alloc_logq(fp_log_size
);
284 if ((ret
= mod_install(&modlinkage
)) != 0) {
285 fc_trace_free_logq(fp_logq
);
286 ddi_soft_state_fini(&fp_driver_softstate
);
287 scsi_hba_fini(&modlinkage
);
295 * Prepare for driver unload
302 if ((ret
= mod_remove(&modlinkage
)) == 0) {
303 fc_trace_free_logq(fp_logq
);
304 ddi_soft_state_fini(&fp_driver_softstate
);
305 scsi_hba_fini(&modlinkage
);
313 * Request mod_info() to handle all cases
316 _info(struct modinfo
*modinfo
)
318 return (mod_info(&modlinkage
, modinfo
));
325 * The respective cmd handlers take care of performing
326 * ULP related invocations
329 fp_attach(dev_info_t
*dip
, ddi_attach_cmd_t cmd
)
334 * We check the value of fp_offline_ticker at this
335 * point. The variable is global for the driver and
336 * not specific to an instance.
338 * If there is no user-defined value found in /etc/system
339 * or fp.conf, then we use 90 seconds (FP_OFFLINE_TICKER).
340 * The minimum setting for this offline timeout according
341 * to the FC-FS2 standard (Fibre Channel Framing and
342 * Signalling-2, see www.t11.org) is R_T_TOV == 100msec.
344 * We do not recommend setting the value to less than 10
345 * seconds (RA_TOV) or more than 90 seconds. If this
346 * variable is greater than 90 seconds then drivers above
347 * fp (fcp, sd, scsi_vhci, vxdmp et al) might complain.
350 fp_offline_ticker
= ddi_prop_get_int(DDI_DEV_T_ANY
,
351 dip
, DDI_PROP_DONTPASS
| DDI_PROP_NOTPROM
, "fp_offline_ticker",
354 if ((fp_offline_ticker
< 10) ||
355 (fp_offline_ticker
> 90)) {
356 cmn_err(CE_WARN
, "Setting fp_offline_ticker to "
357 "%d second(s). This is outside the "
358 "recommended range of 10..90 seconds",
363 * Tick every second when there are commands to retry.
364 * It should tick at the least granular value of pkt_timeout
365 * (which is one second)
369 fp_retry_ticks
= drv_usectohz(fp_retry_ticker
* 1000 * 1000);
370 fp_offline_ticks
= drv_usectohz(fp_offline_ticker
* 1000 * 1000);
374 rval
= fp_attach_handler(dip
);
378 rval
= fp_resume_handler(dip
);
392 * If a ULP fails to handle cmd request converse of
393 * cmd is invoked for ULPs that previously succeeded
397 fp_detach(dev_info_t
*dip
, ddi_detach_cmd_t cmd
)
399 int rval
= DDI_FAILURE
;
400 fc_local_port_t
*port
;
401 fc_attach_cmd_t converse
;
404 if ((port
= ddi_get_soft_state(fp_driver_softstate
,
405 ddi_get_instance(dip
))) == NULL
) {
406 return (DDI_FAILURE
);
409 mutex_enter(&port
->fp_mutex
);
411 if (port
->fp_ulp_attach
) {
412 mutex_exit(&port
->fp_mutex
);
413 return (DDI_FAILURE
);
418 if (port
->fp_task
!= FP_TASK_IDLE
) {
419 mutex_exit(&port
->fp_mutex
);
420 return (DDI_FAILURE
);
423 /* Let's attempt to quit the job handler gracefully */
424 port
->fp_soft_state
|= FP_DETACH_INPROGRESS
;
426 mutex_exit(&port
->fp_mutex
);
427 converse
= FC_CMD_ATTACH
;
428 if (fctl_detach_ulps(port
, FC_CMD_DETACH
,
429 &modlinkage
) != FC_SUCCESS
) {
430 mutex_enter(&port
->fp_mutex
);
431 port
->fp_soft_state
&= ~FP_DETACH_INPROGRESS
;
432 mutex_exit(&port
->fp_mutex
);
437 mutex_enter(&port
->fp_mutex
);
438 for (cnt
= 0; (port
->fp_job_head
) && (cnt
< fp_cmd_wait_cnt
);
440 mutex_exit(&port
->fp_mutex
);
442 mutex_enter(&port
->fp_mutex
);
445 if (port
->fp_job_head
) {
446 mutex_exit(&port
->fp_mutex
);
450 mutex_exit(&port
->fp_mutex
);
452 rval
= fp_detach_handler(port
);
456 mutex_exit(&port
->fp_mutex
);
457 converse
= FC_CMD_RESUME
;
458 if (fctl_detach_ulps(port
, FC_CMD_SUSPEND
,
459 &modlinkage
) != FC_SUCCESS
) {
463 if ((rval
= fp_suspend_handler(port
)) != DDI_SUCCESS
) {
464 (void) callb_generic_cpr(&port
->fp_cpr_info
,
470 mutex_exit(&port
->fp_mutex
);
475 * Use softint to perform reattach. Mark fp_ulp_attach so we
476 * don't attempt to do this repeatedly on behalf of some persistent
479 if (rval
!= DDI_SUCCESS
) {
480 mutex_enter(&port
->fp_mutex
);
481 port
->fp_ulp_attach
= 1;
484 * If the port is in the low power mode then there is
485 * possibility that fca too could be in low power mode.
486 * Try to raise the power before calling attach ulps.
489 if ((port
->fp_soft_state
& FP_SOFT_POWER_DOWN
) &&
490 (!(port
->fp_soft_state
& FP_SOFT_NO_PMCOMP
))) {
491 mutex_exit(&port
->fp_mutex
);
492 (void) pm_raise_power(port
->fp_port_dip
,
493 FP_PM_COMPONENT
, FP_PM_PORT_UP
);
495 mutex_exit(&port
->fp_mutex
);
499 fp_attach_ulps(port
, converse
);
501 mutex_enter(&port
->fp_mutex
);
502 while (port
->fp_ulp_attach
) {
503 cv_wait(&port
->fp_attach_cv
, &port
->fp_mutex
);
506 port
->fp_soft_state
&= ~FP_DETACH_INPROGRESS
;
509 * Mark state as detach failed so asynchronous ULP attach
510 * events (downstream, not the ones we're initiating with
511 * the call to fp_attach_ulps) are not honored. We're
512 * really still in pending detach.
514 port
->fp_soft_state
|= FP_DETACH_FAILED
;
516 mutex_exit(&port
->fp_mutex
);
525 * Given the device number, return either the
526 * dev_info_t pointer or the instance number.
531 fp_getinfo(dev_info_t
*dip
, ddi_info_cmd_t cmd
, void *arg
, void **result
)
535 fc_local_port_t
*port
;
538 instance
= getminor((dev_t
)arg
);
541 case DDI_INFO_DEVT2DEVINFO
:
542 if ((port
= ddi_get_soft_state(fp_driver_softstate
,
543 instance
)) == NULL
) {
547 *result
= (void *)port
->fp_port_dip
;
550 case DDI_INFO_DEVT2INSTANCE
:
551 *result
= (void *)(uintptr_t)instance
;
564 * Entry point for power up and power down request from kernel
567 fp_power(dev_info_t
*dip
, int comp
, int level
)
569 int rval
= DDI_FAILURE
;
570 fc_local_port_t
*port
;
572 port
= ddi_get_soft_state(fp_driver_softstate
, ddi_get_instance(dip
));
573 if (port
== NULL
|| comp
!= FP_PM_COMPONENT
) {
582 * If the port is DDI_SUSPENDed, let the DDI_RESUME
583 * code complete the rediscovery.
585 mutex_enter(&port
->fp_mutex
);
586 if (port
->fp_soft_state
& FP_SOFT_SUSPEND
) {
587 port
->fp_soft_state
&= ~FP_SOFT_POWER_DOWN
;
588 port
->fp_pm_level
= FP_PM_PORT_UP
;
589 mutex_exit(&port
->fp_mutex
);
590 fctl_attach_ulps(port
, FC_CMD_POWER_UP
, &modlinkage
);
594 if (port
->fp_soft_state
& FP_SOFT_POWER_DOWN
) {
595 ASSERT(port
->fp_pm_level
== FP_PM_PORT_DOWN
);
597 port
->fp_pm_level
= FP_PM_PORT_UP
;
598 rval
= fp_power_up(port
);
599 if (rval
!= DDI_SUCCESS
) {
600 port
->fp_pm_level
= FP_PM_PORT_DOWN
;
603 port
->fp_pm_level
= FP_PM_PORT_UP
;
605 mutex_exit(&port
->fp_mutex
);
608 case FP_PM_PORT_DOWN
:
609 mutex_enter(&port
->fp_mutex
);
611 ASSERT(!(port
->fp_soft_state
& FP_SOFT_NO_PMCOMP
));
612 if (port
->fp_soft_state
& FP_SOFT_NO_PMCOMP
) {
614 * PM framework goofed up. We have don't
615 * have any PM components. Let's never go down.
617 mutex_exit(&port
->fp_mutex
);
622 if (port
->fp_ulp_attach
) {
623 /* We shouldn't let the power go down */
624 mutex_exit(&port
->fp_mutex
);
629 * Not a whole lot to do if we are detaching
631 if (port
->fp_soft_state
& FP_SOFT_IN_DETACH
) {
632 port
->fp_pm_level
= FP_PM_PORT_DOWN
;
633 mutex_exit(&port
->fp_mutex
);
638 if (!port
->fp_pm_busy
&& !port
->fp_pm_busy_nocomp
) {
639 port
->fp_pm_level
= FP_PM_PORT_DOWN
;
641 rval
= fp_power_down(port
);
642 if (rval
!= DDI_SUCCESS
) {
643 port
->fp_pm_level
= FP_PM_PORT_UP
;
644 ASSERT(!(port
->fp_soft_state
&
645 FP_SOFT_POWER_DOWN
));
647 ASSERT(port
->fp_soft_state
&
651 mutex_exit(&port
->fp_mutex
);
663 * Open FC port devctl node
666 fp_open(dev_t
*devp
, int flag
, int otype
, cred_t
*credp
)
669 fc_local_port_t
*port
;
671 if (otype
!= OTYP_CHR
) {
676 * This is not a toy to play with. Allow only powerful
677 * users (hopefully knowledgeable) to access the port
678 * (A hacker potentially could download a sick binary
681 if (drv_priv(credp
)) {
685 instance
= (int)getminor(*devp
);
687 port
= ddi_get_soft_state(fp_driver_softstate
, instance
);
692 mutex_enter(&port
->fp_mutex
);
693 if (port
->fp_flag
& FP_EXCL
) {
695 * It is already open for exclusive access.
696 * So shut the door on this caller.
698 mutex_exit(&port
->fp_mutex
);
703 if (port
->fp_flag
& FP_OPEN
) {
705 * Exclusive operation not possible
706 * as it is already opened
708 mutex_exit(&port
->fp_mutex
);
711 port
->fp_flag
|= FP_EXCL
;
713 port
->fp_flag
|= FP_OPEN
;
714 mutex_exit(&port
->fp_mutex
);
721 * The driver close entry point is called on the last close()
722 * of a device. So it is perfectly alright to just clobber the
723 * open flag and reset it to idle (instead of having to reset
724 * each flag bits). For any confusion, check out close(9E).
729 fp_close(dev_t dev
, int flag
, int otype
, cred_t
*credp
)
732 fc_local_port_t
*port
;
734 if (otype
!= OTYP_CHR
) {
738 instance
= (int)getminor(dev
);
740 port
= ddi_get_soft_state(fp_driver_softstate
, instance
);
745 mutex_enter(&port
->fp_mutex
);
746 if ((port
->fp_flag
& FP_OPEN
) == 0) {
747 mutex_exit(&port
->fp_mutex
);
750 port
->fp_flag
= FP_IDLE
;
751 mutex_exit(&port
->fp_mutex
);
757 * Handle IOCTL requests
762 fp_ioctl(dev_t dev
, int cmd
, intptr_t data
, int mode
, cred_t
*credp
, int *rval
)
767 fc_local_port_t
*port
;
769 instance
= (int)getminor(dev
);
771 port
= ddi_get_soft_state(fp_driver_softstate
, instance
);
776 mutex_enter(&port
->fp_mutex
);
777 if ((port
->fp_flag
& FP_OPEN
) == 0) {
778 mutex_exit(&port
->fp_mutex
);
782 if (port
->fp_soft_state
& FP_SOFT_SUSPEND
) {
783 mutex_exit(&port
->fp_mutex
);
787 mutex_exit(&port
->fp_mutex
);
789 /* this will raise power if necessary */
790 ret
= fctl_busy_port(port
);
795 ASSERT(port
->fp_pm_level
== FP_PM_PORT_UP
);
800 #ifdef _MULTI_DATAMODEL
801 switch (ddi_model_convert_from(mode
& FMODELS
)) {
802 case DDI_MODEL_ILP32
: {
803 struct fcio32 fcio32
;
805 if (ddi_copyin((void *)data
, (void *)&fcio32
,
806 sizeof (struct fcio32
), mode
)) {
810 fcio
.fcio_xfer
= fcio32
.fcio_xfer
;
811 fcio
.fcio_cmd
= fcio32
.fcio_cmd
;
812 fcio
.fcio_flags
= fcio32
.fcio_flags
;
813 fcio
.fcio_cmd_flags
= fcio32
.fcio_cmd_flags
;
814 fcio
.fcio_ilen
= (size_t)fcio32
.fcio_ilen
;
816 (caddr_t
)(uintptr_t)fcio32
.fcio_ibuf
;
817 fcio
.fcio_olen
= (size_t)fcio32
.fcio_olen
;
819 (caddr_t
)(uintptr_t)fcio32
.fcio_obuf
;
820 fcio
.fcio_alen
= (size_t)fcio32
.fcio_alen
;
822 (caddr_t
)(uintptr_t)fcio32
.fcio_abuf
;
823 fcio
.fcio_errno
= fcio32
.fcio_errno
;
828 if (ddi_copyin((void *)data
, (void *)&fcio
,
829 sizeof (fcio_t
), mode
)) {
834 #else /* _MULTI_DATAMODEL */
835 if (ddi_copyin((void *)data
, (void *)&fcio
,
836 sizeof (fcio_t
), mode
)) {
840 #endif /* _MULTI_DATAMODEL */
842 ret
= fp_fciocmd(port
, data
, mode
, &fcio
);
848 ret
= fctl_ulp_port_ioctl(port
, dev
, cmd
, data
,
852 fctl_idle_port(port
);
859 * Init Symbolic Port Name and Node Name
860 * LV will try to get symbolic names from FCA driver
861 * and register these to name server,
862 * if LV fails to get these,
863 * LV will register its default symbolic names to name server.
864 * The Default symbolic node name format is :
865 * <hostname>:<hba driver name>(instance)
866 * The Default symbolic port name format is :
870 fp_init_symbolic_names(fc_local_port_t
*port
)
872 const char *vendorname
= ddi_driver_name(port
->fp_fca_dip
);
874 char fcaname
[50] = {0};
875 int hostnlen
, fcanlen
;
877 if (port
->fp_sym_node_namelen
== 0) {
878 hostnlen
= strlen(utsname
.nodename
);
879 (void) snprintf(fcaname
, sizeof (fcaname
),
880 "%s%d", vendorname
, ddi_get_instance(port
->fp_fca_dip
));
881 fcanlen
= strlen(fcaname
);
883 sym_name
= kmem_zalloc(hostnlen
+ fcanlen
+ 2, KM_SLEEP
);
884 (void) sprintf(sym_name
, "%s:%s", utsname
.nodename
, fcaname
);
885 port
->fp_sym_node_namelen
= strlen(sym_name
);
886 if (port
->fp_sym_node_namelen
>= FCHBA_SYMB_NAME_LEN
) {
887 port
->fp_sym_node_namelen
= FCHBA_SYMB_NAME_LEN
;
889 (void) strncpy(port
->fp_sym_node_name
, sym_name
,
890 port
->fp_sym_node_namelen
);
891 kmem_free(sym_name
, hostnlen
+ fcanlen
+ 2);
894 if (port
->fp_sym_port_namelen
== 0) {
895 char *pathname
= kmem_zalloc(MAXPATHLEN
, KM_SLEEP
);
897 (void) ddi_pathname(port
->fp_port_dip
, pathname
);
898 port
->fp_sym_port_namelen
= strlen(pathname
);
899 if (port
->fp_sym_port_namelen
>= FCHBA_SYMB_NAME_LEN
) {
900 port
->fp_sym_port_namelen
= FCHBA_SYMB_NAME_LEN
;
902 (void) strncpy(port
->fp_sym_port_name
, pathname
,
903 port
->fp_sym_port_namelen
);
904 kmem_free(pathname
, MAXPATHLEN
);
910 * Perform port attach
913 fp_attach_handler(dev_info_t
*dip
)
923 fc_local_port_t
*port
;
925 fc_local_port_t
*phyport
= NULL
;
927 char pwwn
[17], nwwn
[17];
929 instance
= ddi_get_instance(dip
);
930 port_len
= sizeof (port_num
);
931 rval
= ddi_prop_op(DDI_DEV_T_ANY
, dip
, PROP_LEN_AND_VAL_BUF
,
932 DDI_PROP_DONTPASS
| DDI_PROP_CANSLEEP
, "port",
933 (caddr_t
)&port_num
, &port_len
);
934 if (rval
!= DDI_SUCCESS
) {
935 cmn_err(CE_WARN
, "fp(%d): No port property in devinfo",
937 return (DDI_FAILURE
);
940 if (ddi_create_minor_node(dip
, "devctl", S_IFCHR
, instance
,
941 DDI_NT_NEXUS
, 0) != DDI_SUCCESS
) {
942 cmn_err(CE_WARN
, "fp(%d): failed to create devctl minor node",
944 return (DDI_FAILURE
);
947 if (ddi_create_minor_node(dip
, "fc", S_IFCHR
, instance
,
948 DDI_NT_FC_ATTACHMENT_POINT
, 0) != DDI_SUCCESS
) {
949 cmn_err(CE_WARN
, "fp(%d): failed to create fc attachment"
950 " point minor node", instance
);
951 ddi_remove_minor_node(dip
, NULL
);
952 return (DDI_FAILURE
);
955 if (ddi_soft_state_zalloc(fp_driver_softstate
, instance
)
957 cmn_err(CE_WARN
, "fp(%d): failed to alloc soft state",
959 ddi_remove_minor_node(dip
, NULL
);
960 return (DDI_FAILURE
);
962 port
= ddi_get_soft_state(fp_driver_softstate
, instance
);
964 (void) sprintf(port
->fp_ibuf
, "fp(%d)", instance
);
966 port
->fp_instance
= instance
;
967 port
->fp_ulp_attach
= 1;
968 port
->fp_port_num
= port_num
;
969 port
->fp_verbose
= fp_verbosity
;
970 port
->fp_options
= fp_options
;
972 port
->fp_fca_dip
= ddi_get_parent(dip
);
973 port
->fp_port_dip
= dip
;
974 port
->fp_fca_tran
= (fc_fca_tran_t
*)
975 ddi_get_driver_private(port
->fp_fca_dip
);
977 port
->fp_task
= port
->fp_last_task
= FP_TASK_IDLE
;
980 * Init the starting value of fp_rscn_count. Note that if
981 * FC_INVALID_RSCN_COUNT is 0 (which is what it currently is), the
982 * actual # of RSCNs will be (fp_rscn_count - 1)
984 port
->fp_rscn_count
= FC_INVALID_RSCN_COUNT
+ 1;
986 mutex_init(&port
->fp_mutex
, NULL
, MUTEX_DRIVER
, NULL
);
987 cv_init(&port
->fp_cv
, NULL
, CV_DRIVER
, NULL
);
988 cv_init(&port
->fp_attach_cv
, NULL
, CV_DRIVER
, NULL
);
990 (void) sprintf(name
, "fp%d_cache", instance
);
992 if ((portpro1
= ddi_prop_get_int(DDI_DEV_T_ANY
,
993 dip
, DDI_PROP_DONTPASS
| DDI_PROP_NOTPROM
,
994 "phyport-instance", -1)) != -1) {
995 phyport
= ddi_get_soft_state(fp_driver_softstate
, portpro1
);
996 fc_wwn_to_str(&phyport
->fp_service_params
.nport_ww_name
, pwwn
);
997 fc_wwn_to_str(&phyport
->fp_service_params
.node_ww_name
, nwwn
);
998 port
->fp_npiv_type
= FC_NPIV_PORT
;
1002 * Allocate the pool of fc_packet_t structs to be used with
1005 port
->fp_pkt_cache
= kmem_cache_create(name
,
1006 (port
->fp_fca_tran
->fca_pkt_size
) + sizeof (fp_cmd_t
), 8,
1007 fp_cache_constructor
, fp_cache_destructor
, NULL
, (void *)port
,
1009 port
->fp_out_fpcmds
= 0;
1010 if (port
->fp_pkt_cache
== NULL
) {
1011 goto cache_alloc_failed
;
1016 * Allocate the d_id and pwwn hash tables for all remote ports
1017 * connected to this local port.
1019 port
->fp_did_table
= kmem_zalloc(did_table_size
*
1020 sizeof (struct d_id_hash
), KM_SLEEP
);
1022 port
->fp_pwwn_table
= kmem_zalloc(pwwn_table_size
*
1023 sizeof (struct pwwn_hash
), KM_SLEEP
);
1025 port
->fp_taskq
= taskq_create("fp_ulp_callback", 1,
1026 MINCLSYSPRI
, 1, 16, 0);
1028 /* Indicate that don't have the pm components yet */
1029 port
->fp_soft_state
|= FP_SOFT_NO_PMCOMP
;
1032 * Bind the callbacks with the FCA driver. This will open the gate
1033 * for asynchronous callbacks, so after this call the fp_mutex
1034 * must be held when updating the fc_local_port_t struct.
1036 * This is done _before_ setting up the job thread so we can avoid
1037 * cleaning up after the thread_create() in the error path. This
1038 * also means fp will be operating with fp_els_resp_pkt set to NULL.
1040 if (fp_bind_callbacks(port
) != DDI_SUCCESS
) {
1041 goto bind_callbacks_failed
;
1045 mutex_enter(&phyport
->fp_mutex
);
1046 if (phyport
->fp_port_next
) {
1047 phyport
->fp_port_next
->fp_port_prev
= port
;
1048 port
->fp_port_next
= phyport
->fp_port_next
;
1049 phyport
->fp_port_next
= port
;
1050 port
->fp_port_prev
= phyport
;
1052 phyport
->fp_port_next
= port
;
1053 phyport
->fp_port_prev
= port
;
1054 port
->fp_port_next
= phyport
;
1055 port
->fp_port_prev
= phyport
;
1057 mutex_exit(&phyport
->fp_mutex
);
1061 * Init Symbolic Names
1063 fp_init_symbolic_names(port
);
1065 pkt
= fp_alloc_pkt(port
, sizeof (la_els_logi_t
), sizeof (la_els_logi_t
),
1069 cmn_err(CE_WARN
, "fp(%d): failed to allocate ELS packet",
1071 goto alloc_els_packet_failed
;
1074 (void) thread_create(NULL
, 0, fp_job_handler
, port
, 0, &p0
, TS_RUN
,
1077 fc_wwn_to_str(&port
->fp_service_params
.nport_ww_name
, i_pwwn
);
1078 if (ddi_prop_update_string(DDI_DEV_T_NONE
, dip
, "initiator-port",
1079 i_pwwn
) != DDI_PROP_SUCCESS
) {
1080 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
1081 "fp(%d): Updating 'initiator-port' property"
1082 " on fp dev_info node failed", instance
);
1085 fc_wwn_to_str(&port
->fp_service_params
.node_ww_name
, i_pwwn
);
1086 if (ddi_prop_update_string(DDI_DEV_T_NONE
, dip
, "initiator-node",
1087 i_pwwn
) != DDI_PROP_SUCCESS
) {
1088 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
1089 "fp(%d): Updating 'initiator-node' property"
1090 " on fp dev_info node failed", instance
);
1093 mutex_enter(&port
->fp_mutex
);
1094 port
->fp_els_resp_pkt
= pkt
;
1095 mutex_exit(&port
->fp_mutex
);
1098 * Determine the count of unsolicited buffers this FCA can support
1100 fp_retrieve_caps(port
);
1103 * Allocate unsolicited buffer tokens
1105 if (port
->fp_ub_count
) {
1106 ub_count
= port
->fp_ub_count
;
1107 port
->fp_ub_tokens
= kmem_zalloc(ub_count
*
1108 sizeof (*port
->fp_ub_tokens
), KM_SLEEP
);
1110 * Do not fail the attach if unsolicited buffer allocation
1111 * fails; Just try to get along with whatever the FCA can do.
1113 if (fc_ulp_uballoc(port
, &ub_count
, fp_unsol_buf_size
,
1114 FC_TYPE_EXTENDED_LS
, port
->fp_ub_tokens
) !=
1115 FC_SUCCESS
|| ub_count
!= port
->fp_ub_count
) {
1116 cmn_err(CE_WARN
, "fp(%d): failed to allocate "
1117 " Unsolicited buffers. proceeding with attach...",
1119 kmem_free(port
->fp_ub_tokens
,
1120 sizeof (*port
->fp_ub_tokens
) * port
->fp_ub_count
);
1121 port
->fp_ub_tokens
= NULL
;
1125 fp_load_ulp_modules(dip
, port
);
1128 * Enable DDI_SUSPEND and DDI_RESUME for this instance.
1130 (void) ddi_prop_create(DDI_DEV_T_NONE
, dip
, DDI_PROP_CANSLEEP
,
1131 "pm-hardware-state", "needs-suspend-resume",
1132 strlen("needs-suspend-resume") + 1);
1135 * fctl maintains a list of all port handles, so
1136 * help fctl add this one to its list now.
1138 mutex_enter(&port
->fp_mutex
);
1139 fctl_add_port(port
);
1142 * If a state change is already in progress, set the bind state t
1143 * OFFLINE as well, so further state change callbacks into ULPs
1144 * will pass the appropriate states
1146 if (FC_PORT_STATE_MASK(port
->fp_bind_state
) == FC_STATE_OFFLINE
||
1147 port
->fp_statec_busy
) {
1148 port
->fp_bind_state
= FC_STATE_OFFLINE
;
1149 mutex_exit(&port
->fp_mutex
);
1151 fp_startup_done((opaque_t
)port
, FC_PKT_SUCCESS
);
1154 * Without dropping the mutex, ensure that the port
1155 * startup happens ahead of state change callback
1158 ASSERT(port
->fp_job_tail
== NULL
&& port
->fp_job_head
== NULL
);
1160 port
->fp_last_task
= port
->fp_task
;
1161 port
->fp_task
= FP_TASK_PORT_STARTUP
;
1163 job
= fctl_alloc_job(JOB_PORT_STARTUP
, JOB_TYPE_FCTL_ASYNC
,
1164 fp_startup_done
, (opaque_t
)port
, KM_SLEEP
);
1166 port
->fp_job_head
= port
->fp_job_tail
= job
;
1168 cv_signal(&port
->fp_cv
);
1170 mutex_exit(&port
->fp_mutex
);
1173 mutex_enter(&port
->fp_mutex
);
1174 while (port
->fp_ulp_attach
) {
1175 cv_wait(&port
->fp_attach_cv
, &port
->fp_mutex
);
1177 mutex_exit(&port
->fp_mutex
);
1179 if (ddi_prop_update_string_array(DDI_DEV_T_NONE
, dip
,
1180 "pm-components", fp_pm_comps
,
1181 sizeof (fp_pm_comps
) / sizeof (fp_pm_comps
[0])) !=
1183 FP_TRACE(FP_NHEAD2(9, 0), "Failed to create PM"
1184 " components property, PM disabled on this port.");
1185 mutex_enter(&port
->fp_mutex
);
1186 port
->fp_pm_level
= FP_PM_PORT_UP
;
1187 mutex_exit(&port
->fp_mutex
);
1189 if (pm_raise_power(dip
, FP_PM_COMPONENT
,
1190 FP_PM_PORT_UP
) != DDI_SUCCESS
) {
1191 FP_TRACE(FP_NHEAD2(9, 0), "Failed to raise"
1193 mutex_enter(&port
->fp_mutex
);
1194 port
->fp_pm_level
= FP_PM_PORT_UP
;
1195 mutex_exit(&port
->fp_mutex
);
1199 * Don't unset the FP_SOFT_NO_PMCOMP flag until after
1200 * the call to pm_raise_power. The PM framework can't
1201 * handle multiple threads calling into it during attach.
1204 mutex_enter(&port
->fp_mutex
);
1205 port
->fp_soft_state
&= ~FP_SOFT_NO_PMCOMP
;
1206 mutex_exit(&port
->fp_mutex
);
1209 ddi_report_dev(dip
);
1211 fp_log_port_event(port
, ESC_SUNFC_PORT_ATTACH
);
1213 return (DDI_SUCCESS
);
1216 * Unwind any/all preceeding allocations in the event of an error.
1219 alloc_els_packet_failed
:
1221 if (port
->fp_fca_handle
!= NULL
) {
1222 port
->fp_fca_tran
->fca_unbind_port(port
->fp_fca_handle
);
1223 port
->fp_fca_handle
= NULL
;
1226 if (port
->fp_ub_tokens
!= NULL
) {
1227 (void) fc_ulp_ubfree(port
, port
->fp_ub_count
,
1228 port
->fp_ub_tokens
);
1229 kmem_free(port
->fp_ub_tokens
,
1230 port
->fp_ub_count
* sizeof (*port
->fp_ub_tokens
));
1231 port
->fp_ub_tokens
= NULL
;
1234 if (port
->fp_els_resp_pkt
!= NULL
) {
1235 fp_free_pkt(port
->fp_els_resp_pkt
);
1236 port
->fp_els_resp_pkt
= NULL
;
1239 bind_callbacks_failed
:
1241 if (port
->fp_taskq
!= NULL
) {
1242 taskq_destroy(port
->fp_taskq
);
1245 if (port
->fp_pwwn_table
!= NULL
) {
1246 kmem_free(port
->fp_pwwn_table
,
1247 pwwn_table_size
* sizeof (struct pwwn_hash
));
1248 port
->fp_pwwn_table
= NULL
;
1251 if (port
->fp_did_table
!= NULL
) {
1252 kmem_free(port
->fp_did_table
,
1253 did_table_size
* sizeof (struct d_id_hash
));
1254 port
->fp_did_table
= NULL
;
1257 if (port
->fp_pkt_cache
!= NULL
) {
1258 kmem_cache_destroy(port
->fp_pkt_cache
);
1259 port
->fp_pkt_cache
= NULL
;
1264 cv_destroy(&port
->fp_attach_cv
);
1265 cv_destroy(&port
->fp_cv
);
1266 mutex_destroy(&port
->fp_mutex
);
1267 ddi_remove_minor_node(port
->fp_port_dip
, NULL
);
1268 ddi_soft_state_free(fp_driver_softstate
, instance
);
1269 ddi_prop_remove_all(dip
);
1271 return (DDI_FAILURE
);
1276 * Handle DDI_RESUME request
1279 fp_resume_handler(dev_info_t
*dip
)
1282 fc_local_port_t
*port
;
1284 port
= ddi_get_soft_state(fp_driver_softstate
, ddi_get_instance(dip
));
1286 ASSERT(port
!= NULL
);
1289 mutex_enter(&port
->fp_mutex
);
1290 ASSERT(port
->fp_soft_state
& FP_SOFT_SUSPEND
);
1291 mutex_exit(&port
->fp_mutex
);
1295 * If the port was power suspended, raise the power level
1297 mutex_enter(&port
->fp_mutex
);
1298 if ((port
->fp_soft_state
& FP_SOFT_POWER_DOWN
) &&
1299 (!(port
->fp_soft_state
& FP_SOFT_NO_PMCOMP
))) {
1300 ASSERT(port
->fp_pm_level
== FP_PM_PORT_DOWN
);
1302 mutex_exit(&port
->fp_mutex
);
1303 if (pm_raise_power(dip
, FP_PM_COMPONENT
,
1304 FP_PM_PORT_UP
) != DDI_SUCCESS
) {
1305 FP_TRACE(FP_NHEAD2(9, 0),
1306 "Failed to raise the power level");
1307 return (DDI_FAILURE
);
1309 mutex_enter(&port
->fp_mutex
);
1311 port
->fp_soft_state
&= ~FP_SOFT_SUSPEND
;
1312 mutex_exit(&port
->fp_mutex
);
1315 * All the discovery is initiated and handled by per-port thread.
1316 * Further all the discovery is done in handled in callback mode
1317 * (not polled mode); In a specific case such as this, the discovery
1318 * is required to happen in polled mode. The easiest way out is
1319 * to bail out port thread and get started. Come back and fix this
1320 * to do on demand discovery initiated by ULPs. ULPs such as FCP
1321 * will do on-demand discovery during pre-power-up busctl handling
1322 * which will only be possible when SCSA provides a new HBA vector
1323 * for sending down the PM busctl requests.
1325 (void) callb_generic_cpr(&port
->fp_cpr_info
, CB_CODE_CPR_RESUME
);
1327 rval
= fp_resume_all(port
, FC_CMD_RESUME
);
1328 if (rval
!= DDI_SUCCESS
) {
1329 mutex_enter(&port
->fp_mutex
);
1330 port
->fp_soft_state
|= FP_SOFT_SUSPEND
;
1331 mutex_exit(&port
->fp_mutex
);
1332 (void) callb_generic_cpr(&port
->fp_cpr_info
,
1340 * Perform FC Port power on initialization
1343 fp_power_up(fc_local_port_t
*port
)
1347 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
1349 ASSERT((port
->fp_soft_state
& FP_SOFT_SUSPEND
) == 0);
1350 ASSERT(port
->fp_soft_state
& FP_SOFT_POWER_DOWN
);
1352 port
->fp_soft_state
&= ~FP_SOFT_POWER_DOWN
;
1354 mutex_exit(&port
->fp_mutex
);
1356 rval
= fp_resume_all(port
, FC_CMD_POWER_UP
);
1357 if (rval
!= DDI_SUCCESS
) {
1358 mutex_enter(&port
->fp_mutex
);
1359 port
->fp_soft_state
|= FP_SOFT_POWER_DOWN
;
1361 mutex_enter(&port
->fp_mutex
);
1369 * It is important to note that the power may possibly be removed between
1370 * SUSPEND and the ensuing RESUME operation. In such a context the underlying
1371 * FC port hardware would have gone through an OFFLINE to ONLINE transition
1372 * (hardware state). In this case, the port driver may need to rediscover the
1373 * topology, perform LOGINs, register with the name server again and perform
1374 * any such port initialization procedures. To perform LOGINs, the driver could
1375 * use the port device handle to see if a LOGIN needs to be performed and use
1376 * the D_ID and WWN in it. The LOGINs may fail (if the hardware is reconfigured
1377 * or removed) which will be reflected in the map the ULPs will see.
1380 fp_resume_all(fc_local_port_t
*port
, fc_attach_cmd_t cmd
)
1383 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
1385 if (fp_bind_callbacks(port
) != DDI_SUCCESS
) {
1386 return (DDI_FAILURE
);
1389 mutex_enter(&port
->fp_mutex
);
1392 * If there are commands queued for delayed retry, instead of
1393 * working the hard way to figure out which ones are good for
1394 * restart and which ones not (ELSs are definitely not good
1395 * as the port will have to go through a new spin of rediscovery
1396 * now), so just flush them out.
1398 if (port
->fp_restore
& FP_RESTORE_WAIT_TIMEOUT
) {
1401 port
->fp_restore
&= ~FP_RESTORE_WAIT_TIMEOUT
;
1403 mutex_exit(&port
->fp_mutex
);
1404 while ((cmd
= fp_deque_cmd(port
)) != NULL
) {
1405 cmd
->cmd_pkt
.pkt_state
= FC_PKT_TRAN_ERROR
;
1408 mutex_enter(&port
->fp_mutex
);
1411 if (FC_PORT_STATE_MASK(port
->fp_bind_state
) == FC_STATE_OFFLINE
) {
1412 if ((port
->fp_restore
& FP_RESTORE_OFFLINE_TIMEOUT
) ||
1413 port
->fp_dev_count
) {
1414 port
->fp_restore
&= ~FP_RESTORE_OFFLINE_TIMEOUT
;
1415 port
->fp_offline_tid
= timeout(fp_offline_timeout
,
1416 (caddr_t
)port
, fp_offline_ticks
);
1418 if (port
->fp_job_head
) {
1419 cv_signal(&port
->fp_cv
);
1421 mutex_exit(&port
->fp_mutex
);
1422 fctl_attach_ulps(port
, cmd
, &modlinkage
);
1424 struct job_request
*job
;
1427 * If an OFFLINE timer was running at the time of
1428 * suspending, there is no need to restart it as
1429 * the port is ONLINE now.
1431 port
->fp_restore
&= ~FP_RESTORE_OFFLINE_TIMEOUT
;
1432 if (port
->fp_statec_busy
== 0) {
1433 port
->fp_soft_state
|= FP_SOFT_IN_STATEC_CB
;
1435 port
->fp_statec_busy
++;
1436 mutex_exit(&port
->fp_mutex
);
1438 job
= fctl_alloc_job(JOB_PORT_ONLINE
,
1439 JOB_CANCEL_ULP_NOTIFICATION
, NULL
, NULL
, KM_SLEEP
);
1440 fctl_enque_job(port
, job
);
1443 fctl_remove_oldies(port
);
1445 fctl_attach_ulps(port
, cmd
, &modlinkage
);
1446 fctl_dealloc_job(job
);
1449 return (DDI_SUCCESS
);
1454 * At this time, there shouldn't be any I/O requests on this port.
1455 * But the unsolicited callbacks from the underlying FCA port need
1456 * to be handled very carefully. The steps followed to handle the
1458 * + Grab the port driver mutex, check if the unsolicited
1459 * callback is currently under processing. If true, fail
1460 * the DDI_DETACH request by printing a message; If false
1461 * mark the DDI_DETACH as under progress, so that any
1462 * further unsolicited callbacks get bounced.
1463 * + Perform PRLO/LOGO if necessary, cleanup all the data
1465 * + Get the job_handler thread to gracefully exit.
1466 * + Unregister callbacks with the FCA port.
1467 * + Now that some peace is found, notify all the ULPs of
1468 * DDI_DETACH request (using ulp_port_detach entry point)
1469 * + Free all mutexes, semaphores, conditional variables.
1470 * + Free the soft state, return success.
1472 * Important considerations:
1473 * Port driver de-registers state change and unsolicited
1474 * callbacks before taking up the task of notifying ULPs
1475 * and performing PRLO and LOGOs.
1477 * A port may go offline at the time PRLO/LOGO is being
1478 * requested. It is expected of all FCA drivers to fail
1479 * such requests either immediately with a FC_OFFLINE
1480 * return code to fc_fca_transport() or return the packet
1481 * asynchronously with pkt state set to FC_PKT_PORT_OFFLINE
1484 fp_detach_handler(fc_local_port_t
*port
)
1487 uint32_t delay_count
;
1488 fc_orphan_t
*orp
, *tmporp
;
1491 * In a Fabric topology with many host ports connected to
1492 * a switch, another detaching instance of fp might have
1493 * triggered a LOGO (which is an unsolicited request to
1494 * this instance). So in order to be able to successfully
1495 * detach by taking care of such cases a delay of about
1496 * 30 seconds is introduced.
1499 mutex_enter(&port
->fp_mutex
);
1500 if (port
->fp_out_fpcmds
!= 0) {
1502 * At this time we can only check fp internal commands, because
1503 * sd/ssd/scsi_vhci should have finsihed all their commands,
1504 * fcp/fcip/fcsm should have finished all their commands.
1506 * It seems that all fp internal commands are asynchronous now.
1508 port
->fp_soft_state
&= ~FP_DETACH_INPROGRESS
;
1509 mutex_exit(&port
->fp_mutex
);
1511 cmn_err(CE_WARN
, "fp(%d): %d fp_cmd(s) is/are in progress"
1512 " Failing detach", port
->fp_instance
, port
->fp_out_fpcmds
);
1513 return (DDI_FAILURE
);
1516 while ((port
->fp_soft_state
&
1517 (FP_SOFT_IN_STATEC_CB
| FP_SOFT_IN_UNSOL_CB
)) &&
1518 (delay_count
< 30)) {
1519 mutex_exit(&port
->fp_mutex
);
1522 mutex_enter(&port
->fp_mutex
);
1525 if (port
->fp_soft_state
&
1526 (FP_SOFT_IN_STATEC_CB
| FP_SOFT_IN_UNSOL_CB
)) {
1527 port
->fp_soft_state
&= ~FP_DETACH_INPROGRESS
;
1528 mutex_exit(&port
->fp_mutex
);
1530 cmn_err(CE_WARN
, "fp(%d): FCA callback in progress: "
1531 " Failing detach", port
->fp_instance
);
1532 return (DDI_FAILURE
);
1535 port
->fp_soft_state
|= FP_SOFT_IN_DETACH
;
1536 port
->fp_soft_state
&= ~FP_DETACH_INPROGRESS
;
1537 mutex_exit(&port
->fp_mutex
);
1540 * If we're powered down, we need to raise power prior to submitting
1541 * the JOB_PORT_SHUTDOWN job. Otherwise, the job handler will never
1542 * process the shutdown job.
1544 if (fctl_busy_port(port
) != 0) {
1545 cmn_err(CE_WARN
, "fp(%d): fctl_busy_port failed",
1547 mutex_enter(&port
->fp_mutex
);
1548 port
->fp_soft_state
&= ~FP_SOFT_IN_DETACH
;
1549 mutex_exit(&port
->fp_mutex
);
1550 return (DDI_FAILURE
);
1554 * This will deallocate data structs and cause the "job" thread
1555 * to exit, in preparation for DDI_DETACH on the instance.
1556 * This can sleep for an arbitrary duration, since it waits for
1557 * commands over the wire, timeout(9F) callbacks, etc.
1559 * CAUTION: There is still a race here, where the "job" thread
1560 * can still be executing code even tho the fctl_jobwait() call
1561 * below has returned to us. In theory the fp driver could even be
1562 * modunloaded even tho the job thread isn't done executing.
1563 * without creating the race condition.
1565 job
= fctl_alloc_job(JOB_PORT_SHUTDOWN
, 0, NULL
,
1566 (opaque_t
)port
, KM_SLEEP
);
1567 fctl_enque_job(port
, job
);
1569 fctl_dealloc_job(job
);
1572 (void) pm_lower_power(port
->fp_port_dip
, FP_PM_COMPONENT
,
1575 if (port
->fp_taskq
) {
1576 taskq_destroy(port
->fp_taskq
);
1579 ddi_prop_remove_all(port
->fp_port_dip
);
1581 ddi_remove_minor_node(port
->fp_port_dip
, NULL
);
1583 fctl_remove_port(port
);
1585 fp_free_pkt(port
->fp_els_resp_pkt
);
1587 if (port
->fp_ub_tokens
) {
1588 if (fc_ulp_ubfree(port
, port
->fp_ub_count
,
1589 port
->fp_ub_tokens
) != FC_SUCCESS
) {
1590 cmn_err(CE_WARN
, "fp(%d): couldn't free "
1591 " unsolicited buffers", port
->fp_instance
);
1593 kmem_free(port
->fp_ub_tokens
,
1594 sizeof (*port
->fp_ub_tokens
) * port
->fp_ub_count
);
1595 port
->fp_ub_tokens
= NULL
;
1598 if (port
->fp_pkt_cache
!= NULL
) {
1599 kmem_cache_destroy(port
->fp_pkt_cache
);
1602 port
->fp_fca_tran
->fca_unbind_port(port
->fp_fca_handle
);
1604 mutex_enter(&port
->fp_mutex
);
1605 if (port
->fp_did_table
) {
1606 kmem_free(port
->fp_did_table
, did_table_size
*
1607 sizeof (struct d_id_hash
));
1610 if (port
->fp_pwwn_table
) {
1611 kmem_free(port
->fp_pwwn_table
, pwwn_table_size
*
1612 sizeof (struct pwwn_hash
));
1614 orp
= port
->fp_orphan_list
;
1617 orp
= orp
->orp_next
;
1618 kmem_free(tmporp
, sizeof (*orp
));
1621 mutex_exit(&port
->fp_mutex
);
1623 fp_log_port_event(port
, ESC_SUNFC_PORT_DETACH
);
1625 mutex_destroy(&port
->fp_mutex
);
1626 cv_destroy(&port
->fp_attach_cv
);
1627 cv_destroy(&port
->fp_cv
);
1628 ddi_soft_state_free(fp_driver_softstate
, port
->fp_instance
);
1630 return (DDI_SUCCESS
);
1635 * Steps to perform DDI_SUSPEND operation on a FC port
1637 * - If already suspended return DDI_FAILURE
1638 * - If already power-suspended return DDI_SUCCESS
1639 * - If an unsolicited callback or state change handling is in
1640 * in progress, throw a warning message, return DDI_FAILURE
1642 * - SUSPEND the job_handler thread (means do nothing as it is
1643 * taken care of by the CPR frame work)
1646 fp_suspend_handler(fc_local_port_t
*port
)
1648 uint32_t delay_count
;
1650 mutex_enter(&port
->fp_mutex
);
1653 * The following should never happen, but
1654 * let the driver be more defensive here
1656 if (port
->fp_soft_state
& FP_SOFT_SUSPEND
) {
1657 mutex_exit(&port
->fp_mutex
);
1658 return (DDI_FAILURE
);
1662 * If the port is already power suspended, there
1663 * is nothing else to do, So return DDI_SUCCESS,
1664 * but mark the SUSPEND bit in the soft state
1667 if (port
->fp_soft_state
& FP_SOFT_POWER_DOWN
) {
1668 port
->fp_soft_state
|= FP_SOFT_SUSPEND
;
1669 mutex_exit(&port
->fp_mutex
);
1670 return (DDI_SUCCESS
);
1674 * Check if an unsolicited callback or state change handling is
1675 * in progress. If true, fail the suspend operation; also throw
1676 * a warning message notifying the failure. Note that Sun PCI
1677 * hotplug spec recommends messages in cases of failure (but
1678 * not flooding the console)
1680 * Busy waiting for a short interval (500 millisecond ?) to see
1681 * if the callback processing completes may be another idea. Since
1682 * most of the callback processing involves a lot of work, it
1683 * is safe to just fail the SUSPEND operation. It is definitely
1684 * not bad to fail the SUSPEND operation if the driver is busy.
1687 while ((port
->fp_soft_state
& (FP_SOFT_IN_STATEC_CB
|
1688 FP_SOFT_IN_UNSOL_CB
)) && (delay_count
< 30)) {
1689 mutex_exit(&port
->fp_mutex
);
1692 mutex_enter(&port
->fp_mutex
);
1695 if (port
->fp_soft_state
& (FP_SOFT_IN_STATEC_CB
|
1696 FP_SOFT_IN_UNSOL_CB
)) {
1697 mutex_exit(&port
->fp_mutex
);
1698 cmn_err(CE_WARN
, "fp(%d): FCA callback in progress: "
1699 " Failing suspend", port
->fp_instance
);
1700 return (DDI_FAILURE
);
1704 * Check of FC port thread is busy
1706 if (port
->fp_job_head
) {
1707 mutex_exit(&port
->fp_mutex
);
1708 FP_TRACE(FP_NHEAD2(9, 0),
1709 "FC port thread is busy: Failing suspend");
1710 return (DDI_FAILURE
);
1712 port
->fp_soft_state
|= FP_SOFT_SUSPEND
;
1714 fp_suspend_all(port
);
1715 mutex_exit(&port
->fp_mutex
);
1717 return (DDI_SUCCESS
);
1722 * Prepare for graceful power down of a FC port
1725 fp_power_down(fc_local_port_t
*port
)
1727 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
1730 * Power down request followed by a DDI_SUSPEND should
1731 * never happen; If it does return DDI_SUCCESS
1733 if (port
->fp_soft_state
& FP_SOFT_SUSPEND
) {
1734 port
->fp_soft_state
|= FP_SOFT_POWER_DOWN
;
1735 return (DDI_SUCCESS
);
1739 * If the port is already power suspended, there
1740 * is nothing else to do, So return DDI_SUCCESS,
1742 if (port
->fp_soft_state
& FP_SOFT_POWER_DOWN
) {
1743 return (DDI_SUCCESS
);
1747 * Check if an unsolicited callback or state change handling
1748 * is in progress. If true, fail the PM suspend operation.
1749 * But don't print a message unless the verbosity of the
1750 * driver desires otherwise.
1752 if ((port
->fp_soft_state
& FP_SOFT_IN_STATEC_CB
) ||
1753 (port
->fp_soft_state
& FP_SOFT_IN_UNSOL_CB
)) {
1754 FP_TRACE(FP_NHEAD2(9, 0),
1755 "Unsolicited callback in progress: Failing power down");
1756 return (DDI_FAILURE
);
1760 * Check of FC port thread is busy
1762 if (port
->fp_job_head
) {
1763 FP_TRACE(FP_NHEAD2(9, 0),
1764 "FC port thread is busy: Failing power down");
1765 return (DDI_FAILURE
);
1767 port
->fp_soft_state
|= FP_SOFT_POWER_DOWN
;
1770 * check if the ULPs are ready for power down
1772 mutex_exit(&port
->fp_mutex
);
1773 if (fctl_detach_ulps(port
, FC_CMD_POWER_DOWN
,
1774 &modlinkage
) != FC_SUCCESS
) {
1775 mutex_enter(&port
->fp_mutex
);
1776 port
->fp_soft_state
&= ~FP_SOFT_POWER_DOWN
;
1777 mutex_exit(&port
->fp_mutex
);
1780 * Power back up the obedient ULPs that went down
1782 fp_attach_ulps(port
, FC_CMD_POWER_UP
);
1784 FP_TRACE(FP_NHEAD2(9, 0),
1785 "ULP(s) busy, detach_ulps failed. Failing power down");
1786 mutex_enter(&port
->fp_mutex
);
1787 return (DDI_FAILURE
);
1789 mutex_enter(&port
->fp_mutex
);
1791 fp_suspend_all(port
);
1793 return (DDI_SUCCESS
);
1798 * Suspend the entire FC port
1801 fp_suspend_all(fc_local_port_t
*port
)
1804 struct pwwn_hash
*head
;
1805 fc_remote_port_t
*pd
;
1807 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
1809 if (port
->fp_wait_tid
!= 0) {
1812 tid
= port
->fp_wait_tid
;
1813 port
->fp_wait_tid
= (timeout_id_t
)NULL
;
1814 mutex_exit(&port
->fp_mutex
);
1815 (void) untimeout(tid
);
1816 mutex_enter(&port
->fp_mutex
);
1817 port
->fp_restore
|= FP_RESTORE_WAIT_TIMEOUT
;
1820 if (port
->fp_offline_tid
) {
1823 tid
= port
->fp_offline_tid
;
1824 port
->fp_offline_tid
= (timeout_id_t
)NULL
;
1825 mutex_exit(&port
->fp_mutex
);
1826 (void) untimeout(tid
);
1827 mutex_enter(&port
->fp_mutex
);
1828 port
->fp_restore
|= FP_RESTORE_OFFLINE_TIMEOUT
;
1830 mutex_exit(&port
->fp_mutex
);
1831 port
->fp_fca_tran
->fca_unbind_port(port
->fp_fca_handle
);
1832 mutex_enter(&port
->fp_mutex
);
1835 * Mark all devices as OLD, and reset the LOGIN state as well
1836 * (this will force the ULPs to perform a LOGIN after calling
1837 * fc_portgetmap() during RESUME/PM_RESUME)
1839 for (index
= 0; index
< pwwn_table_size
; index
++) {
1840 head
= &port
->fp_pwwn_table
[index
];
1841 pd
= head
->pwwn_head
;
1842 while (pd
!= NULL
) {
1843 mutex_enter(&pd
->pd_mutex
);
1844 fp_remote_port_offline(pd
);
1845 fctl_delist_did_table(port
, pd
);
1846 pd
->pd_state
= PORT_DEVICE_VALID
;
1847 pd
->pd_login_count
= 0;
1848 mutex_exit(&pd
->pd_mutex
);
1849 pd
= pd
->pd_wwn_hnext
;
1856 * fp_cache_constructor: Constructor function for kmem_cache_create(9F).
1857 * Performs intializations for fc_packet_t structs.
1858 * Returns 0 for success or -1 for failure.
1860 * This function allocates DMA handles for both command and responses.
1861 * Most of the ELSs used have both command and responses so it is strongly
1862 * desired to move them to cache constructor routine.
1864 * Context: Can sleep iff called with KM_SLEEP flag.
1867 fp_cache_constructor(void *buf
, void *cdarg
, int kmflags
)
1869 int (*cb
) (caddr_t
);
1871 fp_cmd_t
*cmd
= (fp_cmd_t
*)buf
;
1872 fc_local_port_t
*port
= (fc_local_port_t
*)cdarg
;
1874 cb
= (kmflags
== KM_SLEEP
) ? DDI_DMA_SLEEP
: DDI_DMA_DONTWAIT
;
1876 cmd
->cmd_next
= NULL
;
1878 cmd
->cmd_dflags
= 0;
1879 cmd
->cmd_job
= NULL
;
1880 cmd
->cmd_port
= port
;
1881 pkt
= &cmd
->cmd_pkt
;
1883 if (!(port
->fp_soft_state
& FP_SOFT_FCA_IS_NODMA
)) {
1884 if (ddi_dma_alloc_handle(port
->fp_fca_dip
,
1885 port
->fp_fca_tran
->fca_dma_attr
, cb
, NULL
,
1886 &pkt
->pkt_cmd_dma
) != DDI_SUCCESS
) {
1890 if (ddi_dma_alloc_handle(port
->fp_fca_dip
,
1891 port
->fp_fca_tran
->fca_dma_attr
, cb
, NULL
,
1892 &pkt
->pkt_resp_dma
) != DDI_SUCCESS
) {
1893 ddi_dma_free_handle(&pkt
->pkt_cmd_dma
);
1897 pkt
->pkt_cmd_dma
= 0;
1898 pkt
->pkt_resp_dma
= 0;
1901 pkt
->pkt_cmd_acc
= pkt
->pkt_resp_acc
= NULL
;
1902 pkt
->pkt_cmd_cookie_cnt
= pkt
->pkt_resp_cookie_cnt
=
1903 pkt
->pkt_data_cookie_cnt
= 0;
1904 pkt
->pkt_cmd_cookie
= pkt
->pkt_resp_cookie
=
1905 pkt
->pkt_data_cookie
= NULL
;
1906 pkt
->pkt_fca_private
= (caddr_t
)buf
+ sizeof (fp_cmd_t
);
1913 * fp_cache_destructor: Destructor function for kmem_cache_create().
1914 * Performs un-intializations for fc_packet_t structs.
1918 fp_cache_destructor(void *buf
, void *cdarg
)
1920 fp_cmd_t
*cmd
= (fp_cmd_t
*)buf
;
1923 pkt
= &cmd
->cmd_pkt
;
1924 if (pkt
->pkt_cmd_dma
) {
1925 ddi_dma_free_handle(&pkt
->pkt_cmd_dma
);
1928 if (pkt
->pkt_resp_dma
) {
1929 ddi_dma_free_handle(&pkt
->pkt_resp_dma
);
1935 * Packet allocation for ELS and any other port driver commands
1937 * Some ELSs like FLOGI and PLOGI are critical for topology and
1938 * device discovery and a system's inability to allocate memory
1939 * or DVMA resources while performing some of these critical ELSs
1940 * cause a lot of problem. While memory allocation failures are
1941 * rare, DVMA resource failures are common as the applications
1942 * are becoming more and more powerful on huge servers. So it
1943 * is desirable to have a framework support to reserve a fragment
1944 * of DVMA. So until this is fixed the correct way, the suffering
1945 * is huge whenever a LIP happens at a time DVMA resources are
1946 * drained out completely - So an attempt needs to be made to
1947 * KM_SLEEP while requesting for these resources, hoping that
1948 * the requests won't hang forever.
1950 * The fc_remote_port_t argument is stored into the pkt_pd field in the
1951 * fc_packet_t struct prior to the fc_ulp_init_packet() call. This
1952 * ensures that the pd_ref_count for the fc_remote_port_t is valid.
1953 * If there is no fc_remote_port_t associated with the fc_packet_t, then
1954 * fp_alloc_pkt() must be called with pd set to NULL.
1956 * fp/fctl will resue fp_cmd_t somewhere, and change pkt_cmdlen/rsplen,
1957 * actually, it's a design fault. But there's no problem for physical
1958 * FCAs. But it will cause memory leak or panic for virtual FCAs like fcoei.
1960 * For FCAs that don't support DMA, such as fcoei, we will use
1961 * pkt_fctl_rsvd1/rsvd2 to keep the real cmd_len/resp_len.
1965 fp_alloc_pkt(fc_local_port_t
*port
, int cmd_len
, int resp_len
, int kmflags
,
1966 fc_remote_port_t
*pd
)
1972 int (*cb
) (caddr_t
);
1973 ddi_dma_cookie_t pkt_cookie
;
1974 ddi_dma_cookie_t
*cp
;
1977 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
1979 cb
= (kmflags
== KM_SLEEP
) ? DDI_DMA_SLEEP
: DDI_DMA_DONTWAIT
;
1981 cmd
= (fp_cmd_t
*)kmem_cache_alloc(port
->fp_pkt_cache
, kmflags
);
1986 cmd
->cmd_ulp_pkt
= NULL
;
1988 pkt
= &cmd
->cmd_pkt
;
1989 ASSERT(cmd
->cmd_dflags
== 0);
1991 pkt
->pkt_datalen
= 0;
1992 pkt
->pkt_data
= NULL
;
1994 pkt
->pkt_action
= 0;
1995 pkt
->pkt_reason
= 0;
1997 pkt
->pkt_cmd
= NULL
;
1998 pkt
->pkt_resp
= NULL
;
1999 pkt
->pkt_fctl_rsvd1
= NULL
;
2000 pkt
->pkt_fctl_rsvd2
= NULL
;
2003 * Init pkt_pd with the given pointer; this must be done _before_
2004 * the call to fc_ulp_init_packet().
2008 /* Now call the FCA driver to init its private, per-packet fields */
2009 if (fc_ulp_init_packet((opaque_t
)port
, pkt
, kmflags
) != FC_SUCCESS
) {
2010 goto alloc_pkt_failed
;
2013 if (cmd_len
&& !(port
->fp_soft_state
& FP_SOFT_FCA_IS_NODMA
)) {
2014 ASSERT(pkt
->pkt_cmd_dma
!= NULL
);
2016 rval
= ddi_dma_mem_alloc(pkt
->pkt_cmd_dma
, cmd_len
,
2017 port
->fp_fca_tran
->fca_acc_attr
, DDI_DMA_CONSISTENT
,
2018 cb
, NULL
, (caddr_t
*)&pkt
->pkt_cmd
, &real_len
,
2021 if (rval
!= DDI_SUCCESS
) {
2022 goto alloc_pkt_failed
;
2024 cmd
->cmd_dflags
|= FP_CMD_VALID_DMA_MEM
;
2026 if (real_len
< cmd_len
) {
2027 goto alloc_pkt_failed
;
2030 rval
= ddi_dma_addr_bind_handle(pkt
->pkt_cmd_dma
, NULL
,
2031 pkt
->pkt_cmd
, real_len
, DDI_DMA_WRITE
|
2032 DDI_DMA_CONSISTENT
, cb
, NULL
,
2033 &pkt_cookie
, &pkt
->pkt_cmd_cookie_cnt
);
2035 if (rval
!= DDI_DMA_MAPPED
) {
2036 goto alloc_pkt_failed
;
2039 cmd
->cmd_dflags
|= FP_CMD_VALID_DMA_BIND
;
2041 if (pkt
->pkt_cmd_cookie_cnt
>
2042 port
->fp_fca_tran
->fca_dma_attr
->dma_attr_sgllen
) {
2043 goto alloc_pkt_failed
;
2046 ASSERT(pkt
->pkt_cmd_cookie_cnt
!= 0);
2048 cp
= pkt
->pkt_cmd_cookie
= (ddi_dma_cookie_t
*)kmem_alloc(
2049 pkt
->pkt_cmd_cookie_cnt
* sizeof (pkt_cookie
),
2053 goto alloc_pkt_failed
;
2058 for (cnt
= 1; cnt
< pkt
->pkt_cmd_cookie_cnt
; cnt
++, cp
++) {
2059 ddi_dma_nextcookie(pkt
->pkt_cmd_dma
, &pkt_cookie
);
2062 } else if (cmd_len
!= 0) {
2063 pkt
->pkt_cmd
= kmem_alloc(cmd_len
, KM_SLEEP
);
2064 pkt
->pkt_fctl_rsvd1
= (opaque_t
)(uintptr_t)cmd_len
;
2067 if (resp_len
&& !(port
->fp_soft_state
& FP_SOFT_FCA_IS_NODMA
)) {
2068 ASSERT(pkt
->pkt_resp_dma
!= NULL
);
2070 rval
= ddi_dma_mem_alloc(pkt
->pkt_resp_dma
, resp_len
,
2071 port
->fp_fca_tran
->fca_acc_attr
,
2072 DDI_DMA_CONSISTENT
, cb
, NULL
,
2073 (caddr_t
*)&pkt
->pkt_resp
, &real_len
,
2074 &pkt
->pkt_resp_acc
);
2076 if (rval
!= DDI_SUCCESS
) {
2077 goto alloc_pkt_failed
;
2079 cmd
->cmd_dflags
|= FP_RESP_VALID_DMA_MEM
;
2081 if (real_len
< resp_len
) {
2082 goto alloc_pkt_failed
;
2085 rval
= ddi_dma_addr_bind_handle(pkt
->pkt_resp_dma
, NULL
,
2086 pkt
->pkt_resp
, real_len
, DDI_DMA_READ
|
2087 DDI_DMA_CONSISTENT
, cb
, NULL
,
2088 &pkt_cookie
, &pkt
->pkt_resp_cookie_cnt
);
2090 if (rval
!= DDI_DMA_MAPPED
) {
2091 goto alloc_pkt_failed
;
2094 cmd
->cmd_dflags
|= FP_RESP_VALID_DMA_BIND
;
2096 if (pkt
->pkt_resp_cookie_cnt
>
2097 port
->fp_fca_tran
->fca_dma_attr
->dma_attr_sgllen
) {
2098 goto alloc_pkt_failed
;
2101 ASSERT(pkt
->pkt_cmd_cookie_cnt
!= 0);
2103 cp
= pkt
->pkt_resp_cookie
= (ddi_dma_cookie_t
*)kmem_alloc(
2104 pkt
->pkt_resp_cookie_cnt
* sizeof (pkt_cookie
),
2108 goto alloc_pkt_failed
;
2113 for (cnt
= 1; cnt
< pkt
->pkt_resp_cookie_cnt
; cnt
++, cp
++) {
2114 ddi_dma_nextcookie(pkt
->pkt_resp_dma
, &pkt_cookie
);
2117 } else if (resp_len
!= 0) {
2118 pkt
->pkt_resp
= kmem_alloc(resp_len
, KM_SLEEP
);
2119 pkt
->pkt_fctl_rsvd2
= (opaque_t
)(uintptr_t)resp_len
;
2122 pkt
->pkt_cmdlen
= cmd_len
;
2123 pkt
->pkt_rsplen
= resp_len
;
2124 pkt
->pkt_ulp_private
= cmd
;
2132 if (pkt
->pkt_cmd_cookie
!= NULL
) {
2133 kmem_free(pkt
->pkt_cmd_cookie
,
2134 pkt
->pkt_cmd_cookie_cnt
* sizeof (ddi_dma_cookie_t
));
2135 pkt
->pkt_cmd_cookie
= NULL
;
2138 if (pkt
->pkt_resp_cookie
!= NULL
) {
2139 kmem_free(pkt
->pkt_resp_cookie
,
2140 pkt
->pkt_resp_cookie_cnt
* sizeof (ddi_dma_cookie_t
));
2141 pkt
->pkt_resp_cookie
= NULL
;
2144 if (port
->fp_soft_state
& FP_SOFT_FCA_IS_NODMA
) {
2146 kmem_free(pkt
->pkt_cmd
, cmd_len
);
2149 if (pkt
->pkt_resp
) {
2150 kmem_free(pkt
->pkt_resp
, resp_len
);
2154 kmem_cache_free(port
->fp_pkt_cache
, cmd
);
2164 fp_free_pkt(fp_cmd_t
*cmd
)
2166 fc_local_port_t
*port
;
2169 ASSERT(!MUTEX_HELD(&cmd
->cmd_port
->fp_mutex
));
2171 cmd
->cmd_next
= NULL
;
2172 cmd
->cmd_job
= NULL
;
2173 pkt
= &cmd
->cmd_pkt
;
2174 pkt
->pkt_ulp_private
= 0;
2175 pkt
->pkt_tran_flags
= 0;
2176 pkt
->pkt_tran_type
= 0;
2177 port
= cmd
->cmd_port
;
2179 if (pkt
->pkt_cmd_cookie
!= NULL
) {
2180 kmem_free(pkt
->pkt_cmd_cookie
, pkt
->pkt_cmd_cookie_cnt
*
2181 sizeof (ddi_dma_cookie_t
));
2182 pkt
->pkt_cmd_cookie
= NULL
;
2185 if (pkt
->pkt_resp_cookie
!= NULL
) {
2186 kmem_free(pkt
->pkt_resp_cookie
, pkt
->pkt_resp_cookie_cnt
*
2187 sizeof (ddi_dma_cookie_t
));
2188 pkt
->pkt_resp_cookie
= NULL
;
2191 if (port
->fp_soft_state
& FP_SOFT_FCA_IS_NODMA
) {
2193 kmem_free(pkt
->pkt_cmd
,
2194 (uint32_t)(uintptr_t)pkt
->pkt_fctl_rsvd1
);
2197 if (pkt
->pkt_resp
) {
2198 kmem_free(pkt
->pkt_resp
,
2199 (uint32_t)(uintptr_t)pkt
->pkt_fctl_rsvd2
);
2204 (void) fc_ulp_uninit_packet((opaque_t
)port
, pkt
);
2205 kmem_cache_free(port
->fp_pkt_cache
, (void *)cmd
);
2210 * Release DVMA resources
2213 fp_free_dma(fp_cmd_t
*cmd
)
2215 fc_packet_t
*pkt
= &cmd
->cmd_pkt
;
2217 pkt
->pkt_cmdlen
= 0;
2218 pkt
->pkt_rsplen
= 0;
2219 pkt
->pkt_tran_type
= 0;
2220 pkt
->pkt_tran_flags
= 0;
2222 if (cmd
->cmd_dflags
& FP_CMD_VALID_DMA_BIND
) {
2223 (void) ddi_dma_unbind_handle(pkt
->pkt_cmd_dma
);
2226 if (cmd
->cmd_dflags
& FP_CMD_VALID_DMA_MEM
) {
2227 if (pkt
->pkt_cmd_acc
) {
2228 ddi_dma_mem_free(&pkt
->pkt_cmd_acc
);
2232 if (cmd
->cmd_dflags
& FP_RESP_VALID_DMA_BIND
) {
2233 (void) ddi_dma_unbind_handle(pkt
->pkt_resp_dma
);
2236 if (cmd
->cmd_dflags
& FP_RESP_VALID_DMA_MEM
) {
2237 if (pkt
->pkt_resp_acc
) {
2238 ddi_dma_mem_free(&pkt
->pkt_resp_acc
);
2241 cmd
->cmd_dflags
= 0;
2246 * Dedicated thread to perform various activities. One thread for
2247 * each fc_local_port_t (driver soft state) instance.
2248 * Note, this effectively works out to one thread for each local
2249 * port, but there are also some Solaris taskq threads in use on a per-local
2250 * port basis; these also need to be taken into consideration.
2253 fp_job_handler(fc_local_port_t
*port
)
2257 fc_remote_port_t
*pd
;
2262 * Solaris-internal stuff for proper operation of kernel threads
2265 CALLB_CPR_INIT(&port
->fp_cpr_info
, &port
->fp_mutex
,
2266 callb_generic_cpr
, "fp_job_handler");
2270 /* Loop forever waiting for work to do */
2273 mutex_enter(&port
->fp_mutex
);
2276 * Sleep if no work to do right now, or if we want
2277 * to suspend or power-down.
2279 while (port
->fp_job_head
== NULL
||
2280 (port
->fp_soft_state
& (FP_SOFT_POWER_DOWN
|
2281 FP_SOFT_SUSPEND
))) {
2282 CALLB_CPR_SAFE_BEGIN(&port
->fp_cpr_info
);
2283 cv_wait(&port
->fp_cv
, &port
->fp_mutex
);
2284 CALLB_CPR_SAFE_END(&port
->fp_cpr_info
, &port
->fp_mutex
);
2288 * OK, we've just been woken up, so retrieve the next entry
2289 * from the head of the job queue for this local port.
2291 job
= fctl_deque_job(port
);
2294 * Handle all the fp driver's supported job codes here
2295 * in this big honkin' switch.
2297 switch (job
->job_code
) {
2298 case JOB_PORT_SHUTDOWN
:
2300 * fp_port_shutdown() is only called from here. This
2301 * will prepare the local port instance (softstate)
2302 * for detaching. This cancels timeout callbacks,
2303 * executes LOGOs with remote ports, cleans up tables,
2304 * and deallocates data structs.
2306 fp_port_shutdown(port
, job
);
2309 * This will exit the job thread.
2312 CALLB_CPR_EXIT(&(port
->fp_cpr_info
));
2314 mutex_exit(&port
->fp_mutex
);
2321 case JOB_ATTACH_ULP
: {
2323 * This job is spawned in response to a ULP calling
2327 boolean_t do_attach_ulps
= B_TRUE
;
2330 * If fp is detaching, we don't want to call
2331 * fp_startup_done as this asynchronous
2332 * notification may interfere with the re-attach.
2335 if (port
->fp_soft_state
& (FP_DETACH_INPROGRESS
|
2336 FP_SOFT_IN_DETACH
| FP_DETACH_FAILED
)) {
2337 do_attach_ulps
= B_FALSE
;
2340 * We are going to force the transport
2341 * to attach to the ULPs, so set
2342 * fp_ulp_attach. This will keep any
2343 * potential detach from occurring until
2346 port
->fp_ulp_attach
= 1;
2349 mutex_exit(&port
->fp_mutex
);
2352 * NOTE: Since we just dropped the mutex, there is now
2353 * a race window where the fp_soft_state check above
2354 * could change here. This race is covered because an
2355 * additional check was added in the functions hidden
2356 * under fp_startup_done().
2358 if (do_attach_ulps
== B_TRUE
) {
2360 * This goes thru a bit of a convoluted call
2361 * chain before spawning off a DDI taskq
2362 * request to perform the actual attach
2363 * operations. Blocking can occur at a number
2366 fp_startup_done((opaque_t
)port
, FC_PKT_SUCCESS
);
2368 job
->job_result
= FC_SUCCESS
;
2373 case JOB_ULP_NOTIFY
: {
2375 * Pass state change notifications up to any/all
2380 statec
= job
->job_ulp_listlen
;
2381 if (statec
== FC_STATE_RESET_REQUESTED
) {
2382 port
->fp_last_task
= port
->fp_task
;
2383 port
->fp_task
= FP_TASK_OFFLINE
;
2384 fp_port_offline(port
, 0);
2385 port
->fp_task
= port
->fp_last_task
;
2386 port
->fp_last_task
= FP_TASK_IDLE
;
2389 if (--port
->fp_statec_busy
== 0) {
2390 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
2393 mutex_exit(&port
->fp_mutex
);
2395 job
->job_result
= fp_ulp_notify(port
, statec
, KM_SLEEP
);
2402 * Issue a PLOGI to a single remote port. Multiple
2403 * PLOGIs to different remote ports may occur in
2405 * This can create the fc_remote_port_t if it does not
2409 mutex_exit(&port
->fp_mutex
);
2410 d_id
= (uint32_t *)job
->job_private
;
2411 pd
= fctl_get_remote_port_by_did(port
, *d_id
);
2414 mutex_enter(&pd
->pd_mutex
);
2415 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
2416 pd
->pd_login_count
++;
2417 mutex_exit(&pd
->pd_mutex
);
2418 job
->job_result
= FC_SUCCESS
;
2422 mutex_exit(&pd
->pd_mutex
);
2424 mutex_enter(&port
->fp_mutex
);
2425 if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
2426 mutex_exit(&port
->fp_mutex
);
2427 pd
= fp_create_remote_port_by_ns(port
,
2430 job
->job_result
= FC_FAILURE
;
2435 mutex_exit(&port
->fp_mutex
);
2439 job
->job_flags
|= JOB_TYPE_FP_ASYNC
;
2440 job
->job_counter
= 1;
2442 rval
= fp_port_login(port
, *d_id
, job
,
2443 FP_CMD_PLOGI_RETAIN
, KM_SLEEP
, pd
, NULL
);
2445 if (rval
!= FC_SUCCESS
) {
2446 job
->job_result
= rval
;
2451 case JOB_LOGO_ONE
: {
2453 * Issue a PLOGO to a single remote port. Multiple
2454 * PLOGOs to different remote ports may occur in
2457 fc_remote_port_t
*pd
;
2460 ASSERT(job
->job_counter
> 0);
2463 pd
= (fc_remote_port_t
*)job
->job_ulp_pkts
;
2465 mutex_enter(&pd
->pd_mutex
);
2466 if (pd
->pd_state
!= PORT_DEVICE_LOGGED_IN
) {
2467 mutex_exit(&pd
->pd_mutex
);
2468 job
->job_result
= FC_LOGINREQ
;
2469 mutex_exit(&port
->fp_mutex
);
2473 if (pd
->pd_login_count
> 1) {
2474 pd
->pd_login_count
--;
2475 mutex_exit(&pd
->pd_mutex
);
2476 job
->job_result
= FC_SUCCESS
;
2477 mutex_exit(&port
->fp_mutex
);
2481 mutex_exit(&pd
->pd_mutex
);
2482 mutex_exit(&port
->fp_mutex
);
2483 job
->job_flags
|= JOB_TYPE_FP_ASYNC
;
2484 (void) fp_logout(port
, pd
, job
);
2488 case JOB_FCIO_LOGIN
:
2490 * PLOGI initiated at ioctl request.
2492 mutex_exit(&port
->fp_mutex
);
2494 fp_fcio_login(port
, job
->job_private
, job
);
2498 case JOB_FCIO_LOGOUT
:
2500 * PLOGO initiated at ioctl request.
2502 mutex_exit(&port
->fp_mutex
);
2504 fp_fcio_logout(port
, job
->job_private
, job
);
2508 case JOB_PORT_GETMAP
:
2509 case JOB_PORT_GETMAP_PLOGI_ALL
: {
2510 port
->fp_last_task
= port
->fp_task
;
2511 port
->fp_task
= FP_TASK_GETMAP
;
2513 switch (port
->fp_topology
) {
2514 case FC_TOP_PRIVATE_LOOP
:
2515 job
->job_counter
= 1;
2517 fp_get_loopmap(port
, job
);
2518 mutex_exit(&port
->fp_mutex
);
2520 fctl_fillout_map(port
,
2521 (fc_portmap_t
**)job
->job_private
,
2522 (uint32_t *)job
->job_arg
, 1, 0, 0);
2524 mutex_enter(&port
->fp_mutex
);
2527 case FC_TOP_PUBLIC_LOOP
:
2529 mutex_exit(&port
->fp_mutex
);
2530 job
->job_counter
= 1;
2532 job
->job_result
= fp_ns_getmap(port
,
2533 job
, (fc_portmap_t
**)job
->job_private
,
2534 (uint32_t *)job
->job_arg
,
2537 mutex_enter(&port
->fp_mutex
);
2541 mutex_exit(&port
->fp_mutex
);
2542 fctl_fillout_map(port
,
2543 (fc_portmap_t
**)job
->job_private
,
2544 (uint32_t *)job
->job_arg
, 1, 0, 0);
2546 mutex_enter(&port
->fp_mutex
);
2550 mutex_exit(&port
->fp_mutex
);
2552 mutex_enter(&port
->fp_mutex
);
2555 port
->fp_task
= port
->fp_last_task
;
2556 port
->fp_last_task
= FP_TASK_IDLE
;
2557 mutex_exit(&port
->fp_mutex
);
2561 case JOB_PORT_OFFLINE
: {
2562 fp_log_port_event(port
, ESC_SUNFC_PORT_OFFLINE
);
2564 port
->fp_last_task
= port
->fp_task
;
2565 port
->fp_task
= FP_TASK_OFFLINE
;
2567 if (port
->fp_statec_busy
> 2) {
2568 job
->job_flags
|= JOB_CANCEL_ULP_NOTIFICATION
;
2569 fp_port_offline(port
, 0);
2570 if (--port
->fp_statec_busy
== 0) {
2571 port
->fp_soft_state
&=
2572 ~FP_SOFT_IN_STATEC_CB
;
2575 fp_port_offline(port
, 1);
2578 port
->fp_task
= port
->fp_last_task
;
2579 port
->fp_last_task
= FP_TASK_IDLE
;
2581 mutex_exit(&port
->fp_mutex
);
2587 case JOB_PORT_STARTUP
: {
2588 if ((rval
= fp_port_startup(port
, job
)) != FC_SUCCESS
) {
2589 if (port
->fp_statec_busy
> 1) {
2590 mutex_exit(&port
->fp_mutex
);
2593 mutex_exit(&port
->fp_mutex
);
2595 FP_TRACE(FP_NHEAD2(9, rval
),
2596 "Topology discovery failed");
2601 * Attempt building device handles in case
2604 if (port
->fp_topology
== FC_TOP_PRIVATE_LOOP
) {
2605 job
->job_counter
= 1;
2607 fp_get_loopmap(port
, job
);
2608 mutex_exit(&port
->fp_mutex
);
2610 mutex_enter(&port
->fp_mutex
);
2611 if (port
->fp_lilp_map
.lilp_magic
< MAGIC_LIRP
) {
2612 ASSERT(port
->fp_total_devices
== 0);
2613 port
->fp_total_devices
=
2616 } else if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
2618 * Hack to avoid state changes going up early
2620 port
->fp_statec_busy
++;
2621 port
->fp_soft_state
|= FP_SOFT_IN_STATEC_CB
;
2623 job
->job_flags
|= JOB_CANCEL_ULP_NOTIFICATION
;
2624 fp_fabric_online(port
, job
);
2625 job
->job_flags
&= ~JOB_CANCEL_ULP_NOTIFICATION
;
2627 mutex_exit(&port
->fp_mutex
);
2632 case JOB_PORT_ONLINE
: {
2637 fp_log_port_event(port
, ESC_SUNFC_PORT_ONLINE
);
2640 * Bail out early if there are a lot of
2641 * state changes in the pipeline
2643 if (port
->fp_statec_busy
> 1) {
2644 --port
->fp_statec_busy
;
2645 mutex_exit(&port
->fp_mutex
);
2650 switch (old_top
= port
->fp_topology
) {
2651 case FC_TOP_PRIVATE_LOOP
:
2652 oldtop
= "Private Loop";
2655 case FC_TOP_PUBLIC_LOOP
:
2656 oldtop
= "Public Loop";
2660 oldtop
= "Point to Point";
2672 port
->fp_last_task
= port
->fp_task
;
2673 port
->fp_task
= FP_TASK_ONLINE
;
2675 if ((rval
= fp_port_startup(port
, job
)) != FC_SUCCESS
) {
2677 port
->fp_task
= port
->fp_last_task
;
2678 port
->fp_last_task
= FP_TASK_IDLE
;
2680 if (port
->fp_statec_busy
> 1) {
2681 --port
->fp_statec_busy
;
2682 mutex_exit(&port
->fp_mutex
);
2686 port
->fp_state
= FC_STATE_OFFLINE
;
2688 FP_TRACE(FP_NHEAD2(9, rval
),
2689 "Topology discovery failed");
2691 if (--port
->fp_statec_busy
== 0) {
2692 port
->fp_soft_state
&=
2693 ~FP_SOFT_IN_STATEC_CB
;
2696 if (port
->fp_offline_tid
== NULL
) {
2697 port
->fp_offline_tid
=
2698 timeout(fp_offline_timeout
,
2699 (caddr_t
)port
, fp_offline_ticks
);
2702 mutex_exit(&port
->fp_mutex
);
2706 switch (port
->fp_topology
) {
2707 case FC_TOP_PRIVATE_LOOP
:
2708 newtop
= "Private Loop";
2711 case FC_TOP_PUBLIC_LOOP
:
2712 newtop
= "Public Loop";
2716 newtop
= "Point to Point";
2728 if (oldtop
&& newtop
&& strcmp(oldtop
, newtop
)) {
2729 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
2730 "Change in FC Topology old = %s new = %s",
2734 switch (port
->fp_topology
) {
2735 case FC_TOP_PRIVATE_LOOP
: {
2736 int orphan
= (old_top
== FC_TOP_FABRIC
||
2737 old_top
== FC_TOP_PUBLIC_LOOP
) ? 1 : 0;
2739 mutex_exit(&port
->fp_mutex
);
2740 fp_loop_online(port
, job
, orphan
);
2744 case FC_TOP_PUBLIC_LOOP
:
2747 fp_fabric_online(port
, job
);
2748 mutex_exit(&port
->fp_mutex
);
2752 fp_p2p_online(port
, job
);
2753 mutex_exit(&port
->fp_mutex
);
2757 if (--port
->fp_statec_busy
!= 0) {
2759 * Watch curiously at what the next
2760 * state transition can do.
2762 mutex_exit(&port
->fp_mutex
);
2766 FP_TRACE(FP_NHEAD2(9, 0),
2767 "Topology Unknown, Offlining the port..");
2769 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
2770 port
->fp_state
= FC_STATE_OFFLINE
;
2772 if (port
->fp_offline_tid
== NULL
) {
2773 port
->fp_offline_tid
=
2774 timeout(fp_offline_timeout
,
2775 (caddr_t
)port
, fp_offline_ticks
);
2777 mutex_exit(&port
->fp_mutex
);
2781 mutex_enter(&port
->fp_mutex
);
2783 port
->fp_task
= port
->fp_last_task
;
2784 port
->fp_last_task
= FP_TASK_IDLE
;
2786 mutex_exit(&port
->fp_mutex
);
2792 case JOB_PLOGI_GROUP
: {
2793 mutex_exit(&port
->fp_mutex
);
2794 fp_plogi_group(port
, job
);
2798 case JOB_UNSOL_REQUEST
: {
2799 mutex_exit(&port
->fp_mutex
);
2800 fp_handle_unsol_buf(port
,
2801 (fc_unsol_buf_t
*)job
->job_private
, job
);
2802 fctl_dealloc_job(job
);
2807 fctl_ns_req_t
*ns_cmd
;
2809 mutex_exit(&port
->fp_mutex
);
2811 job
->job_flags
|= JOB_TYPE_FP_ASYNC
;
2812 ns_cmd
= (fctl_ns_req_t
*)job
->job_private
;
2813 if (ns_cmd
->ns_cmd_code
< NS_GA_NXT
||
2814 ns_cmd
->ns_cmd_code
> NS_DA_ID
) {
2815 job
->job_result
= FC_BADCMD
;
2820 if (FC_IS_CMD_A_REG(ns_cmd
->ns_cmd_code
)) {
2821 if (ns_cmd
->ns_pd
!= NULL
) {
2822 job
->job_result
= FC_BADOBJECT
;
2827 job
->job_counter
= 1;
2829 rval
= fp_ns_reg(port
, ns_cmd
->ns_pd
,
2830 ns_cmd
->ns_cmd_code
, job
, 0, KM_SLEEP
);
2832 if (rval
!= FC_SUCCESS
) {
2833 job
->job_result
= rval
;
2838 job
->job_result
= FC_SUCCESS
;
2839 job
->job_counter
= 1;
2841 rval
= fp_ns_query(port
, ns_cmd
, job
, 0, KM_SLEEP
);
2842 if (rval
!= FC_SUCCESS
) {
2848 case JOB_LINK_RESET
: {
2852 pwwn
= (la_wwn_t
*)job
->job_private
;
2853 ASSERT(pwwn
!= NULL
);
2855 topology
= port
->fp_topology
;
2856 mutex_exit(&port
->fp_mutex
);
2858 if (fctl_is_wwn_zero(pwwn
) == FC_SUCCESS
||
2859 topology
== FC_TOP_PRIVATE_LOOP
) {
2860 job
->job_flags
|= JOB_TYPE_FP_ASYNC
;
2861 rval
= port
->fp_fca_tran
->fca_reset(
2862 port
->fp_fca_handle
, FC_FCA_LINK_RESET
);
2863 job
->job_result
= rval
;
2866 ASSERT((job
->job_flags
&
2867 JOB_TYPE_FP_ASYNC
) == 0);
2869 if (FC_IS_TOP_SWITCH(topology
)) {
2870 rval
= fp_remote_lip(port
, pwwn
,
2875 if (rval
!= FC_SUCCESS
) {
2876 job
->job_result
= rval
;
2884 mutex_exit(&port
->fp_mutex
);
2885 job
->job_result
= FC_BADCMD
;
2895 * Perform FC port bring up initialization
2898 fp_port_startup(fc_local_port_t
*port
, job_request_t
*job
)
2903 fc_lilpmap_t
*lilp_map
;
2905 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
2906 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
2908 FP_DTRACE(FP_NHEAD1(2, 0), "Entering fp_port_startup;"
2909 " port=%p, job=%p", port
, job
);
2911 port
->fp_topology
= FC_TOP_UNKNOWN
;
2912 port
->fp_port_id
.port_id
= 0;
2913 state
= FC_PORT_STATE_MASK(port
->fp_state
);
2915 if (state
== FC_STATE_OFFLINE
) {
2916 port
->fp_port_type
.port_type
= FC_NS_PORT_UNKNOWN
;
2917 job
->job_result
= FC_OFFLINE
;
2918 mutex_exit(&port
->fp_mutex
);
2920 mutex_enter(&port
->fp_mutex
);
2921 return (FC_OFFLINE
);
2924 if (state
== FC_STATE_LOOP
) {
2925 port
->fp_port_type
.port_type
= FC_NS_PORT_NL
;
2926 mutex_exit(&port
->fp_mutex
);
2928 lilp_map
= &port
->fp_lilp_map
;
2929 if ((rval
= fp_get_lilpmap(port
, lilp_map
)) != FC_SUCCESS
) {
2930 job
->job_result
= FC_FAILURE
;
2933 FP_TRACE(FP_NHEAD1(9, rval
),
2934 "LILP map Invalid or not present");
2935 mutex_enter(&port
->fp_mutex
);
2936 return (FC_FAILURE
);
2939 if (lilp_map
->lilp_length
== 0) {
2940 job
->job_result
= FC_NO_MAP
;
2942 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
2943 "LILP map length zero");
2944 mutex_enter(&port
->fp_mutex
);
2947 src_id
= lilp_map
->lilp_myalpa
& 0xFF;
2949 fc_remote_port_t
*pd
;
2951 fc_fca_p2p_info_t p2p_info
;
2955 * Get P2P remote port info if possible
2957 bzero((caddr_t
)&pm
, sizeof (pm
));
2959 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
2960 pm
.pm_cmd_code
= FC_PORT_GET_P2P_INFO
;
2961 pm
.pm_data_len
= sizeof (fc_fca_p2p_info_t
);
2962 pm
.pm_data_buf
= (caddr_t
)&p2p_info
;
2964 rval
= port
->fp_fca_tran
->fca_port_manage(
2965 port
->fp_fca_handle
, &pm
);
2967 if (rval
== FC_SUCCESS
) {
2968 port
->fp_port_id
.port_id
= p2p_info
.fca_d_id
;
2969 port
->fp_port_type
.port_type
= FC_NS_PORT_N
;
2970 port
->fp_topology
= FC_TOP_PT_PT
;
2971 port
->fp_total_devices
= 1;
2972 pd_recepient
= fctl_wwn_cmp(
2973 &port
->fp_service_params
.nport_ww_name
,
2974 &p2p_info
.pwwn
) < 0 ?
2975 PD_PLOGI_RECEPIENT
: PD_PLOGI_INITIATOR
;
2976 mutex_exit(&port
->fp_mutex
);
2977 pd
= fctl_create_remote_port(port
,
2981 pd_recepient
, KM_NOSLEEP
);
2982 FP_DTRACE(FP_NHEAD1(2, 0), "Exiting fp_port_startup;"
2983 " P2P port=%p pd=%p fp %x pd %x", port
, pd
,
2984 port
->fp_port_id
.port_id
, p2p_info
.d_id
);
2985 mutex_enter(&port
->fp_mutex
);
2986 return (FC_SUCCESS
);
2988 port
->fp_port_type
.port_type
= FC_NS_PORT_N
;
2989 mutex_exit(&port
->fp_mutex
);
2993 job
->job_counter
= 1;
2994 job
->job_result
= FC_SUCCESS
;
2996 if ((rval
= fp_fabric_login(port
, src_id
, job
, FP_CMD_PLOGI_DONT_CARE
,
2997 KM_SLEEP
)) != FC_SUCCESS
) {
2998 port
->fp_port_type
.port_type
= FC_NS_PORT_UNKNOWN
;
2999 job
->job_result
= FC_FAILURE
;
3002 mutex_enter(&port
->fp_mutex
);
3003 if (port
->fp_statec_busy
<= 1) {
3004 mutex_exit(&port
->fp_mutex
);
3005 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, rval
, NULL
,
3006 "Couldn't transport FLOGI");
3007 mutex_enter(&port
->fp_mutex
);
3009 return (FC_FAILURE
);
3014 mutex_enter(&port
->fp_mutex
);
3015 if (job
->job_result
== FC_SUCCESS
) {
3016 if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
3017 mutex_exit(&port
->fp_mutex
);
3018 fp_ns_init(port
, job
, KM_SLEEP
);
3019 mutex_enter(&port
->fp_mutex
);
3022 if (state
== FC_STATE_LOOP
) {
3023 port
->fp_topology
= FC_TOP_PRIVATE_LOOP
;
3024 port
->fp_port_id
.port_id
=
3025 port
->fp_lilp_map
.lilp_myalpa
& 0xFF;
3029 FP_DTRACE(FP_NHEAD1(2, 0), "Exiting fp_port_startup; port=%p, job=%p",
3032 return (FC_SUCCESS
);
3037 * Perform ULP invocations following FC port startup
3041 fp_startup_done(opaque_t arg
, uchar_t result
)
3043 fc_local_port_t
*port
= arg
;
3045 fp_attach_ulps(port
, FC_CMD_ATTACH
);
3047 FP_DTRACE(FP_NHEAD1(2, 0), "fp_startup almost complete; port=%p", port
);
3052 * Perform ULP port attach
3055 fp_ulp_port_attach(void *arg
)
3057 fp_soft_attach_t
*att
= (fp_soft_attach_t
*)arg
;
3058 fc_local_port_t
*port
= att
->att_port
;
3060 FP_DTRACE(FP_NHEAD1(1, 0), "port attach of"
3061 " ULPs begin; port=%p, cmd=%x", port
, att
->att_cmd
);
3063 fctl_attach_ulps(att
->att_port
, att
->att_cmd
, &modlinkage
);
3065 if (att
->att_need_pm_idle
== B_TRUE
) {
3066 fctl_idle_port(port
);
3069 FP_DTRACE(FP_NHEAD1(1, 0), "port attach of"
3070 " ULPs end; port=%p, cmd=%x", port
, att
->att_cmd
);
3072 mutex_enter(&att
->att_port
->fp_mutex
);
3073 att
->att_port
->fp_ulp_attach
= 0;
3075 port
->fp_task
= port
->fp_last_task
;
3076 port
->fp_last_task
= FP_TASK_IDLE
;
3078 cv_signal(&att
->att_port
->fp_attach_cv
);
3080 mutex_exit(&att
->att_port
->fp_mutex
);
3082 kmem_free(att
, sizeof (fp_soft_attach_t
));
3086 * Entry point to funnel all requests down to FCAs
3089 fp_sendcmd(fc_local_port_t
*port
, fp_cmd_t
*cmd
, opaque_t fca_handle
)
3093 mutex_enter(&port
->fp_mutex
);
3094 if (port
->fp_statec_busy
> 1 || (cmd
->cmd_ulp_pkt
!= NULL
&&
3095 (port
->fp_statec_busy
|| FC_PORT_STATE_MASK(port
->fp_state
) ==
3096 FC_STATE_OFFLINE
))) {
3098 * This means there is more than one state change
3099 * at this point of time - Since they are processed
3100 * serially, any processing of the current one should
3101 * be failed, failed and move up in processing the next
3103 cmd
->cmd_pkt
.pkt_state
= FC_PKT_ELS_IN_PROGRESS
;
3104 cmd
->cmd_pkt
.pkt_reason
= FC_REASON_OFFLINE
;
3107 * A state change that is going to be invalidated
3108 * by another one already in the port driver's queue
3109 * need not go up to all ULPs. This will minimize
3110 * needless processing and ripples in ULP modules
3112 cmd
->cmd_job
->job_flags
|= JOB_CANCEL_ULP_NOTIFICATION
;
3114 mutex_exit(&port
->fp_mutex
);
3115 return (FC_STATEC_BUSY
);
3118 if (FC_PORT_STATE_MASK(port
->fp_state
) == FC_STATE_OFFLINE
) {
3119 cmd
->cmd_pkt
.pkt_state
= FC_PKT_PORT_OFFLINE
;
3120 cmd
->cmd_pkt
.pkt_reason
= FC_REASON_OFFLINE
;
3121 mutex_exit(&port
->fp_mutex
);
3123 return (FC_OFFLINE
);
3125 mutex_exit(&port
->fp_mutex
);
3127 rval
= cmd
->cmd_transport(fca_handle
, &cmd
->cmd_pkt
);
3128 if (rval
!= FC_SUCCESS
) {
3129 if (rval
== FC_TRAN_BUSY
) {
3130 cmd
->cmd_retry_interval
= fp_retry_delay
;
3131 rval
= fp_retry_cmd(&cmd
->cmd_pkt
);
3132 if (rval
== FC_FAILURE
) {
3133 cmd
->cmd_pkt
.pkt_state
= FC_PKT_TRAN_BSY
;
3137 mutex_enter(&port
->fp_mutex
);
3138 port
->fp_out_fpcmds
++;
3139 mutex_exit(&port
->fp_mutex
);
3147 * Each time a timeout kicks in, walk the wait queue, decrement the
3148 * the retry_interval, when the retry_interval becomes less than
3149 * or equal to zero, re-transport the command: If the re-transport
3150 * fails with BUSY, enqueue the command in the wait queue.
3152 * In order to prevent looping forever because of commands enqueued
3153 * from within this function itself, save the current tail pointer
3154 * (in cur_tail) and exit the loop after serving this command.
3157 fp_resendcmd(void *port_handle
)
3160 fc_local_port_t
*port
;
3165 mutex_enter(&port
->fp_mutex
);
3166 cur_tail
= port
->fp_wait_tail
;
3167 mutex_exit(&port
->fp_mutex
);
3169 while ((cmd
= fp_deque_cmd(port
)) != NULL
) {
3170 cmd
->cmd_retry_interval
-= fp_retry_ticker
;
3171 /* Check if we are detaching */
3172 if (port
->fp_soft_state
&
3173 (FP_SOFT_IN_DETACH
| FP_DETACH_INPROGRESS
)) {
3174 cmd
->cmd_pkt
.pkt_state
= FC_PKT_TRAN_ERROR
;
3175 cmd
->cmd_pkt
.pkt_reason
= 0;
3177 } else if (cmd
->cmd_retry_interval
<= 0) {
3178 rval
= cmd
->cmd_transport(port
->fp_fca_handle
,
3181 if (rval
!= FC_SUCCESS
) {
3182 if (cmd
->cmd_pkt
.pkt_state
== FC_PKT_TRAN_BSY
) {
3183 if (--cmd
->cmd_retry_count
) {
3184 fp_enque_cmd(port
, cmd
);
3185 if (cmd
== cur_tail
) {
3190 cmd
->cmd_pkt
.pkt_state
=
3193 cmd
->cmd_pkt
.pkt_state
=
3196 cmd
->cmd_pkt
.pkt_reason
= 0;
3199 mutex_enter(&port
->fp_mutex
);
3200 port
->fp_out_fpcmds
++;
3201 mutex_exit(&port
->fp_mutex
);
3204 fp_enque_cmd(port
, cmd
);
3207 if (cmd
== cur_tail
) {
3212 mutex_enter(&port
->fp_mutex
);
3213 if (port
->fp_wait_head
) {
3216 mutex_exit(&port
->fp_mutex
);
3217 tid
= timeout(fp_resendcmd
, (caddr_t
)port
,
3219 mutex_enter(&port
->fp_mutex
);
3220 port
->fp_wait_tid
= tid
;
3222 port
->fp_wait_tid
= NULL
;
3224 mutex_exit(&port
->fp_mutex
);
3229 * Handle Local, Fabric, N_Port, Transport (whatever that means) BUSY here.
3231 * Yes, as you can see below, cmd_retry_count is used here too. That means
3232 * the retries for BUSY are less if there were transport failures (transport
3233 * failure means fca_transport failure). The goal is not to exceed overall
3234 * retries set in the cmd_retry_count (whatever may be the reason for retry)
3241 fp_retry_cmd(fc_packet_t
*pkt
)
3245 cmd
= pkt
->pkt_ulp_private
;
3247 if (--cmd
->cmd_retry_count
) {
3248 fp_enque_cmd(cmd
->cmd_port
, cmd
);
3249 return (FC_SUCCESS
);
3251 return (FC_FAILURE
);
3257 * Queue up FC packet for deferred retry
3260 fp_enque_cmd(fc_local_port_t
*port
, fp_cmd_t
*cmd
)
3264 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
3267 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, &cmd
->cmd_pkt
,
3268 "Retrying ELS for %x", cmd
->cmd_pkt
.pkt_cmd_fhdr
.d_id
);
3271 mutex_enter(&port
->fp_mutex
);
3272 if (port
->fp_wait_tail
) {
3273 port
->fp_wait_tail
->cmd_next
= cmd
;
3274 port
->fp_wait_tail
= cmd
;
3276 ASSERT(port
->fp_wait_head
== NULL
);
3277 port
->fp_wait_head
= port
->fp_wait_tail
= cmd
;
3278 if (port
->fp_wait_tid
== NULL
) {
3279 mutex_exit(&port
->fp_mutex
);
3280 tid
= timeout(fp_resendcmd
, (caddr_t
)port
,
3282 mutex_enter(&port
->fp_mutex
);
3283 port
->fp_wait_tid
= tid
;
3286 mutex_exit(&port
->fp_mutex
);
3291 * Handle all RJT codes
3294 fp_handle_reject(fc_packet_t
*pkt
)
3296 int rval
= FC_FAILURE
;
3299 fc_local_port_t
*port
;
3301 cmd
= pkt
->pkt_ulp_private
;
3302 port
= cmd
->cmd_port
;
3304 switch (pkt
->pkt_state
) {
3305 case FC_PKT_FABRIC_RJT
:
3306 case FC_PKT_NPORT_RJT
:
3307 if (pkt
->pkt_reason
== FC_REASON_CLASS_NOT_SUPP
) {
3308 next_class
= fp_get_nextclass(cmd
->cmd_port
,
3309 FC_TRAN_CLASS(pkt
->pkt_tran_flags
));
3311 if (next_class
== FC_TRAN_CLASS_INVALID
) {
3314 pkt
->pkt_tran_flags
= FC_TRAN_INTR
| next_class
;
3315 pkt
->pkt_tran_type
= FC_PKT_EXCHANGE
;
3317 rval
= fp_sendcmd(cmd
->cmd_port
, cmd
,
3318 cmd
->cmd_port
->fp_fca_handle
);
3320 if (rval
!= FC_SUCCESS
) {
3321 pkt
->pkt_state
= FC_PKT_TRAN_ERROR
;
3328 if ((pkt
->pkt_reason
== FC_REASON_LOGICAL_ERROR
) ||
3329 (pkt
->pkt_reason
== FC_REASON_LOGICAL_BSY
)) {
3330 cmd
->cmd_retry_interval
= fp_retry_delay
;
3331 rval
= fp_retry_cmd(pkt
);
3336 if ((pkt
->pkt_reason
== FC_REASON_FS_LOGICAL_BUSY
) ||
3337 ((pkt
->pkt_reason
== FC_REASON_FS_CMD_UNABLE
) &&
3338 (pkt
->pkt_expln
== 0x00))) {
3339 cmd
->cmd_retry_interval
= fp_retry_delay
;
3340 rval
= fp_retry_cmd(pkt
);
3344 case FC_PKT_LOCAL_RJT
:
3345 if (pkt
->pkt_reason
== FC_REASON_QFULL
) {
3346 cmd
->cmd_retry_interval
= fp_retry_delay
;
3347 rval
= fp_retry_cmd(pkt
);
3352 FP_TRACE(FP_NHEAD1(1, 0),
3353 "fp_handle_reject(): Invalid pkt_state");
3362 * Return the next class of service supported by the FCA
3365 fp_get_nextclass(fc_local_port_t
*port
, uchar_t cur_class
)
3369 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
3371 switch (cur_class
) {
3372 case FC_TRAN_CLASS_INVALID
:
3373 if (port
->fp_cos
& FC_NS_CLASS1
) {
3374 next_class
= FC_TRAN_CLASS1
;
3379 case FC_TRAN_CLASS1
:
3380 if (port
->fp_cos
& FC_NS_CLASS2
) {
3381 next_class
= FC_TRAN_CLASS2
;
3386 case FC_TRAN_CLASS2
:
3387 if (port
->fp_cos
& FC_NS_CLASS3
) {
3388 next_class
= FC_TRAN_CLASS3
;
3393 case FC_TRAN_CLASS3
:
3395 next_class
= FC_TRAN_CLASS_INVALID
;
3399 return (next_class
);
3404 * Determine if a class of service is supported by the FCA
3407 fp_is_class_supported(uint32_t cos
, uchar_t tran_class
)
3411 switch (tran_class
) {
3412 case FC_TRAN_CLASS1
:
3413 if (cos
& FC_NS_CLASS1
) {
3420 case FC_TRAN_CLASS2
:
3421 if (cos
& FC_NS_CLASS2
) {
3428 case FC_TRAN_CLASS3
:
3429 if (cos
& FC_NS_CLASS3
) {
3446 * Dequeue FC packet for retry
3449 fp_deque_cmd(fc_local_port_t
*port
)
3453 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
3455 mutex_enter(&port
->fp_mutex
);
3457 if (port
->fp_wait_head
== NULL
) {
3459 * To avoid races, NULL the fp_wait_tid as
3460 * we are about to exit the timeout thread.
3462 port
->fp_wait_tid
= NULL
;
3463 mutex_exit(&port
->fp_mutex
);
3467 cmd
= port
->fp_wait_head
;
3468 port
->fp_wait_head
= cmd
->cmd_next
;
3469 cmd
->cmd_next
= NULL
;
3471 if (port
->fp_wait_head
== NULL
) {
3472 port
->fp_wait_tail
= NULL
;
3474 mutex_exit(&port
->fp_mutex
);
3481 * Wait for job completion
3484 fp_jobwait(job_request_t
*job
)
3486 sema_p(&job
->job_port_sema
);
3491 * Convert FC packet state to FC errno
3494 fp_state_to_rval(uchar_t state
)
3498 for (count
= 0; count
< sizeof (fp_xlat
) /
3499 sizeof (fp_xlat
[0]); count
++) {
3500 if (fp_xlat
[count
].xlat_state
== state
) {
3501 return (fp_xlat
[count
].xlat_rval
);
3505 return (FC_FAILURE
);
3510 * For Synchronous I/O requests, the caller is
3511 * expected to do fctl_jobdone(if necessary)
3513 * We want to preserve at least one failure in the
3514 * job_result if it happens.
3518 fp_iodone(fp_cmd_t
*cmd
)
3520 fc_packet_t
*ulp_pkt
= cmd
->cmd_ulp_pkt
;
3521 job_request_t
*job
= cmd
->cmd_job
;
3522 fc_remote_port_t
*pd
= cmd
->cmd_pkt
.pkt_pd
;
3524 ASSERT(job
!= NULL
);
3525 ASSERT(cmd
->cmd_port
!= NULL
);
3526 ASSERT(&cmd
->cmd_pkt
!= NULL
);
3528 mutex_enter(&job
->job_mutex
);
3529 if (job
->job_result
== FC_SUCCESS
) {
3530 job
->job_result
= fp_state_to_rval(cmd
->cmd_pkt
.pkt_state
);
3532 mutex_exit(&job
->job_mutex
);
3535 mutex_enter(&pd
->pd_mutex
);
3536 pd
->pd_flags
= PD_IDLE
;
3537 mutex_exit(&pd
->pd_mutex
);
3541 if (pd
&& cmd
->cmd_flags
& FP_CMD_DELDEV_ON_ERROR
&&
3542 FP_IS_PKT_ERROR(ulp_pkt
)) {
3543 fc_local_port_t
*port
;
3544 fc_remote_node_t
*node
;
3546 port
= cmd
->cmd_port
;
3548 mutex_enter(&pd
->pd_mutex
);
3549 pd
->pd_state
= PORT_DEVICE_INVALID
;
3551 node
= pd
->pd_remote_nodep
;
3552 mutex_exit(&pd
->pd_mutex
);
3554 ASSERT(node
!= NULL
);
3555 ASSERT(port
!= NULL
);
3557 if (fctl_destroy_remote_port(port
, pd
) == 0) {
3558 fctl_destroy_remote_node(node
);
3561 ulp_pkt
->pkt_pd
= NULL
;
3564 ulp_pkt
->pkt_comp(ulp_pkt
);
3573 * Job completion handler
3576 fp_jobdone(job_request_t
*job
)
3578 mutex_enter(&job
->job_mutex
);
3579 ASSERT(job
->job_counter
> 0);
3581 if (--job
->job_counter
!= 0) {
3582 mutex_exit(&job
->job_mutex
);
3586 if (job
->job_ulp_pkts
) {
3587 ASSERT(job
->job_ulp_listlen
> 0);
3588 kmem_free(job
->job_ulp_pkts
,
3589 sizeof (fc_packet_t
*) * job
->job_ulp_listlen
);
3592 if (job
->job_flags
& JOB_TYPE_FP_ASYNC
) {
3593 mutex_exit(&job
->job_mutex
);
3596 mutex_exit(&job
->job_mutex
);
3597 sema_v(&job
->job_port_sema
);
3603 * Try to perform shutdown of a port during a detach. No return
3604 * value since the detach should not fail because the port shutdown
3608 fp_port_shutdown(fc_local_port_t
*port
, job_request_t
*job
)
3614 struct pwwn_hash
*head
;
3615 fc_remote_port_t
*pd
;
3617 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
3619 job
->job_result
= FC_SUCCESS
;
3621 if (port
->fp_taskq
) {
3623 * We must release the mutex here to ensure that other
3624 * potential jobs can complete their processing. Many
3625 * also need this mutex.
3627 mutex_exit(&port
->fp_mutex
);
3628 taskq_wait(port
->fp_taskq
);
3629 mutex_enter(&port
->fp_mutex
);
3632 if (port
->fp_offline_tid
) {
3635 tid
= port
->fp_offline_tid
;
3636 port
->fp_offline_tid
= NULL
;
3637 mutex_exit(&port
->fp_mutex
);
3638 (void) untimeout(tid
);
3639 mutex_enter(&port
->fp_mutex
);
3642 if (port
->fp_wait_tid
) {
3645 tid
= port
->fp_wait_tid
;
3646 port
->fp_wait_tid
= NULL
;
3647 mutex_exit(&port
->fp_mutex
);
3648 (void) untimeout(tid
);
3650 mutex_exit(&port
->fp_mutex
);
3654 * While we cancel the timeout, let's also return the
3655 * the outstanding requests back to the callers.
3657 while ((cmd
= fp_deque_cmd(port
)) != NULL
) {
3658 ASSERT(cmd
->cmd_job
!= NULL
);
3659 cmd
->cmd_job
->job_result
= FC_OFFLINE
;
3664 * Gracefully LOGO with all the devices logged in.
3666 mutex_enter(&port
->fp_mutex
);
3668 for (count
= index
= 0; index
< pwwn_table_size
; index
++) {
3669 head
= &port
->fp_pwwn_table
[index
];
3670 pd
= head
->pwwn_head
;
3671 while (pd
!= NULL
) {
3672 mutex_enter(&pd
->pd_mutex
);
3673 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
3676 mutex_exit(&pd
->pd_mutex
);
3677 pd
= pd
->pd_wwn_hnext
;
3681 if (job
->job_flags
& JOB_TYPE_FP_ASYNC
) {
3682 flags
= job
->job_flags
;
3683 job
->job_flags
&= ~JOB_TYPE_FP_ASYNC
;
3688 job
->job_counter
= count
;
3690 for (index
= 0; index
< pwwn_table_size
; index
++) {
3691 head
= &port
->fp_pwwn_table
[index
];
3692 pd
= head
->pwwn_head
;
3693 while (pd
!= NULL
) {
3694 mutex_enter(&pd
->pd_mutex
);
3695 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
3696 ASSERT(pd
->pd_login_count
> 0);
3698 * Force the counter to ONE in order
3699 * for us to really send LOGO els.
3701 pd
->pd_login_count
= 1;
3702 mutex_exit(&pd
->pd_mutex
);
3703 mutex_exit(&port
->fp_mutex
);
3704 (void) fp_logout(port
, pd
, job
);
3705 mutex_enter(&port
->fp_mutex
);
3707 mutex_exit(&pd
->pd_mutex
);
3709 pd
= pd
->pd_wwn_hnext
;
3712 mutex_exit(&port
->fp_mutex
);
3715 mutex_exit(&port
->fp_mutex
);
3718 if (job
->job_result
!= FC_SUCCESS
) {
3719 FP_TRACE(FP_NHEAD1(9, 0),
3720 "Can't logout all devices. Proceeding with"
3722 job
->job_result
= FC_SUCCESS
;
3725 fctl_destroy_all_remote_ports(port
);
3727 mutex_enter(&port
->fp_mutex
);
3728 if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
3729 mutex_exit(&port
->fp_mutex
);
3730 fp_ns_fini(port
, job
);
3732 mutex_exit(&port
->fp_mutex
);
3736 job
->job_flags
= flags
;
3739 mutex_enter(&port
->fp_mutex
);
3745 * Build the port driver's data structures based on the AL_PA list
3748 fp_get_loopmap(fc_local_port_t
*port
, job_request_t
*job
)
3754 fc_remote_port_t
*pd
;
3755 fc_lilpmap_t
*lilp_map
;
3757 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
3759 if (FC_PORT_STATE_MASK(port
->fp_state
) == FC_STATE_OFFLINE
) {
3760 job
->job_result
= FC_OFFLINE
;
3761 mutex_exit(&port
->fp_mutex
);
3763 mutex_enter(&port
->fp_mutex
);
3767 if (port
->fp_lilp_map
.lilp_length
== 0) {
3768 mutex_exit(&port
->fp_mutex
);
3769 job
->job_result
= FC_NO_MAP
;
3771 mutex_enter(&port
->fp_mutex
);
3774 mutex_exit(&port
->fp_mutex
);
3776 lilp_map
= &port
->fp_lilp_map
;
3777 job
->job_counter
= lilp_map
->lilp_length
;
3779 if (job
->job_code
== JOB_PORT_GETMAP_PLOGI_ALL
) {
3780 flag
= FP_CMD_PLOGI_RETAIN
;
3782 flag
= FP_CMD_PLOGI_DONT_CARE
;
3785 for (count
= 0; count
< lilp_map
->lilp_length
; count
++) {
3786 d_id
= lilp_map
->lilp_alpalist
[count
];
3788 if (d_id
== (lilp_map
->lilp_myalpa
& 0xFF)) {
3793 pd
= fctl_get_remote_port_by_did(port
, d_id
);
3795 mutex_enter(&pd
->pd_mutex
);
3796 if (flag
== FP_CMD_PLOGI_DONT_CARE
||
3797 pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
3798 mutex_exit(&pd
->pd_mutex
);
3802 mutex_exit(&pd
->pd_mutex
);
3805 rval
= fp_port_login(port
, d_id
, job
, flag
,
3806 KM_SLEEP
, pd
, NULL
);
3807 if (rval
!= FC_SUCCESS
) {
3812 mutex_enter(&port
->fp_mutex
);
3817 * Perform loop ONLINE processing
3820 fp_loop_online(fc_local_port_t
*port
, job_request_t
*job
, int orphan
)
3826 fc_lilpmap_t
*lilp_map
;
3827 fc_remote_port_t
*pd
;
3828 fc_portmap_t
*changelist
;
3830 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
3832 FP_TRACE(FP_NHEAD1(1, 0), "fp_loop_online begin; port=%p, job=%p",
3835 lilp_map
= &port
->fp_lilp_map
;
3837 if (lilp_map
->lilp_length
) {
3838 mutex_enter(&port
->fp_mutex
);
3839 if (port
->fp_soft_state
& FP_SOFT_IN_FCA_RESET
) {
3840 port
->fp_soft_state
&= ~FP_SOFT_IN_FCA_RESET
;
3841 mutex_exit(&port
->fp_mutex
);
3842 ddi_sleep(PLDA_RR_TOV
);
3844 mutex_exit(&port
->fp_mutex
);
3847 job
->job_counter
= lilp_map
->lilp_length
;
3849 for (count
= 0; count
< lilp_map
->lilp_length
; count
++) {
3850 d_id
= lilp_map
->lilp_alpalist
[count
];
3852 if (d_id
== (lilp_map
->lilp_myalpa
& 0xFF)) {
3857 pd
= fctl_get_remote_port_by_did(port
, d_id
);
3860 mutex_enter(&pd
->pd_mutex
);
3861 if (pd
->pd_recepient
== PD_PLOGI_INITIATOR
) {
3862 ASSERT(pd
->pd_type
!= PORT_DEVICE_OLD
);
3864 mutex_exit(&pd
->pd_mutex
);
3870 rval
= fp_port_login(port
, d_id
, job
,
3871 FP_CMD_PLOGI_DONT_CARE
, KM_SLEEP
, pd
, NULL
);
3873 if (rval
!= FC_SUCCESS
) {
3882 if ((job
->job_flags
& JOB_CANCEL_ULP_NOTIFICATION
) == 0) {
3883 mutex_enter(&port
->fp_mutex
);
3884 ASSERT(port
->fp_statec_busy
> 0);
3885 if (port
->fp_statec_busy
== 1) {
3886 mutex_exit(&port
->fp_mutex
);
3887 fctl_fillout_map(port
, &changelist
, &listlen
,
3890 mutex_enter(&port
->fp_mutex
);
3891 if (port
->fp_lilp_map
.lilp_magic
< MAGIC_LIRP
) {
3892 ASSERT(port
->fp_total_devices
== 0);
3893 port
->fp_total_devices
= port
->fp_dev_count
;
3896 job
->job_flags
|= JOB_CANCEL_ULP_NOTIFICATION
;
3898 mutex_exit(&port
->fp_mutex
);
3901 if ((job
->job_flags
& JOB_CANCEL_ULP_NOTIFICATION
) == 0) {
3902 (void) fp_ulp_statec_cb(port
, FC_STATE_ONLINE
, changelist
,
3903 listlen
, listlen
, KM_SLEEP
);
3905 mutex_enter(&port
->fp_mutex
);
3906 if (--port
->fp_statec_busy
== 0) {
3907 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
3909 ASSERT(changelist
== NULL
&& listlen
== 0);
3910 mutex_exit(&port
->fp_mutex
);
3913 FP_TRACE(FP_NHEAD1(1, 0), "fp_loop_online end; port=%p, job=%p",
3919 * Get an Arbitrated Loop map from the underlying FCA
3922 fp_get_lilpmap(fc_local_port_t
*port
, fc_lilpmap_t
*lilp_map
)
3926 FP_TRACE(FP_NHEAD1(1, 0), "fp_get_lilpmap Begin; port=%p, map=%p",
3929 bzero((caddr_t
)lilp_map
, sizeof (fc_lilpmap_t
));
3930 rval
= port
->fp_fca_tran
->fca_getmap(port
->fp_fca_handle
, lilp_map
);
3931 lilp_map
->lilp_magic
&= 0xFF; /* Ignore upper byte */
3933 if (rval
!= FC_SUCCESS
) {
3935 } else if (lilp_map
->lilp_length
== 0 &&
3936 (lilp_map
->lilp_magic
>= MAGIC_LISM
&&
3937 lilp_map
->lilp_magic
< MAGIC_LIRP
)) {
3938 uchar_t lilp_length
;
3941 * Since the map length is zero, provide all
3942 * the valid AL_PAs for NL_ports discovery.
3944 lilp_length
= sizeof (fp_valid_alpas
) /
3945 sizeof (fp_valid_alpas
[0]);
3946 lilp_map
->lilp_length
= lilp_length
;
3947 bcopy(fp_valid_alpas
, lilp_map
->lilp_alpalist
,
3950 rval
= fp_validate_lilp_map(lilp_map
);
3952 if (rval
== FC_SUCCESS
) {
3953 mutex_enter(&port
->fp_mutex
);
3954 port
->fp_total_devices
= lilp_map
->lilp_length
- 1;
3955 mutex_exit(&port
->fp_mutex
);
3959 mutex_enter(&port
->fp_mutex
);
3960 if (rval
!= FC_SUCCESS
&& !(port
->fp_soft_state
& FP_SOFT_BAD_LINK
)) {
3961 port
->fp_soft_state
|= FP_SOFT_BAD_LINK
;
3962 mutex_exit(&port
->fp_mutex
);
3964 if (port
->fp_fca_tran
->fca_reset(port
->fp_fca_handle
,
3965 FC_FCA_RESET_CORE
) != FC_SUCCESS
) {
3966 FP_TRACE(FP_NHEAD1(9, 0),
3967 "FCA reset failed after LILP map was found"
3970 } else if (rval
== FC_SUCCESS
) {
3971 port
->fp_soft_state
&= ~FP_SOFT_BAD_LINK
;
3972 mutex_exit(&port
->fp_mutex
);
3974 mutex_exit(&port
->fp_mutex
);
3977 FP_TRACE(FP_NHEAD1(1, 0), "fp_get_lilpmap End; port=%p, map=%p", port
,
3985 * Perform Fabric Login:
3991 * FC_TRANSPORT_ERROR
3992 * and a lot others defined in fc_error.h
3995 fp_fabric_login(fc_local_port_t
*port
, uint32_t s_id
, job_request_t
*job
,
3996 int flag
, int sleep
)
4002 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
4004 FP_TRACE(FP_NHEAD1(1, 0), "fp_fabric_login Begin; port=%p, job=%p",
4007 class = fp_get_nextclass(port
, FC_TRAN_CLASS_INVALID
);
4008 if (class == FC_TRAN_CLASS_INVALID
) {
4009 return (FC_ELS_BAD
);
4012 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logi_t
),
4013 sizeof (la_els_logi_t
), sleep
, NULL
);
4018 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| class;
4019 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
4020 cmd
->cmd_flags
= flag
;
4021 cmd
->cmd_retry_count
= fp_retry_count
;
4022 cmd
->cmd_ulp_pkt
= NULL
;
4024 fp_xlogi_init(port
, cmd
, s_id
, 0xFFFFFE, fp_flogi_intr
,
4027 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
4028 if (rval
!= FC_SUCCESS
) {
4032 FP_TRACE(FP_NHEAD1(1, 0), "fp_fabric_login End; port=%p, job=%p",
4040 * In some scenarios such as private loop device discovery period
4041 * the fc_remote_port_t data structure isn't allocated. The allocation
4042 * is done when the PLOGI is successful. In some other scenarios
4043 * such as Fabric topology, the fc_remote_port_t is already created
4044 * and initialized with appropriate values (as the NS provides
4048 fp_port_login(fc_local_port_t
*port
, uint32_t d_id
, job_request_t
*job
,
4049 int cmd_flag
, int sleep
, fc_remote_port_t
*pd
, fc_packet_t
*ulp_pkt
)
4054 fc_remote_port_t
*tmp_pd
;
4060 ASSERT(fctl_get_remote_port_by_did(port
, d_id
) == NULL
);
4063 ASSERT(job
->job_counter
> 0);
4065 class = fp_get_nextclass(port
, FC_TRAN_CLASS_INVALID
);
4066 if (class == FC_TRAN_CLASS_INVALID
) {
4067 return (FC_ELS_BAD
);
4070 mutex_enter(&port
->fp_mutex
);
4071 tmp_pd
= fctl_lookup_pd_by_did(port
, d_id
);
4072 mutex_exit(&port
->fp_mutex
);
4076 mutex_enter(&tmp_pd
->pd_mutex
);
4077 if ((tmp_pd
->pd_aux_flags
& PD_DISABLE_RELOGIN
) &&
4078 !(tmp_pd
->pd_aux_flags
& PD_LOGGED_OUT
)) {
4079 tmp_pd
->pd_state
= PORT_DEVICE_LOGGED_IN
;
4082 mutex_exit(&tmp_pd
->pd_mutex
);
4086 mutex_enter(&tmp_pd
->pd_mutex
);
4087 if (tmp_pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
4088 cmd_flag
|= FP_CMD_PLOGI_RETAIN
;
4090 mutex_exit(&tmp_pd
->pd_mutex
);
4092 cmd
= fp_alloc_pkt(port
, sizeof (la_els_adisc_t
),
4093 sizeof (la_els_adisc_t
), sleep
, tmp_pd
);
4098 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| class;
4099 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
4100 cmd
->cmd_flags
= cmd_flag
;
4101 cmd
->cmd_retry_count
= fp_retry_count
;
4102 cmd
->cmd_ulp_pkt
= ulp_pkt
;
4104 mutex_enter(&port
->fp_mutex
);
4105 mutex_enter(&tmp_pd
->pd_mutex
);
4106 fp_adisc_init(cmd
, job
);
4107 mutex_exit(&tmp_pd
->pd_mutex
);
4108 mutex_exit(&port
->fp_mutex
);
4110 cmd
->cmd_pkt
.pkt_cmdlen
= sizeof (la_els_adisc_t
);
4111 cmd
->cmd_pkt
.pkt_rsplen
= sizeof (la_els_adisc_t
);
4114 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logi_t
),
4115 sizeof (la_els_logi_t
), sleep
, pd
);
4120 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| class;
4121 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
4122 cmd
->cmd_flags
= cmd_flag
;
4123 cmd
->cmd_retry_count
= fp_retry_count
;
4124 cmd
->cmd_ulp_pkt
= ulp_pkt
;
4126 mutex_enter(&port
->fp_mutex
);
4127 src_id
= port
->fp_port_id
.port_id
;
4128 mutex_exit(&port
->fp_mutex
);
4130 fp_xlogi_init(port
, cmd
, src_id
, d_id
, fp_plogi_intr
,
4135 mutex_enter(&pd
->pd_mutex
);
4136 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
4137 mutex_exit(&pd
->pd_mutex
);
4140 /* npiv check to make sure we don't log into ourself */
4142 ((port
->fp_npiv_type
== FC_NPIV_PORT
) ||
4143 (port
->fp_npiv_flag
== FC_NPIV_ENABLE
))) {
4144 if ((d_id
& 0xffff00) ==
4145 (port
->fp_port_id
.port_id
& 0xffff00)) {
4151 (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
)) {
4153 fc_packet_t
*pkt
= &cmd
->cmd_pkt
;
4154 pkt
->pkt_state
= FC_PKT_NPORT_RJT
;
4157 mutex_enter(&pd
->pd_mutex
);
4158 pd
->pd_flags
= PD_IDLE
;
4159 mutex_exit(&pd
->pd_mutex
);
4163 fc_packet_t
*pkt
= &cmd
->cmd_pkt
;
4165 ulp_pkt
->pkt_state
= pkt
->pkt_state
;
4166 ulp_pkt
->pkt_reason
= pkt
->pkt_reason
;
4167 ulp_pkt
->pkt_action
= pkt
->pkt_action
;
4168 ulp_pkt
->pkt_expln
= pkt
->pkt_expln
;
4174 return (FC_SUCCESS
);
4179 * Register the LOGIN parameters with a port device
4182 fp_register_login(ddi_acc_handle_t
*handle
, fc_remote_port_t
*pd
,
4183 la_els_logi_t
*acc
, uchar_t
class)
4185 fc_remote_node_t
*node
;
4189 mutex_enter(&pd
->pd_mutex
);
4190 node
= pd
->pd_remote_nodep
;
4191 if (pd
->pd_login_count
== 0) {
4192 pd
->pd_login_count
++;
4196 FC_GET_RSP(pd
->pd_port
, *handle
, (uint8_t *)&pd
->pd_csp
,
4197 (uint8_t *)&acc
->common_service
,
4198 sizeof (acc
->common_service
), DDI_DEV_AUTOINCR
);
4199 FC_GET_RSP(pd
->pd_port
, *handle
, (uint8_t *)&pd
->pd_clsp1
,
4200 (uint8_t *)&acc
->class_1
, sizeof (acc
->class_1
),
4202 FC_GET_RSP(pd
->pd_port
, *handle
, (uint8_t *)&pd
->pd_clsp2
,
4203 (uint8_t *)&acc
->class_2
, sizeof (acc
->class_2
),
4205 FC_GET_RSP(pd
->pd_port
, *handle
, (uint8_t *)&pd
->pd_clsp3
,
4206 (uint8_t *)&acc
->class_3
, sizeof (acc
->class_3
),
4209 pd
->pd_csp
= acc
->common_service
;
4210 pd
->pd_clsp1
= acc
->class_1
;
4211 pd
->pd_clsp2
= acc
->class_2
;
4212 pd
->pd_clsp3
= acc
->class_3
;
4215 pd
->pd_state
= PORT_DEVICE_LOGGED_IN
;
4216 pd
->pd_login_class
= class;
4217 mutex_exit(&pd
->pd_mutex
);
4220 ASSERT(fctl_get_remote_port_by_did(pd
->pd_port
,
4221 pd
->pd_port_id
.port_id
) == pd
);
4224 mutex_enter(&node
->fd_mutex
);
4226 FC_GET_RSP(pd
->pd_port
, *handle
, (uint8_t *)node
->fd_vv
,
4227 (uint8_t *)acc
->vendor_version
, sizeof (node
->fd_vv
),
4230 bcopy(acc
->vendor_version
, node
->fd_vv
, sizeof (node
->fd_vv
));
4232 mutex_exit(&node
->fd_mutex
);
4237 * Mark the remote port as OFFLINE
4240 fp_remote_port_offline(fc_remote_port_t
*pd
)
4242 ASSERT(MUTEX_HELD(&pd
->pd_mutex
));
4243 if (pd
->pd_login_count
&&
4244 ((pd
->pd_aux_flags
& PD_DISABLE_RELOGIN
) == 0)) {
4245 bzero((caddr_t
)&pd
->pd_csp
, sizeof (struct common_service
));
4246 bzero((caddr_t
)&pd
->pd_clsp1
, sizeof (struct service_param
));
4247 bzero((caddr_t
)&pd
->pd_clsp2
, sizeof (struct service_param
));
4248 bzero((caddr_t
)&pd
->pd_clsp3
, sizeof (struct service_param
));
4249 pd
->pd_login_class
= 0;
4251 pd
->pd_type
= PORT_DEVICE_OLD
;
4252 pd
->pd_flags
= PD_IDLE
;
4253 fctl_tc_reset(&pd
->pd_logo_tc
);
4258 * Deregistration of a port device
4261 fp_unregister_login(fc_remote_port_t
*pd
)
4263 fc_remote_node_t
*node
;
4267 mutex_enter(&pd
->pd_mutex
);
4268 pd
->pd_login_count
= 0;
4269 bzero((caddr_t
)&pd
->pd_csp
, sizeof (struct common_service
));
4270 bzero((caddr_t
)&pd
->pd_clsp1
, sizeof (struct service_param
));
4271 bzero((caddr_t
)&pd
->pd_clsp2
, sizeof (struct service_param
));
4272 bzero((caddr_t
)&pd
->pd_clsp3
, sizeof (struct service_param
));
4274 pd
->pd_state
= PORT_DEVICE_VALID
;
4275 pd
->pd_login_class
= 0;
4276 node
= pd
->pd_remote_nodep
;
4277 mutex_exit(&pd
->pd_mutex
);
4279 mutex_enter(&node
->fd_mutex
);
4280 bzero(node
->fd_vv
, sizeof (node
->fd_vv
));
4281 mutex_exit(&node
->fd_mutex
);
4286 * Handle OFFLINE state of an FCA port
4289 fp_port_offline(fc_local_port_t
*port
, int notify
)
4294 struct pwwn_hash
*head
;
4295 fc_remote_port_t
*pd
;
4297 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
4299 for (index
= 0; index
< pwwn_table_size
; index
++) {
4300 head
= &port
->fp_pwwn_table
[index
];
4301 pd
= head
->pwwn_head
;
4302 while (pd
!= NULL
) {
4303 mutex_enter(&pd
->pd_mutex
);
4304 fp_remote_port_offline(pd
);
4305 fctl_delist_did_table(port
, pd
);
4306 mutex_exit(&pd
->pd_mutex
);
4307 pd
= pd
->pd_wwn_hnext
;
4310 port
->fp_total_devices
= 0;
4315 * Decrement the statec busy counter as we
4316 * are almost done with handling the state
4319 ASSERT(port
->fp_statec_busy
> 0);
4320 if (--port
->fp_statec_busy
== 0) {
4321 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
4323 mutex_exit(&port
->fp_mutex
);
4324 (void) fp_ulp_statec_cb(port
, FC_STATE_OFFLINE
, NULL
,
4326 mutex_enter(&port
->fp_mutex
);
4328 if (port
->fp_statec_busy
) {
4331 } else if (port
->fp_statec_busy
> 1) {
4335 if ((tid
= port
->fp_offline_tid
) != NULL
) {
4336 mutex_exit(&port
->fp_mutex
);
4337 (void) untimeout(tid
);
4338 mutex_enter(&port
->fp_mutex
);
4342 port
->fp_offline_tid
= timeout(fp_offline_timeout
,
4343 (caddr_t
)port
, fp_offline_ticks
);
4349 * Offline devices and send up a state change notification to ULPs
4352 fp_offline_timeout(void *port_handle
)
4355 fc_local_port_t
*port
= port_handle
;
4356 uint32_t listlen
= 0;
4357 fc_portmap_t
*changelist
= NULL
;
4359 mutex_enter(&port
->fp_mutex
);
4361 if ((FC_PORT_STATE_MASK(port
->fp_state
) != FC_STATE_OFFLINE
) ||
4362 (port
->fp_soft_state
&
4363 (FP_SOFT_IN_DETACH
| FP_SOFT_SUSPEND
| FP_SOFT_POWER_DOWN
)) ||
4364 port
->fp_dev_count
== 0 || port
->fp_statec_busy
) {
4365 port
->fp_offline_tid
= NULL
;
4366 mutex_exit(&port
->fp_mutex
);
4370 mutex_exit(&port
->fp_mutex
);
4372 FP_TRACE(FP_NHEAD2(9, 0), "OFFLINE timeout");
4374 if (port
->fp_options
& FP_CORE_ON_OFFLINE_TIMEOUT
) {
4375 if ((ret
= port
->fp_fca_tran
->fca_reset(port
->fp_fca_handle
,
4376 FC_FCA_CORE
)) != FC_SUCCESS
) {
4377 FP_TRACE(FP_NHEAD1(9, ret
),
4378 "Failed to force adapter dump");
4380 FP_TRACE(FP_NHEAD1(9, 0),
4381 "Forced adapter dump successfully");
4383 } else if (port
->fp_options
& FP_RESET_CORE_ON_OFFLINE_TIMEOUT
) {
4384 if ((ret
= port
->fp_fca_tran
->fca_reset(port
->fp_fca_handle
,
4385 FC_FCA_RESET_CORE
)) != FC_SUCCESS
) {
4386 FP_TRACE(FP_NHEAD1(9, ret
),
4387 "Failed to force adapter dump and reset");
4389 FP_TRACE(FP_NHEAD1(9, 0),
4390 "Forced adapter dump and reset successfully");
4394 fctl_fillout_map(port
, &changelist
, &listlen
, 1, 0, 0);
4395 (void) fp_ulp_statec_cb(port
, FC_STATE_OFFLINE
, changelist
,
4396 listlen
, listlen
, KM_SLEEP
);
4398 mutex_enter(&port
->fp_mutex
);
4399 port
->fp_offline_tid
= NULL
;
4400 mutex_exit(&port
->fp_mutex
);
4405 * Perform general purpose ELS request initialization
4408 fp_els_init(fp_cmd_t
*cmd
, uint32_t s_id
, uint32_t d_id
,
4409 void (*comp
) (), job_request_t
*job
)
4413 pkt
= &cmd
->cmd_pkt
;
4416 pkt
->pkt_cmd_fhdr
.r_ctl
= R_CTL_ELS_REQ
;
4417 pkt
->pkt_cmd_fhdr
.d_id
= d_id
;
4418 pkt
->pkt_cmd_fhdr
.s_id
= s_id
;
4419 pkt
->pkt_cmd_fhdr
.type
= FC_TYPE_EXTENDED_LS
;
4420 pkt
->pkt_cmd_fhdr
.f_ctl
= F_CTL_SEQ_INITIATIVE
| F_CTL_FIRST_SEQ
;
4421 pkt
->pkt_cmd_fhdr
.seq_id
= 0;
4422 pkt
->pkt_cmd_fhdr
.df_ctl
= 0;
4423 pkt
->pkt_cmd_fhdr
.seq_cnt
= 0;
4424 pkt
->pkt_cmd_fhdr
.ox_id
= 0xffff;
4425 pkt
->pkt_cmd_fhdr
.rx_id
= 0xffff;
4426 pkt
->pkt_cmd_fhdr
.ro
= 0;
4427 pkt
->pkt_cmd_fhdr
.rsvd
= 0;
4428 pkt
->pkt_comp
= comp
;
4429 pkt
->pkt_timeout
= FP_ELS_TIMEOUT
;
4434 * Initialize PLOGI/FLOGI ELS request
4437 fp_xlogi_init(fc_local_port_t
*port
, fp_cmd_t
*cmd
, uint32_t s_id
,
4438 uint32_t d_id
, void (*intr
) (), job_request_t
*job
, uchar_t ls_code
)
4442 fp_els_init(cmd
, s_id
, d_id
, intr
, job
);
4443 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
4445 payload
.ls_code
= ls_code
;
4448 FC_SET_CMD(port
, cmd
->cmd_pkt
.pkt_cmd_acc
,
4449 (uint8_t *)&port
->fp_service_params
,
4450 (uint8_t *)cmd
->cmd_pkt
.pkt_cmd
, sizeof (port
->fp_service_params
),
4453 FC_SET_CMD(port
, cmd
->cmd_pkt
.pkt_cmd_acc
, (uint8_t *)&payload
,
4454 (uint8_t *)cmd
->cmd_pkt
.pkt_cmd
, sizeof (payload
),
4460 * Initialize LOGO ELS request
4463 fp_logo_init(fc_remote_port_t
*pd
, fp_cmd_t
*cmd
, job_request_t
*job
)
4465 fc_local_port_t
*port
;
4467 la_els_logo_t payload
;
4470 pkt
= &cmd
->cmd_pkt
;
4471 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
4472 ASSERT(MUTEX_HELD(&pd
->pd_mutex
));
4474 fp_els_init(cmd
, port
->fp_port_id
.port_id
, pd
->pd_port_id
.port_id
,
4477 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
4479 pkt
->pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
4480 pkt
->pkt_tran_type
= FC_PKT_EXCHANGE
;
4482 payload
.ls_code
.ls_code
= LA_ELS_LOGO
;
4483 payload
.ls_code
.mbz
= 0;
4484 payload
.nport_ww_name
= port
->fp_service_params
.nport_ww_name
;
4485 payload
.nport_id
= port
->fp_port_id
;
4487 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
4488 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
4492 * Initialize RNID ELS request
4495 fp_rnid_init(fp_cmd_t
*cmd
, uint16_t flag
, job_request_t
*job
)
4497 fc_local_port_t
*port
;
4499 la_els_rnid_t payload
;
4500 fc_remote_port_t
*pd
;
4502 pkt
= &cmd
->cmd_pkt
;
4506 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
4507 ASSERT(MUTEX_HELD(&pd
->pd_mutex
));
4509 fp_els_init(cmd
, port
->fp_port_id
.port_id
, pd
->pd_port_id
.port_id
,
4512 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
4513 pkt
->pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
4514 pkt
->pkt_tran_type
= FC_PKT_EXCHANGE
;
4516 payload
.ls_code
.ls_code
= LA_ELS_RNID
;
4517 payload
.ls_code
.mbz
= 0;
4518 payload
.data_format
= flag
;
4520 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
4521 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
4525 * Initialize RLS ELS request
4528 fp_rls_init(fp_cmd_t
*cmd
, job_request_t
*job
)
4530 fc_local_port_t
*port
;
4532 la_els_rls_t payload
;
4533 fc_remote_port_t
*pd
;
4535 pkt
= &cmd
->cmd_pkt
;
4539 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
4540 ASSERT(MUTEX_HELD(&pd
->pd_mutex
));
4542 fp_els_init(cmd
, port
->fp_port_id
.port_id
, pd
->pd_port_id
.port_id
,
4545 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
4546 pkt
->pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
4547 pkt
->pkt_tran_type
= FC_PKT_EXCHANGE
;
4549 payload
.ls_code
.ls_code
= LA_ELS_RLS
;
4550 payload
.ls_code
.mbz
= 0;
4551 payload
.rls_portid
= port
->fp_port_id
;
4553 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
4554 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
4559 * Initialize an ADISC ELS request
4562 fp_adisc_init(fp_cmd_t
*cmd
, job_request_t
*job
)
4564 fc_local_port_t
*port
;
4566 la_els_adisc_t payload
;
4567 fc_remote_port_t
*pd
;
4569 pkt
= &cmd
->cmd_pkt
;
4573 ASSERT(MUTEX_HELD(&pd
->pd_mutex
));
4574 ASSERT(MUTEX_HELD(&pd
->pd_port
->fp_mutex
));
4576 fp_els_init(cmd
, port
->fp_port_id
.port_id
, pd
->pd_port_id
.port_id
,
4577 fp_adisc_intr
, job
);
4579 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
4580 pkt
->pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
4581 pkt
->pkt_tran_type
= FC_PKT_EXCHANGE
;
4583 payload
.ls_code
.ls_code
= LA_ELS_ADISC
;
4584 payload
.ls_code
.mbz
= 0;
4585 payload
.nport_id
= port
->fp_port_id
;
4586 payload
.port_wwn
= port
->fp_service_params
.nport_ww_name
;
4587 payload
.node_wwn
= port
->fp_service_params
.node_ww_name
;
4588 payload
.hard_addr
= port
->fp_hard_addr
;
4590 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
4591 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
4596 * Send up a state change notification to ULPs.
4597 * Spawns a call to fctl_ulp_statec_cb in a taskq thread.
4600 fp_ulp_statec_cb(fc_local_port_t
*port
, uint32_t state
,
4601 fc_portmap_t
*changelist
, uint32_t listlen
, uint32_t alloc_len
, int sleep
)
4603 fc_port_clist_t
*clist
;
4604 fc_remote_port_t
*pd
;
4607 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
4609 clist
= kmem_zalloc(sizeof (*clist
), sleep
);
4610 if (clist
== NULL
) {
4611 kmem_free(changelist
, alloc_len
* sizeof (*changelist
));
4615 clist
->clist_state
= state
;
4617 mutex_enter(&port
->fp_mutex
);
4618 clist
->clist_flags
= port
->fp_topology
;
4619 mutex_exit(&port
->fp_mutex
);
4621 clist
->clist_port
= (opaque_t
)port
;
4622 clist
->clist_len
= listlen
;
4623 clist
->clist_size
= alloc_len
;
4624 clist
->clist_map
= changelist
;
4627 * Bump the reference count of each fc_remote_port_t in this changelist.
4628 * This is necessary since these devices will be sitting in a taskq
4629 * and referenced later. When the state change notification is
4630 * complete, the reference counts will be decremented.
4632 for (count
= 0; count
< clist
->clist_len
; count
++) {
4633 pd
= clist
->clist_map
[count
].map_pd
;
4636 mutex_enter(&pd
->pd_mutex
);
4637 ASSERT((pd
->pd_ref_count
>= 0) ||
4638 (pd
->pd_aux_flags
& PD_GIVEN_TO_ULPS
));
4641 if (clist
->clist_map
[count
].map_state
!=
4642 PORT_DEVICE_INVALID
) {
4643 pd
->pd_aux_flags
|= PD_GIVEN_TO_ULPS
;
4646 mutex_exit(&pd
->pd_mutex
);
4652 * Sanity check for presence of OLD devices in the hash lists
4654 if (clist
->clist_size
) {
4655 ASSERT(clist
->clist_map
!= NULL
);
4656 for (count
= 0; count
< clist
->clist_len
; count
++) {
4657 if (clist
->clist_map
[count
].map_state
==
4658 PORT_DEVICE_INVALID
) {
4662 pd
= clist
->clist_map
[count
].map_pd
;
4665 mutex_enter(&pd
->pd_mutex
);
4666 pwwn
= pd
->pd_port_name
;
4667 d_id
= pd
->pd_port_id
;
4668 mutex_exit(&pd
->pd_mutex
);
4670 pd
= fctl_get_remote_port_by_pwwn(port
, &pwwn
);
4671 ASSERT(pd
!= clist
->clist_map
[count
].map_pd
);
4673 pd
= fctl_get_remote_port_by_did(port
,
4675 ASSERT(pd
!= clist
->clist_map
[count
].map_pd
);
4681 mutex_enter(&port
->fp_mutex
);
4683 if (state
== FC_STATE_ONLINE
) {
4684 if (--port
->fp_statec_busy
== 0) {
4685 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
4688 mutex_exit(&port
->fp_mutex
);
4690 (void) taskq_dispatch(port
->fp_taskq
, fctl_ulp_statec_cb
,
4693 FP_TRACE(FP_NHEAD1(4, 0), "fp_ulp_statec fired; Port=%p,"
4694 "state=%x, len=%d", port
, state
, listlen
);
4696 return (FC_SUCCESS
);
4701 * Send up a FC_STATE_DEVICE_CHANGE state notification to ULPs
4704 fp_ulp_devc_cb(fc_local_port_t
*port
, fc_portmap_t
*changelist
,
4705 uint32_t listlen
, uint32_t alloc_len
, int sleep
, int sync
)
4708 fc_port_clist_t
*clist
;
4710 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
4712 clist
= kmem_zalloc(sizeof (*clist
), sleep
);
4713 if (clist
== NULL
) {
4714 kmem_free(changelist
, alloc_len
* sizeof (*changelist
));
4718 clist
->clist_state
= FC_STATE_DEVICE_CHANGE
;
4720 mutex_enter(&port
->fp_mutex
);
4721 clist
->clist_flags
= port
->fp_topology
;
4722 mutex_exit(&port
->fp_mutex
);
4724 clist
->clist_port
= (opaque_t
)port
;
4725 clist
->clist_len
= listlen
;
4726 clist
->clist_size
= alloc_len
;
4727 clist
->clist_map
= changelist
;
4729 /* Send sysevents for target state changes */
4731 if (clist
->clist_size
) {
4733 fc_remote_port_t
*pd
;
4735 ASSERT(clist
->clist_map
!= NULL
);
4736 for (count
= 0; count
< clist
->clist_len
; count
++) {
4737 pd
= clist
->clist_map
[count
].map_pd
;
4740 * Bump reference counts on all fc_remote_port_t
4741 * structs in this list. We don't know when the task
4742 * will fire, and we don't need these fc_remote_port_t
4743 * structs going away behind our back.
4746 mutex_enter(&pd
->pd_mutex
);
4747 ASSERT((pd
->pd_ref_count
>= 0) ||
4748 (pd
->pd_aux_flags
& PD_GIVEN_TO_ULPS
));
4750 mutex_exit(&pd
->pd_mutex
);
4753 if (clist
->clist_map
[count
].map_state
==
4754 PORT_DEVICE_VALID
) {
4755 if (clist
->clist_map
[count
].map_type
==
4757 /* Update our state change counter */
4758 mutex_enter(&port
->fp_mutex
);
4759 port
->fp_last_change
++;
4760 mutex_exit(&port
->fp_mutex
);
4763 fp_log_target_event(port
,
4764 ESC_SUNFC_TARGET_ADD
,
4765 clist
->clist_map
[count
].map_pwwn
,
4766 clist
->clist_map
[count
].map_did
.
4770 } else if ((clist
->clist_map
[count
].map_type
==
4772 (clist
->clist_map
[count
].map_state
==
4773 PORT_DEVICE_INVALID
)) {
4774 /* Update our state change counter */
4775 mutex_enter(&port
->fp_mutex
);
4776 port
->fp_last_change
++;
4777 mutex_exit(&port
->fp_mutex
);
4780 * For removals, we don't decrement
4781 * pd_ref_count until after the ULP's
4782 * state change callback function has
4787 fp_log_target_event(port
,
4788 ESC_SUNFC_TARGET_REMOVE
,
4789 clist
->clist_map
[count
].map_pwwn
,
4790 clist
->clist_map
[count
].map_did
.port_id
);
4793 if (clist
->clist_map
[count
].map_state
!=
4794 PORT_DEVICE_INVALID
) {
4796 * Indicate that the ULPs are now aware of
4800 mutex_enter(&pd
->pd_mutex
);
4801 pd
->pd_aux_flags
|= PD_GIVEN_TO_ULPS
;
4802 mutex_exit(&pd
->pd_mutex
);
4807 * Sanity check for OLD devices in the hash lists
4809 if (pd
&& clist
->clist_map
[count
].map_state
==
4810 PORT_DEVICE_INVALID
) {
4814 mutex_enter(&pd
->pd_mutex
);
4815 pwwn
= pd
->pd_port_name
;
4816 d_id
= pd
->pd_port_id
;
4817 mutex_exit(&pd
->pd_mutex
);
4820 * This overwrites the 'pd' local variable.
4821 * Beware of this if 'pd' ever gets
4822 * referenced below this block.
4824 pd
= fctl_get_remote_port_by_pwwn(port
, &pwwn
);
4825 ASSERT(pd
!= clist
->clist_map
[count
].map_pd
);
4827 pd
= fctl_get_remote_port_by_did(port
,
4829 ASSERT(pd
!= clist
->clist_map
[count
].map_pd
);
4836 clist
->clist_wait
= 1;
4837 mutex_init(&clist
->clist_mutex
, NULL
, MUTEX_DRIVER
, NULL
);
4838 cv_init(&clist
->clist_cv
, NULL
, CV_DRIVER
, NULL
);
4841 ret
= taskq_dispatch(port
->fp_taskq
, fctl_ulp_statec_cb
, clist
, sleep
);
4843 mutex_enter(&clist
->clist_mutex
);
4844 while (clist
->clist_wait
) {
4845 cv_wait(&clist
->clist_cv
, &clist
->clist_mutex
);
4847 mutex_exit(&clist
->clist_mutex
);
4849 mutex_destroy(&clist
->clist_mutex
);
4850 cv_destroy(&clist
->clist_cv
);
4851 kmem_free(clist
, sizeof (*clist
));
4855 FP_TRACE(FP_NHEAD1(4, 0), "fp_ulp_devc dispatch failed; "
4857 kmem_free(clist
->clist_map
,
4858 sizeof (*(clist
->clist_map
)) * clist
->clist_size
);
4859 kmem_free(clist
, sizeof (*clist
));
4861 FP_TRACE(FP_NHEAD1(4, 0), "fp_ulp_devc fired; port=%p, len=%d",
4865 return (FC_SUCCESS
);
4870 * Perform PLOGI to the group of devices for ULPs
4873 fp_plogi_group(fc_local_port_t
*port
, job_request_t
*job
)
4881 fc_remote_node_t
*node
;
4882 fc_remote_port_t
*pd
;
4883 fc_remote_port_t
*tmp_pd
;
4884 fc_packet_t
*ulp_pkt
;
4885 la_els_logi_t
*els_data
;
4888 FP_TRACE(FP_NHEAD1(1, 0), "fp_plogi_group begin; port=%p, job=%p",
4892 listlen
= job
->job_ulp_listlen
;
4893 job
->job_counter
= job
->job_ulp_listlen
;
4895 mutex_enter(&port
->fp_mutex
);
4896 offline
= (port
->fp_statec_busy
||
4897 FC_PORT_STATE_MASK(port
->fp_state
) == FC_STATE_OFFLINE
) ? 1 : 0;
4898 mutex_exit(&port
->fp_mutex
);
4900 for (count
= 0; count
< listlen
; count
++) {
4901 ASSERT(job
->job_ulp_pkts
[count
]->pkt_rsplen
>=
4902 sizeof (la_els_logi_t
));
4904 ulp_pkt
= job
->job_ulp_pkts
[count
];
4905 pd
= ulp_pkt
->pkt_pd
;
4906 d_id
= ulp_pkt
->pkt_cmd_fhdr
.d_id
;
4911 ulp_pkt
->pkt_state
= FC_PKT_PORT_OFFLINE
;
4912 ulp_pkt
->pkt_reason
= FC_REASON_OFFLINE
;
4913 ulp_pkt
->pkt_pd
= NULL
;
4914 ulp_pkt
->pkt_comp(ulp_pkt
);
4916 job
->job_ulp_pkts
[count
] = NULL
;
4923 pd
= fctl_get_remote_port_by_did(port
, d_id
);
4926 ulp_pkt
->pkt_state
= FC_PKT_FAILURE
;
4929 mutex_enter(&pd
->pd_mutex
);
4930 if (pd
->pd_flags
== PD_ELS_IN_PROGRESS
) {
4931 mutex_exit(&pd
->pd_mutex
);
4932 ulp_pkt
->pkt_state
= FC_PKT_ELS_IN_PROGRESS
;
4934 ulp_pkt
->pkt_comp(ulp_pkt
);
4935 job
->job_ulp_pkts
[count
] = NULL
;
4938 ulp_pkt
->pkt_state
= FC_PKT_FAILURE
;
4939 mutex_exit(&pd
->pd_mutex
);
4944 switch (ulp_pkt
->pkt_state
) {
4945 case FC_PKT_ELS_IN_PROGRESS
:
4946 ulp_pkt
->pkt_reason
= FC_REASON_OFFLINE
;
4948 case FC_PKT_LOCAL_RJT
:
4950 ulp_pkt
->pkt_comp(ulp_pkt
);
4951 job
->job_ulp_pkts
[count
] = NULL
;
4959 * Validate the pd corresponding to the d_id passed
4962 tmp_pd
= fctl_get_remote_port_by_did(port
, d_id
);
4963 if ((tmp_pd
== NULL
) || (pd
!= tmp_pd
)) {
4965 ulp_pkt
->pkt_state
= FC_PKT_FAILURE
;
4966 ulp_pkt
->pkt_reason
= FC_REASON_NO_CONNECTION
;
4967 ulp_pkt
->pkt_pd
= NULL
;
4968 ulp_pkt
->pkt_comp(ulp_pkt
);
4969 job
->job_ulp_pkts
[count
] = NULL
;
4974 FP_TRACE(FP_NHEAD1(3, 0), "fp_plogi_group contd; "
4975 "port=%p, pd=%p", port
, pd
);
4977 mutex_enter(&pd
->pd_mutex
);
4979 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
4981 els_data
= (la_els_logi_t
*)ulp_pkt
->pkt_resp
;
4983 ls_code
.ls_code
= LA_ELS_ACC
;
4986 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
4987 (uint8_t *)&ls_code
, (uint8_t *)&els_data
->ls_code
,
4988 sizeof (ls_code_t
), DDI_DEV_AUTOINCR
);
4990 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
4991 (uint8_t *)&pd
->pd_csp
,
4992 (uint8_t *)&els_data
->common_service
,
4993 sizeof (pd
->pd_csp
), DDI_DEV_AUTOINCR
);
4995 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
4996 (uint8_t *)&pd
->pd_port_name
,
4997 (uint8_t *)&els_data
->nport_ww_name
,
4998 sizeof (pd
->pd_port_name
), DDI_DEV_AUTOINCR
);
5000 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
5001 (uint8_t *)&pd
->pd_clsp1
,
5002 (uint8_t *)&els_data
->class_1
,
5003 sizeof (pd
->pd_clsp1
), DDI_DEV_AUTOINCR
);
5005 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
5006 (uint8_t *)&pd
->pd_clsp2
,
5007 (uint8_t *)&els_data
->class_2
,
5008 sizeof (pd
->pd_clsp2
), DDI_DEV_AUTOINCR
);
5010 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
5011 (uint8_t *)&pd
->pd_clsp3
,
5012 (uint8_t *)&els_data
->class_3
,
5013 sizeof (pd
->pd_clsp3
), DDI_DEV_AUTOINCR
);
5015 node
= pd
->pd_remote_nodep
;
5016 pd
->pd_login_count
++;
5017 pd
->pd_flags
= PD_IDLE
;
5018 ulp_pkt
->pkt_pd
= pd
;
5019 mutex_exit(&pd
->pd_mutex
);
5021 mutex_enter(&node
->fd_mutex
);
5022 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
5023 (uint8_t *)&node
->fd_node_name
,
5024 (uint8_t *)(&els_data
->node_ww_name
),
5025 sizeof (node
->fd_node_name
), DDI_DEV_AUTOINCR
);
5027 FC_SET_CMD(pd
->pd_port
, ulp_pkt
->pkt_resp_acc
,
5028 (uint8_t *)&node
->fd_vv
,
5029 (uint8_t *)(&els_data
->vendor_version
),
5030 sizeof (node
->fd_vv
), DDI_DEV_AUTOINCR
);
5032 mutex_exit(&node
->fd_mutex
);
5033 ulp_pkt
->pkt_state
= FC_PKT_SUCCESS
;
5036 ulp_pkt
->pkt_state
= FC_PKT_FAILURE
; /* reset later */
5037 mutex_exit(&pd
->pd_mutex
);
5040 if (ulp_pkt
->pkt_state
!= FC_PKT_FAILURE
) {
5041 ulp_pkt
->pkt_comp(ulp_pkt
);
5042 job
->job_ulp_pkts
[count
] = NULL
;
5047 if (done
== listlen
) {
5053 job
->job_counter
= listlen
- done
;
5055 for (count
= 0; count
< listlen
; count
++) {
5058 if ((ulp_pkt
= job
->job_ulp_pkts
[count
]) == NULL
) {
5062 ASSERT(ulp_pkt
->pkt_state
== FC_PKT_FAILURE
);
5064 cmd_flags
= FP_CMD_PLOGI_RETAIN
;
5066 d_id
= ulp_pkt
->pkt_cmd_fhdr
.d_id
;
5069 pd
= fctl_get_remote_port_by_did(port
, d_id
);
5072 * We need to properly adjust the port device
5073 * reference counter before we assign the pd
5074 * to the ULP packets port device pointer.
5076 if (pd
!= NULL
&& ulp_pkt
->pkt_pd
== NULL
) {
5077 mutex_enter(&pd
->pd_mutex
);
5079 mutex_exit(&pd
->pd_mutex
);
5080 FP_TRACE(FP_NHEAD1(3, 0),
5081 "fp_plogi_group: DID = 0x%x using new pd %p \
5082 old pd NULL\n", d_id
, pd
);
5083 } else if (pd
!= NULL
&& ulp_pkt
->pkt_pd
!= NULL
&&
5084 ulp_pkt
->pkt_pd
!= pd
) {
5085 mutex_enter(&pd
->pd_mutex
);
5087 mutex_exit(&pd
->pd_mutex
);
5088 mutex_enter(&ulp_pkt
->pkt_pd
->pd_mutex
);
5089 ulp_pkt
->pkt_pd
->pd_ref_count
--;
5090 mutex_exit(&ulp_pkt
->pkt_pd
->pd_mutex
);
5091 FP_TRACE(FP_NHEAD1(3, 0),
5092 "fp_plogi_group: DID = 0x%x pkt_pd %p != pd %p\n",
5093 d_id
, ulp_pkt
->pkt_pd
, pd
);
5094 } else if (pd
== NULL
&& ulp_pkt
->pkt_pd
!= NULL
) {
5095 mutex_enter(&ulp_pkt
->pkt_pd
->pd_mutex
);
5096 ulp_pkt
->pkt_pd
->pd_ref_count
--;
5097 mutex_exit(&ulp_pkt
->pkt_pd
->pd_mutex
);
5098 FP_TRACE(FP_NHEAD1(3, 0),
5099 "fp_plogi_group: DID = 0x%x pd is NULL and \
5100 pkt_pd = %p\n", d_id
, ulp_pkt
->pkt_pd
);
5103 ulp_pkt
->pkt_pd
= pd
;
5106 mutex_enter(&pd
->pd_mutex
);
5107 d_id
= pd
->pd_port_id
.port_id
;
5108 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
5109 mutex_exit(&pd
->pd_mutex
);
5111 d_id
= ulp_pkt
->pkt_cmd_fhdr
.d_id
;
5113 pd
= fctl_get_remote_port_by_did(port
, d_id
);
5117 * In the Fabric topology, use NS to create
5118 * port device, and if that fails still try
5119 * with PLOGI - which will make yet another
5120 * attempt to create after successful PLOGI
5122 mutex_enter(&port
->fp_mutex
);
5123 if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
5124 mutex_exit(&port
->fp_mutex
);
5125 pd
= fp_create_remote_port_by_ns(port
,
5128 cmd_flags
|= FP_CMD_DELDEV_ON_ERROR
;
5130 mutex_enter(&pd
->pd_mutex
);
5131 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
5132 mutex_exit(&pd
->pd_mutex
);
5134 FP_TRACE(FP_NHEAD1(3, 0),
5136 " NS created PD port=%p, job=%p,"
5137 " pd=%p", port
, job
, pd
);
5140 mutex_exit(&port
->fp_mutex
);
5142 if ((ulp_pkt
->pkt_pd
== NULL
) && (pd
!= NULL
)) {
5143 FP_TRACE(FP_NHEAD1(3, 0),
5145 "ulp_pkt's pd is NULL, get a pd %p",
5147 mutex_enter(&pd
->pd_mutex
);
5149 mutex_exit(&pd
->pd_mutex
);
5151 ulp_pkt
->pkt_pd
= pd
;
5154 rval
= fp_port_login(port
, d_id
, job
, cmd_flags
,
5155 KM_SLEEP
, pd
, ulp_pkt
);
5157 if (rval
== FC_SUCCESS
) {
5161 if (rval
== FC_STATEC_BUSY
) {
5162 ulp_pkt
->pkt_state
= FC_PKT_PORT_OFFLINE
;
5163 ulp_pkt
->pkt_reason
= FC_REASON_OFFLINE
;
5165 ulp_pkt
->pkt_state
= FC_PKT_FAILURE
;
5169 mutex_enter(&pd
->pd_mutex
);
5170 pd
->pd_flags
= PD_IDLE
;
5171 mutex_exit(&pd
->pd_mutex
);
5174 if (cmd_flags
& FP_CMD_DELDEV_ON_ERROR
) {
5177 FP_TRACE(FP_NHEAD1(3, 0), "fp_plogi_group: NS created,"
5178 " PD removed; port=%p, job=%p", port
, job
);
5180 mutex_enter(&pd
->pd_mutex
);
5182 node
= pd
->pd_remote_nodep
;
5183 mutex_exit(&pd
->pd_mutex
);
5185 ASSERT(node
!= NULL
);
5187 if (fctl_destroy_remote_port(port
, pd
) == 0) {
5188 fctl_destroy_remote_node(node
);
5190 ulp_pkt
->pkt_pd
= NULL
;
5192 ulp_pkt
->pkt_comp(ulp_pkt
);
5199 FP_TRACE(FP_NHEAD1(1, 0), "fp_plogi_group end: port=%p, job=%p",
5205 * Name server request initialization
5208 fp_ns_init(fc_local_port_t
*port
, job_request_t
*job
, int sleep
)
5214 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
5216 job
->job_counter
= 1;
5217 job
->job_result
= FC_SUCCESS
;
5219 rval
= fp_port_login(port
, 0xFFFFFC, job
, FP_CMD_PLOGI_RETAIN
,
5220 KM_SLEEP
, NULL
, NULL
);
5222 if (rval
!= FC_SUCCESS
) {
5223 mutex_enter(&port
->fp_mutex
);
5224 port
->fp_topology
= FC_TOP_NO_NS
;
5225 mutex_exit(&port
->fp_mutex
);
5231 if (job
->job_result
!= FC_SUCCESS
) {
5232 mutex_enter(&port
->fp_mutex
);
5233 port
->fp_topology
= FC_TOP_NO_NS
;
5234 mutex_exit(&port
->fp_mutex
);
5239 * At this time, we'll do NS registration for objects in the
5240 * ns_reg_cmds (see top of this file) array.
5242 * Each time a ULP module registers with the transport, the
5243 * appropriate fc4 bit is set fc4 types and registered with
5244 * the NS for this support. Also, ULPs and FC admin utilities
5245 * may do registration for objects like IP address, symbolic
5246 * port/node name, Initial process associator at run time.
5248 size
= sizeof (ns_reg_cmds
) / sizeof (ns_reg_cmds
[0]);
5249 job
->job_counter
= size
;
5250 job
->job_result
= FC_SUCCESS
;
5252 for (count
= 0; count
< size
; count
++) {
5253 if (fp_ns_reg(port
, NULL
, ns_reg_cmds
[count
],
5254 job
, 0, sleep
) != FC_SUCCESS
) {
5262 job
->job_result
= FC_SUCCESS
;
5264 (void) fp_ns_get_devcount(port
, job
, 0, KM_SLEEP
);
5266 if (port
->fp_dev_count
< FP_MAX_DEVICES
) {
5267 (void) fp_ns_get_devcount(port
, job
, 1, KM_SLEEP
);
5270 job
->job_counter
= 1;
5272 if (fp_ns_scr(port
, job
, FC_SCR_FULL_REGISTRATION
,
5273 sleep
) == FC_SUCCESS
) {
5280 * Name server finish:
5281 * Unregister for RSCNs
5282 * Unregister all the host port objects in the Name Server
5283 * Perform LOGO with the NS;
5286 fp_ns_fini(fc_local_port_t
*port
, job_request_t
*job
)
5292 la_els_logo_t payload
;
5294 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
5296 job
->job_counter
= 1;
5298 if (fp_ns_scr(port
, job
, FC_SCR_CLEAR_REGISTRATION
, KM_SLEEP
) !=
5304 job
->job_counter
= 1;
5306 if (fp_ns_reg(port
, NULL
, NS_DA_ID
, job
, 0, KM_SLEEP
) != FC_SUCCESS
) {
5311 job
->job_counter
= 1;
5313 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logo_t
),
5314 FP_PORT_IDENTIFIER_LEN
, KM_SLEEP
, NULL
);
5315 pkt
= &cmd
->cmd_pkt
;
5317 mutex_enter(&port
->fp_mutex
);
5318 class = port
->fp_ns_login_class
;
5319 s_id
= port
->fp_port_id
.port_id
;
5320 payload
.nport_id
= port
->fp_port_id
;
5321 mutex_exit(&port
->fp_mutex
);
5323 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| class;
5324 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
5325 cmd
->cmd_flags
= FP_CMD_PLOGI_DONT_CARE
;
5326 cmd
->cmd_retry_count
= 1;
5327 cmd
->cmd_ulp_pkt
= NULL
;
5329 if (port
->fp_npiv_type
== FC_NPIV_PORT
) {
5330 fp_els_init(cmd
, s_id
, 0xFFFFFE, fp_logo_intr
, job
);
5332 fp_els_init(cmd
, s_id
, 0xFFFFFC, fp_logo_intr
, job
);
5335 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
5337 payload
.ls_code
.ls_code
= LA_ELS_LOGO
;
5338 payload
.ls_code
.mbz
= 0;
5339 payload
.nport_ww_name
= port
->fp_service_params
.nport_ww_name
;
5341 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
5342 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
5344 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
) {
5352 * NS Registration function.
5354 * It should be seriously noted that FC-GS-2 currently doesn't support
5355 * an Object Registration by a D_ID other than the owner of the object.
5356 * What we are aiming at currently is to at least allow Symbolic Node/Port
5357 * Name registration for any N_Port Identifier by the host software.
5359 * Anyway, if the second argument (fc_remote_port_t *) is NULL, this
5360 * function treats the request as Host NS Object.
5363 fp_ns_reg(fc_local_port_t
*port
, fc_remote_port_t
*pd
, uint16_t cmd_code
,
5364 job_request_t
*job
, int polled
, int sleep
)
5372 mutex_enter(&port
->fp_mutex
);
5373 s_id
= port
->fp_port_id
;
5374 mutex_exit(&port
->fp_mutex
);
5376 mutex_enter(&pd
->pd_mutex
);
5377 s_id
= pd
->pd_port_id
;
5378 mutex_exit(&pd
->pd_mutex
);
5382 job
->job_counter
= 1;
5390 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5391 sizeof (ns_rxn_req_t
), sizeof (fc_reg_resp_t
), sleep
, NULL
);
5395 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5396 pkt
= &cmd
->cmd_pkt
;
5399 rxn
.rxn_xname
= ((cmd_code
== NS_RPN_ID
) ?
5400 (port
->fp_service_params
.nport_ww_name
) :
5401 (port
->fp_service_params
.node_ww_name
));
5403 if (cmd_code
== NS_RPN_ID
) {
5404 mutex_enter(&pd
->pd_mutex
);
5405 rxn
.rxn_xname
= pd
->pd_port_name
;
5406 mutex_exit(&pd
->pd_mutex
);
5408 fc_remote_node_t
*node
;
5410 mutex_enter(&pd
->pd_mutex
);
5411 node
= pd
->pd_remote_nodep
;
5412 mutex_exit(&pd
->pd_mutex
);
5414 mutex_enter(&node
->fd_mutex
);
5415 rxn
.rxn_xname
= node
->fd_node_name
;
5416 mutex_exit(&node
->fd_mutex
);
5419 rxn
.rxn_port_id
= s_id
;
5421 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&rxn
,
5422 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5423 sizeof (rxn
), DDI_DEV_AUTOINCR
);
5431 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5432 sizeof (ns_rcos_t
), sizeof (fc_reg_resp_t
), sleep
, NULL
);
5436 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5437 pkt
= &cmd
->cmd_pkt
;
5440 rcos
.rcos_cos
= port
->fp_cos
;
5442 mutex_enter(&pd
->pd_mutex
);
5443 rcos
.rcos_cos
= pd
->pd_cos
;
5444 mutex_exit(&pd
->pd_mutex
);
5446 rcos
.rcos_port_id
= s_id
;
5448 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&rcos
,
5449 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5450 sizeof (rcos
), DDI_DEV_AUTOINCR
);
5458 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5459 sizeof (ns_rfc_type_t
), sizeof (fc_reg_resp_t
), sleep
,
5464 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5465 pkt
= &cmd
->cmd_pkt
;
5468 mutex_enter(&port
->fp_mutex
);
5469 bcopy(port
->fp_fc4_types
, rfc
.rfc_types
,
5470 sizeof (port
->fp_fc4_types
));
5471 mutex_exit(&port
->fp_mutex
);
5473 mutex_enter(&pd
->pd_mutex
);
5474 bcopy(pd
->pd_fc4types
, rfc
.rfc_types
,
5475 sizeof (pd
->pd_fc4types
));
5476 mutex_exit(&pd
->pd_mutex
);
5478 rfc
.rfc_port_id
= s_id
;
5480 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&rfc
,
5481 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5482 sizeof (rfc
), DDI_DEV_AUTOINCR
);
5493 mutex_enter(&port
->fp_mutex
);
5494 name_len
= port
->fp_sym_port_namelen
;
5495 mutex_exit(&port
->fp_mutex
);
5497 mutex_enter(&pd
->pd_mutex
);
5498 name_len
= pd
->pd_spn_len
;
5499 mutex_exit(&pd
->pd_mutex
);
5502 pl_size
= sizeof (fc_portid_t
) + name_len
+ 1;
5504 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) + pl_size
,
5505 sizeof (fc_reg_resp_t
), sleep
, NULL
);
5510 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5512 pkt
= &cmd
->cmd_pkt
;
5516 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&spn
, (uint8_t *)
5517 (pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)), sizeof (spn
),
5519 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&name_len
,
5520 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)
5521 + sizeof (fc_portid_t
)), 1, DDI_DEV_AUTOINCR
);
5524 mutex_enter(&port
->fp_mutex
);
5525 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
,
5526 (uint8_t *)port
->fp_sym_port_name
, (uint8_t *)
5527 (pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
) +
5528 sizeof (spn
) + 1), name_len
, DDI_DEV_AUTOINCR
);
5529 mutex_exit(&port
->fp_mutex
);
5531 mutex_enter(&pd
->pd_mutex
);
5532 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
,
5533 (uint8_t *)pd
->pd_spn
,
5534 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
) +
5535 sizeof (spn
) + 1), name_len
, DDI_DEV_AUTOINCR
);
5536 mutex_exit(&pd
->pd_mutex
);
5544 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5545 sizeof (ns_rpt_t
), sizeof (fc_reg_resp_t
), sleep
, NULL
);
5549 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5550 pkt
= &cmd
->cmd_pkt
;
5553 rpt
.rpt_type
= port
->fp_port_type
;
5555 mutex_enter(&pd
->pd_mutex
);
5556 rpt
.rpt_type
= pd
->pd_porttype
;
5557 mutex_exit(&pd
->pd_mutex
);
5559 rpt
.rpt_port_id
= s_id
;
5561 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&rpt
,
5562 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5563 sizeof (rpt
), DDI_DEV_AUTOINCR
);
5571 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5572 sizeof (ns_rip_t
), sizeof (fc_reg_resp_t
), sleep
, NULL
);
5576 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5577 pkt
= &cmd
->cmd_pkt
;
5581 port
->fp_service_params
.node_ww_name
;
5582 bcopy(port
->fp_ip_addr
, rip
.rip_ip_addr
,
5583 sizeof (port
->fp_ip_addr
));
5585 fc_remote_node_t
*node
;
5588 * The most correct implementation should have the IP
5589 * address in the fc_remote_node_t structure; I believe
5590 * Node WWN and IP address should have one to one
5591 * correlation (but guess what this is changing in
5592 * FC-GS-2 latest draft)
5594 mutex_enter(&pd
->pd_mutex
);
5595 node
= pd
->pd_remote_nodep
;
5596 bcopy(pd
->pd_ip_addr
, rip
.rip_ip_addr
,
5597 sizeof (pd
->pd_ip_addr
));
5598 mutex_exit(&pd
->pd_mutex
);
5600 mutex_enter(&node
->fd_mutex
);
5601 rip
.rip_node_name
= node
->fd_node_name
;
5602 mutex_exit(&node
->fd_mutex
);
5605 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&rip
,
5606 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5607 sizeof (rip
), DDI_DEV_AUTOINCR
);
5615 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5616 sizeof (ns_ipa_t
), sizeof (fc_reg_resp_t
), sleep
, NULL
);
5620 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5621 pkt
= &cmd
->cmd_pkt
;
5625 port
->fp_service_params
.node_ww_name
;
5626 bcopy(port
->fp_ipa
, ipa
.ipa_value
,
5627 sizeof (port
->fp_ipa
));
5629 fc_remote_node_t
*node
;
5631 mutex_enter(&pd
->pd_mutex
);
5632 node
= pd
->pd_remote_nodep
;
5633 mutex_exit(&pd
->pd_mutex
);
5635 mutex_enter(&node
->fd_mutex
);
5636 ipa
.ipa_node_name
= node
->fd_node_name
;
5637 bcopy(node
->fd_ipa
, ipa
.ipa_value
,
5638 sizeof (node
->fd_ipa
));
5639 mutex_exit(&node
->fd_mutex
);
5642 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&ipa
,
5643 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5644 sizeof (ipa
), DDI_DEV_AUTOINCR
);
5653 fc_remote_node_t
*node
= NULL
;
5656 mutex_enter(&port
->fp_mutex
);
5657 name_len
= port
->fp_sym_node_namelen
;
5658 mutex_exit(&port
->fp_mutex
);
5660 mutex_enter(&pd
->pd_mutex
);
5661 node
= pd
->pd_remote_nodep
;
5662 mutex_exit(&pd
->pd_mutex
);
5664 mutex_enter(&node
->fd_mutex
);
5665 name_len
= node
->fd_snn_len
;
5666 mutex_exit(&node
->fd_mutex
);
5669 pl_size
= sizeof (la_wwn_t
) + name_len
+ 1;
5671 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5672 pl_size
, sizeof (fc_reg_resp_t
), sleep
, NULL
);
5676 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5678 pkt
= &cmd
->cmd_pkt
;
5680 bcopy(&port
->fp_service_params
.node_ww_name
,
5681 &snn
, sizeof (la_wwn_t
));
5684 mutex_enter(&port
->fp_mutex
);
5685 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
,
5686 (uint8_t *)port
->fp_sym_node_name
, (uint8_t *)
5687 (pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
) +
5688 sizeof (snn
) + 1), name_len
, DDI_DEV_AUTOINCR
);
5689 mutex_exit(&port
->fp_mutex
);
5691 ASSERT(node
!= NULL
);
5692 mutex_enter(&node
->fd_mutex
);
5693 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
,
5694 (uint8_t *)node
->fd_snn
,
5695 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
) +
5696 sizeof (snn
) + 1), name_len
, DDI_DEV_AUTOINCR
);
5697 mutex_exit(&node
->fd_mutex
);
5700 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&snn
,
5701 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5702 sizeof (snn
), DDI_DEV_AUTOINCR
);
5703 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&name_len
,
5704 (uint8_t *)(pkt
->pkt_cmd
5705 + sizeof (fc_ct_header_t
) + sizeof (snn
)),
5706 1, DDI_DEV_AUTOINCR
);
5716 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
5717 sizeof (ns_remall_t
), sizeof (fc_reg_resp_t
), sleep
, NULL
);
5723 fp_ct_init(port
, cmd
, NULL
, cmd_code
, NULL
, 0, 0, job
);
5724 pkt
= &cmd
->cmd_pkt
;
5726 ptr
= (char *)(&s_id
);
5731 #if defined(_BIT_FIELDS_LTOH)
5732 bcopy((caddr_t
)tmp
, (caddr_t
)(&rall
.rem_port_id
), 4);
5734 rall
.rem_port_id
= s_id
;
5736 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&rall
,
5737 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
5738 sizeof (rall
), DDI_DEV_AUTOINCR
);
5744 return (FC_FAILURE
);
5747 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
5749 if (rval
!= FC_SUCCESS
) {
5750 job
->job_result
= rval
;
5755 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
5766 * Common interrupt handler
5769 fp_common_intr(fc_packet_t
*pkt
, int iodone
)
5771 int rval
= FC_FAILURE
;
5773 fc_local_port_t
*port
;
5775 cmd
= pkt
->pkt_ulp_private
;
5776 port
= cmd
->cmd_port
;
5779 * Fail fast the upper layer requests if
5780 * a state change has occurred amidst.
5782 mutex_enter(&port
->fp_mutex
);
5783 if (cmd
->cmd_ulp_pkt
!= NULL
&& port
->fp_statec_busy
) {
5784 mutex_exit(&port
->fp_mutex
);
5785 cmd
->cmd_ulp_pkt
->pkt_state
= FC_PKT_PORT_OFFLINE
;
5786 cmd
->cmd_ulp_pkt
->pkt_reason
= FC_REASON_OFFLINE
;
5787 } else if (!(port
->fp_soft_state
&
5788 (FP_SOFT_IN_DETACH
| FP_DETACH_INPROGRESS
))) {
5789 mutex_exit(&port
->fp_mutex
);
5791 switch (pkt
->pkt_state
) {
5792 case FC_PKT_LOCAL_BSY
:
5793 case FC_PKT_FABRIC_BSY
:
5794 case FC_PKT_NPORT_BSY
:
5795 case FC_PKT_TIMEOUT
:
5796 cmd
->cmd_retry_interval
= (pkt
->pkt_state
==
5797 FC_PKT_TIMEOUT
) ? 0 : fp_retry_delay
;
5798 rval
= fp_retry_cmd(pkt
);
5801 case FC_PKT_FABRIC_RJT
:
5802 case FC_PKT_NPORT_RJT
:
5803 case FC_PKT_LOCAL_RJT
:
5807 rval
= fp_handle_reject(pkt
);
5811 if (pkt
->pkt_resp_resid
) {
5812 cmd
->cmd_retry_interval
= 0;
5813 rval
= fp_retry_cmd(pkt
);
5818 mutex_exit(&port
->fp_mutex
);
5821 if (rval
!= FC_SUCCESS
&& iodone
) {
5831 * Some not so long winding theory on point to point topology:
5833 * In the ACC payload, if the D_ID is ZERO and the common service
5834 * parameters indicate N_Port, then the topology is POINT TO POINT.
5836 * In a point to point topology with an N_Port, during Fabric Login,
5837 * the destination N_Port will check with our WWN and decide if it
5838 * needs to issue PLOGI or not. That means, FLOGI could potentially
5839 * trigger an unsolicited PLOGI from an N_Port. The Unsolicited
5840 * PLOGI creates the device handles.
5842 * Assuming that the host port WWN is greater than the other N_Port
5843 * WWN, then we become the master (be aware that this isn't the word
5844 * used in the FC standards) and initiate the PLOGI.
5848 fp_flogi_intr(fc_packet_t
*pkt
)
5855 fc_local_port_t
*port
;
5859 fc_remote_port_t
*pd
;
5864 cmd
= pkt
->pkt_ulp_private
;
5865 port
= cmd
->cmd_port
;
5867 mutex_enter(&port
->fp_mutex
);
5868 port
->fp_out_fpcmds
--;
5869 mutex_exit(&port
->fp_mutex
);
5871 FP_TRACE(FP_NHEAD1(1, 0), "fp_flogi_intr; port=%p, pkt=%p, state=%x",
5872 port
, pkt
, pkt
->pkt_state
);
5874 if (FP_IS_PKT_ERROR(pkt
)) {
5875 (void) fp_common_intr(pkt
, 1);
5880 * Currently, we don't need to swap bytes here because qlc is faking the
5881 * response for us and so endianness is getting taken care of. But we
5882 * have to fix this and generalize this at some point
5884 acc
= (la_els_logi_t
*)pkt
->pkt_resp
;
5886 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&resp
, (uint8_t *)acc
,
5887 sizeof (resp
), DDI_DEV_AUTOINCR
);
5889 ASSERT(resp
.ls_code
== LA_ELS_ACC
);
5890 if (resp
.ls_code
!= LA_ELS_ACC
) {
5891 (void) fp_common_intr(pkt
, 1);
5895 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&csp
,
5896 (uint8_t *)&acc
->common_service
, sizeof (csp
), DDI_DEV_AUTOINCR
);
5898 f_port
= FP_IS_F_PORT(csp
.cmn_features
) ? 1 : 0;
5900 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
5902 mutex_enter(&port
->fp_mutex
);
5903 state
= FC_PORT_STATE_MASK(port
->fp_state
);
5904 mutex_exit(&port
->fp_mutex
);
5907 if (state
!= FC_STATE_LOOP
) {
5908 swwn
= &port
->fp_service_params
.nport_ww_name
;
5910 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&dwwn
,
5911 (uint8_t *)&acc
->nport_ww_name
, sizeof (la_wwn_t
),
5914 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&nwwn
,
5915 (uint8_t *)&acc
->node_ww_name
, sizeof (la_wwn_t
),
5918 mutex_enter(&port
->fp_mutex
);
5920 port
->fp_topology
= FC_TOP_PT_PT
;
5921 port
->fp_total_devices
= 1;
5922 if (fctl_wwn_cmp(swwn
, &dwwn
) >= 0) {
5923 port
->fp_ptpt_master
= 1;
5925 * Let us choose 'X' as S_ID and 'Y'
5926 * as D_ID and that'll work; hopefully
5927 * If not, it will get changed.
5929 s_id
= port
->fp_instance
+ FP_DEFAULT_SID
;
5930 d_id
= port
->fp_instance
+ FP_DEFAULT_DID
;
5931 port
->fp_port_id
.port_id
= s_id
;
5932 mutex_exit(&port
->fp_mutex
);
5934 FP_TRACE(FP_NHEAD1(1, 0), "fp_flogi_intr: fp %x"
5935 "pd %x", port
->fp_port_id
.port_id
, d_id
);
5936 pd
= fctl_create_remote_port(port
,
5937 &nwwn
, &dwwn
, d_id
, PD_PLOGI_INITIATOR
,
5940 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
,
5941 0, NULL
, "couldn't create device"
5947 cmd
->cmd_pkt
.pkt_tran_flags
=
5948 pkt
->pkt_tran_flags
;
5949 cmd
->cmd_pkt
.pkt_tran_type
= pkt
->pkt_tran_type
;
5950 cmd
->cmd_flags
= FP_CMD_PLOGI_RETAIN
;
5951 cmd
->cmd_retry_count
= fp_retry_count
;
5953 fp_xlogi_init(port
, cmd
, s_id
, d_id
,
5954 fp_plogi_intr
, cmd
->cmd_job
, LA_ELS_PLOGI
);
5956 (&cmd
->cmd_pkt
)->pkt_pd
= pd
;
5959 * We've just created this fc_remote_port_t, and
5960 * we're about to use it to send a PLOGI, so
5961 * bump the reference count right now. When
5962 * the packet is freed, the reference count will
5963 * be decremented. The ULP may also start using
5964 * it, so mark it as given away as well.
5967 pd
->pd_aux_flags
|= PD_GIVEN_TO_ULPS
;
5969 if (fp_sendcmd(port
, cmd
,
5970 port
->fp_fca_handle
) == FC_SUCCESS
) {
5975 * The device handles will be created when the
5976 * unsolicited PLOGI is completed successfully
5978 port
->fp_ptpt_master
= 0;
5979 mutex_exit(&port
->fp_mutex
);
5982 pkt
->pkt_state
= FC_PKT_FAILURE
;
5985 mutex_enter(&port
->fp_mutex
);
5986 if (state
== FC_STATE_LOOP
) {
5987 port
->fp_topology
= FC_TOP_PUBLIC_LOOP
;
5989 port
->fp_topology
= FC_TOP_FABRIC
;
5991 FC_GET_RSP(port
, pkt
->pkt_resp_acc
,
5992 (uint8_t *)&port
->fp_fabric_name
,
5993 (uint8_t *)&acc
->node_ww_name
,
5997 port
->fp_port_id
.port_id
= pkt
->pkt_resp_fhdr
.d_id
;
5998 mutex_exit(&port
->fp_mutex
);
6000 pkt
->pkt_state
= FC_PKT_FAILURE
;
6008 * Handle solicited PLOGI response
6011 fp_plogi_intr(fc_packet_t
*pkt
)
6018 fc_local_port_t
*port
;
6019 fc_remote_port_t
*pd
;
6025 cmd
= pkt
->pkt_ulp_private
;
6026 port
= cmd
->cmd_port
;
6027 d_id
= pkt
->pkt_cmd_fhdr
.d_id
;
6030 ASSERT(cmd
->cmd_job
&& cmd
->cmd_job
->job_counter
);
6033 FP_TRACE(FP_NHEAD1(3, 0), "fp_plogi_intr: port=%p, job=%p, d_id=%x,"
6034 " jcount=%d pkt=%p, state=%x", port
, cmd
->cmd_job
, d_id
,
6035 cmd
->cmd_job
->job_counter
, pkt
, pkt
->pkt_state
);
6038 * Bail out early on ULP initiated requests if the
6039 * state change has occurred
6041 mutex_enter(&port
->fp_mutex
);
6042 port
->fp_out_fpcmds
--;
6043 bailout
= ((port
->fp_statec_busy
||
6044 FC_PORT_STATE_MASK(port
->fp_state
) == FC_STATE_OFFLINE
) &&
6045 cmd
->cmd_ulp_pkt
) ? 1 : 0;
6046 mutex_exit(&port
->fp_mutex
);
6048 if (FP_IS_PKT_ERROR(pkt
) || bailout
) {
6052 if (cmd
->cmd_ulp_pkt
) {
6053 cmd
->cmd_ulp_pkt
->pkt_state
= pkt
->pkt_state
;
6054 cmd
->cmd_ulp_pkt
->pkt_reason
= pkt
->pkt_reason
;
6055 cmd
->cmd_ulp_pkt
->pkt_action
= pkt
->pkt_action
;
6056 cmd
->cmd_ulp_pkt
->pkt_expln
= pkt
->pkt_expln
;
6060 * If an unsolicited cross login already created
6061 * a device speed up the discovery by not retrying
6062 * the command mindlessly.
6064 if (pkt
->pkt_pd
== NULL
&&
6065 fctl_get_remote_port_by_did(port
, d_id
) != NULL
) {
6070 if (pkt
->pkt_pd
!= NULL
) {
6071 giveup
= (pkt
->pkt_pd
->pd_recepient
==
6072 PD_PLOGI_RECEPIENT
) ? 1 : 0;
6075 * This pd is marked as plogi
6076 * recipient, stop retrying
6078 FP_TRACE(FP_NHEAD1(3, 0),
6079 "fp_plogi_intr: stop retry as"
6080 " a cross login was accepted"
6081 " from d_id=%x, port=%p.",
6088 if (fp_common_intr(pkt
, 0) == FC_SUCCESS
) {
6092 if ((pd
= fctl_get_remote_port_by_did(port
, d_id
)) != NULL
) {
6093 mutex_enter(&pd
->pd_mutex
);
6094 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
6097 mutex_exit(&pd
->pd_mutex
);
6100 mutex_enter(&port
->fp_mutex
);
6101 if (!bailout
&& !(skip_msg
&& port
->fp_statec_busy
) &&
6102 port
->fp_statec_busy
<= 1 &&
6103 pkt
->pkt_reason
!= FC_REASON_FCAL_OPN_FAIL
) {
6104 mutex_exit(&port
->fp_mutex
);
6106 * In case of Login Collisions, JNI HBAs returns the
6107 * FC pkt back to the Initiator with the state set to
6108 * FC_PKT_LS_RJT and reason to FC_REASON_LOGICAL_ERROR.
6109 * QLC HBAs handles such cases in the FW and doesnot
6110 * return the LS_RJT with Logical error when
6111 * login collision happens.
6113 if ((pkt
->pkt_state
!= FC_PKT_LS_RJT
) ||
6114 (pkt
->pkt_reason
!= FC_REASON_LOGICAL_ERROR
)) {
6115 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, pkt
,
6116 "PLOGI to %x failed", d_id
);
6118 FP_TRACE(FP_NHEAD2(9, 0),
6119 "PLOGI to %x failed. state=%x reason=%x.",
6120 d_id
, pkt
->pkt_state
, pkt
->pkt_reason
);
6122 mutex_exit(&port
->fp_mutex
);
6129 acc
= (la_els_logi_t
*)pkt
->pkt_resp
;
6131 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&resp
, (uint8_t *)acc
,
6132 sizeof (resp
), DDI_DEV_AUTOINCR
);
6134 ASSERT(resp
.ls_code
== LA_ELS_ACC
);
6135 if (resp
.ls_code
!= LA_ELS_ACC
) {
6136 (void) fp_common_intr(pkt
, 1);
6140 if (d_id
== FS_NAME_SERVER
|| d_id
== FS_FABRIC_CONTROLLER
) {
6141 mutex_enter(&port
->fp_mutex
);
6142 port
->fp_ns_login_class
= FC_TRAN_CLASS(pkt
->pkt_tran_flags
);
6143 mutex_exit(&port
->fp_mutex
);
6148 ASSERT(acc
== (la_els_logi_t
*)pkt
->pkt_resp
);
6150 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&pwwn
,
6151 (uint8_t *)&acc
->nport_ww_name
, sizeof (la_wwn_t
),
6154 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&nwwn
,
6155 (uint8_t *)&acc
->node_ww_name
, sizeof (la_wwn_t
),
6158 ASSERT(fctl_is_wwn_zero(&pwwn
) == FC_FAILURE
);
6159 ASSERT(fctl_is_wwn_zero(&nwwn
) == FC_FAILURE
);
6161 if ((pd
= pkt
->pkt_pd
) == NULL
) {
6162 pd
= fctl_get_remote_port_by_pwwn(port
, &pwwn
);
6164 FP_TRACE(FP_NHEAD2(1, 0), "fp_plogi_intr: fp %x pd %x",
6165 port
->fp_port_id
.port_id
, d_id
);
6166 pd
= fctl_create_remote_port(port
, &nwwn
, &pwwn
, d_id
,
6167 PD_PLOGI_INITIATOR
, KM_NOSLEEP
);
6169 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
6170 "couldn't create port device handles"
6176 fc_remote_port_t
*tmp_pd
;
6178 tmp_pd
= fctl_get_remote_port_by_did(port
, d_id
);
6179 if (tmp_pd
!= NULL
) {
6184 mutex_enter(&port
->fp_mutex
);
6185 mutex_enter(&pd
->pd_mutex
);
6186 if ((pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) ||
6187 (pd
->pd_aux_flags
& PD_LOGGED_OUT
)) {
6188 cmd
->cmd_flags
|= FP_CMD_PLOGI_RETAIN
;
6191 if (pd
->pd_type
== PORT_DEVICE_OLD
) {
6192 if (pd
->pd_port_id
.port_id
!= d_id
) {
6193 fctl_delist_did_table(port
, pd
);
6194 pd
->pd_type
= PORT_DEVICE_CHANGED
;
6195 pd
->pd_port_id
.port_id
= d_id
;
6197 pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
6201 if (pd
->pd_aux_flags
& PD_IN_DID_QUEUE
) {
6204 fc_wwn_to_str(&pd
->pd_port_name
, ww_name
);
6206 mutex_exit(&pd
->pd_mutex
);
6207 mutex_exit(&port
->fp_mutex
);
6208 FP_TRACE(FP_NHEAD2(9, 0),
6209 "Possible Duplicate name or address"
6210 " identifiers in the PLOGI response"
6211 " D_ID=%x, PWWN=%s: Please check the"
6212 " configuration", d_id
, ww_name
);
6216 fctl_enlist_did_table(port
, pd
);
6217 pd
->pd_aux_flags
&= ~PD_LOGGED_OUT
;
6218 mutex_exit(&pd
->pd_mutex
);
6219 mutex_exit(&port
->fp_mutex
);
6222 fc_remote_port_t
*tmp_pd
, *new_wwn_pd
;
6224 tmp_pd
= fctl_get_remote_port_by_did(port
, d_id
);
6225 new_wwn_pd
= fctl_get_remote_port_by_pwwn(port
, &pwwn
);
6227 mutex_enter(&port
->fp_mutex
);
6228 mutex_enter(&pd
->pd_mutex
);
6229 if (fctl_wwn_cmp(&pd
->pd_port_name
, &pwwn
) == 0) {
6230 FP_TRACE(FP_NHEAD1(3, 0), "fp_plogi_intr: d_id=%x,"
6231 " pd_state=%x pd_type=%x", d_id
, pd
->pd_state
,
6233 if ((pd
->pd_state
== PORT_DEVICE_LOGGED_IN
&&
6234 pd
->pd_type
== PORT_DEVICE_OLD
) ||
6235 (pd
->pd_aux_flags
& PD_LOGGED_OUT
)) {
6236 pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
6237 } else if (pd
->pd_state
!= PORT_DEVICE_LOGGED_IN
) {
6238 pd
->pd_type
= PORT_DEVICE_NEW
;
6244 fc_wwn_to_str(&pd
->pd_port_name
, old_name
);
6245 fc_wwn_to_str(&pwwn
, new_name
);
6247 FP_TRACE(FP_NHEAD1(9, 0),
6248 "fp_plogi_intr: PWWN of a device with D_ID=%x "
6249 "changed. New PWWN = %s, OLD PWWN = %s ; tmp_pd:%p "
6250 "pd:%p new_wwn_pd:%p, cmd_ulp_pkt:%p, bailout:0x%x",
6251 d_id
, new_name
, old_name
, tmp_pd
, pd
, new_wwn_pd
,
6252 cmd
->cmd_ulp_pkt
, bailout
);
6254 FP_TRACE(FP_NHEAD2(9, 0),
6255 "PWWN of a device with D_ID=%x changed."
6256 " New PWWN = %s, OLD PWWN = %s", d_id
,
6257 new_name
, old_name
);
6259 if (cmd
->cmd_ulp_pkt
&& !bailout
) {
6260 fc_remote_node_t
*rnodep
;
6261 fc_portmap_t
*changelist
;
6262 fc_portmap_t
*listptr
;
6264 /* # entries in changelist */
6266 fctl_delist_pwwn_table(port
, pd
);
6269 * Lets now check if there already is a pd with
6270 * this new WWN in the table. If so, we'll mark
6276 * There is another pd with in the pwwn
6277 * table with the same WWN that we got
6278 * in the PLOGI payload. We have to get
6279 * it out of the pwwn table, update the
6280 * pd's state (fp_fillout_old_map does
6281 * this for us) and add it to the
6282 * changelist that goes up to ULPs.
6284 * len is length of changelist and so
6291 * Odd case where pwwn and did
6292 * tables are out of sync but
6293 * we will handle that too. See
6294 * more comments below.
6296 * One more device that ULPs
6297 * should know about and so len
6298 * gets incremented again.
6303 listptr
= changelist
= kmem_zalloc(len
*
6304 sizeof (*changelist
), KM_SLEEP
);
6306 mutex_enter(&new_wwn_pd
->pd_mutex
);
6307 rnodep
= new_wwn_pd
->pd_remote_nodep
;
6308 mutex_exit(&new_wwn_pd
->pd_mutex
);
6311 * Hold the fd_mutex since
6312 * fctl_copy_portmap_held expects it.
6313 * Preserve lock hierarchy by grabbing
6314 * fd_mutex before pd_mutex
6317 mutex_enter(&rnodep
->fd_mutex
);
6319 mutex_enter(&new_wwn_pd
->pd_mutex
);
6320 fp_fillout_old_map_held(listptr
++,
6322 mutex_exit(&new_wwn_pd
->pd_mutex
);
6324 mutex_exit(&rnodep
->fd_mutex
);
6329 * Lets ensure that the pwwn and did
6330 * tables are in sync. Ideally, we
6331 * should not find that these two pd's
6335 mutex_enter(&tmp_pd
->pd_mutex
);
6337 tmp_pd
->pd_remote_nodep
;
6338 mutex_exit(&tmp_pd
->pd_mutex
);
6340 /* As above grab fd_mutex */
6342 mutex_enter(&rnodep
->
6345 mutex_enter(&tmp_pd
->pd_mutex
);
6347 fp_fillout_old_map_held(
6348 listptr
++, tmp_pd
, 0);
6350 mutex_exit(&tmp_pd
->pd_mutex
);
6352 mutex_exit(&rnodep
->
6357 * Now add "pd" (not tmp_pd)
6358 * to fp_did_table to sync it up
6359 * with fp_pwwn_table
6361 * pd->pd_mutex is already held
6364 fctl_enlist_did_table(port
, pd
);
6367 listptr
= changelist
= kmem_zalloc(
6368 sizeof (*changelist
), KM_SLEEP
);
6371 ASSERT(changelist
!= NULL
);
6373 fp_fillout_changed_map(listptr
, pd
, &d_id
,
6375 fctl_enlist_pwwn_table(port
, pd
);
6377 mutex_exit(&pd
->pd_mutex
);
6378 mutex_exit(&port
->fp_mutex
);
6382 (void) fp_ulp_devc_cb(port
, changelist
, len
,
6383 len
, KM_NOSLEEP
, 0);
6389 if (pd
->pd_porttype
.port_type
== FC_NS_PORT_NL
) {
6392 if (pd
->pd_aux_flags
& PD_DISABLE_RELOGIN
) {
6393 pd
->pd_aux_flags
&= ~PD_LOGGED_OUT
;
6396 mutex_exit(&pd
->pd_mutex
);
6397 mutex_exit(&port
->fp_mutex
);
6399 if (tmp_pd
== NULL
) {
6400 mutex_enter(&port
->fp_mutex
);
6401 mutex_enter(&pd
->pd_mutex
);
6402 if (pd
->pd_aux_flags
& PD_IN_DID_QUEUE
) {
6405 fc_wwn_to_str(&pd
->pd_port_name
, ww_name
);
6406 mutex_exit(&pd
->pd_mutex
);
6407 mutex_exit(&port
->fp_mutex
);
6408 FP_TRACE(FP_NHEAD2(9, 0),
6409 "Possible Duplicate name or address"
6410 " identifiers in the PLOGI response"
6411 " D_ID=%x, PWWN=%s: Please check the"
6412 " configuration", d_id
, ww_name
);
6416 fctl_enlist_did_table(port
, pd
);
6417 pd
->pd_aux_flags
&= ~PD_LOGGED_OUT
;
6418 mutex_exit(&pd
->pd_mutex
);
6419 mutex_exit(&port
->fp_mutex
);
6422 fp_register_login(&pkt
->pkt_resp_acc
, pd
, acc
,
6423 FC_TRAN_CLASS(pkt
->pkt_tran_flags
));
6425 if (cmd
->cmd_ulp_pkt
) {
6426 cmd
->cmd_ulp_pkt
->pkt_state
= pkt
->pkt_state
;
6427 cmd
->cmd_ulp_pkt
->pkt_action
= pkt
->pkt_action
;
6428 cmd
->cmd_ulp_pkt
->pkt_expln
= pkt
->pkt_expln
;
6429 if (cmd
->cmd_ulp_pkt
->pkt_pd
== NULL
) {
6431 FP_TRACE(FP_NHEAD1(9, 0),
6433 "ulp_pkt's pd is NULL, get a pd %p",
6435 mutex_enter(&pd
->pd_mutex
);
6437 mutex_exit(&pd
->pd_mutex
);
6439 cmd
->cmd_ulp_pkt
->pkt_pd
= pd
;
6441 bcopy((caddr_t
)&pkt
->pkt_resp_fhdr
,
6442 (caddr_t
)&cmd
->cmd_ulp_pkt
->pkt_resp_fhdr
,
6443 sizeof (fc_frame_hdr_t
));
6444 bcopy((caddr_t
)pkt
->pkt_resp
,
6445 (caddr_t
)cmd
->cmd_ulp_pkt
->pkt_resp
,
6446 sizeof (la_els_logi_t
));
6449 mutex_enter(&port
->fp_mutex
);
6450 if (port
->fp_topology
== FC_TOP_PRIVATE_LOOP
|| nl_port
) {
6451 mutex_enter(&pd
->pd_mutex
);
6453 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
6454 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
6455 cmd
->cmd_retry_count
= fp_retry_count
;
6458 * If the fc_remote_port_t pointer is not set in the given
6459 * fc_packet_t, then this fc_remote_port_t must have just
6460 * been created. Save the pointer and also increment the
6461 * fc_remote_port_t reference count.
6463 if (pkt
->pkt_pd
== NULL
) {
6465 pd
->pd_ref_count
++; /* It's in use! */
6468 fp_adisc_init(cmd
, cmd
->cmd_job
);
6470 pkt
->pkt_cmdlen
= sizeof (la_els_adisc_t
);
6471 pkt
->pkt_rsplen
= sizeof (la_els_adisc_t
);
6473 mutex_exit(&pd
->pd_mutex
);
6474 mutex_exit(&port
->fp_mutex
);
6476 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) == FC_SUCCESS
) {
6480 mutex_exit(&port
->fp_mutex
);
6483 if ((cmd
->cmd_flags
& FP_CMD_PLOGI_RETAIN
) == 0) {
6484 mutex_enter(&port
->fp_mutex
);
6485 mutex_enter(&pd
->pd_mutex
);
6487 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
6488 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
6489 cmd
->cmd_retry_count
= fp_retry_count
;
6491 fp_logo_init(pd
, cmd
, cmd
->cmd_job
);
6493 pkt
->pkt_cmdlen
= sizeof (la_els_logo_t
);
6494 pkt
->pkt_rsplen
= FP_PORT_IDENTIFIER_LEN
;
6496 mutex_exit(&pd
->pd_mutex
);
6497 mutex_exit(&port
->fp_mutex
);
6499 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) == FC_SUCCESS
) {
6509 * Handle solicited ADISC response
6512 fp_adisc_intr(fc_packet_t
*pkt
)
6516 fp_cmd_t
*cmd
, *logi_cmd
;
6517 fc_local_port_t
*port
;
6518 fc_remote_port_t
*pd
;
6519 la_els_adisc_t
*acc
;
6522 fc_portmap_t
*changelist
;
6523 int initiator
, adiscfail
= 0;
6526 cmd
= pkt
->pkt_ulp_private
;
6527 port
= cmd
->cmd_port
;
6530 ASSERT(cmd
->cmd_job
&& cmd
->cmd_job
->job_counter
);
6533 ASSERT(pd
!= NULL
&& port
!= NULL
&& cmd
!= NULL
);
6535 mutex_enter(&port
->fp_mutex
);
6536 port
->fp_out_fpcmds
--;
6537 bailout
= ((port
->fp_statec_busy
||
6538 FC_PORT_STATE_MASK(port
->fp_state
) == FC_STATE_OFFLINE
) &&
6539 cmd
->cmd_ulp_pkt
) ? 1 : 0;
6540 mutex_exit(&port
->fp_mutex
);
6547 if (pkt
->pkt_state
== FC_PKT_SUCCESS
&& pkt
->pkt_resp_resid
== 0) {
6548 acc
= (la_els_adisc_t
*)pkt
->pkt_resp
;
6550 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&resp
,
6551 (uint8_t *)acc
, sizeof (resp
), DDI_DEV_AUTOINCR
);
6553 if (resp
.ls_code
== LA_ELS_ACC
) {
6556 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&ha
,
6557 (uint8_t *)&acc
->hard_addr
, sizeof (ha
),
6560 mutex_enter(&port
->fp_mutex
);
6563 (port
->fp_topology
== FC_TOP_PRIVATE_LOOP
) ? 1 : 0;
6565 mutex_enter(&pd
->pd_mutex
);
6566 if ((pd
->pd_aux_flags
& PD_IN_DID_QUEUE
) == 0) {
6567 fctl_enlist_did_table(port
, pd
);
6569 mutex_exit(&pd
->pd_mutex
);
6571 mutex_exit(&port
->fp_mutex
);
6573 mutex_enter(&pd
->pd_mutex
);
6574 if (pd
->pd_type
!= PORT_DEVICE_NEW
) {
6575 if (is_private
&& (pd
->pd_hard_addr
.hard_addr
!=
6577 pd
->pd_type
= PORT_DEVICE_CHANGED
;
6579 pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
6583 if (is_private
&& (ha
.hard_addr
&&
6584 pd
->pd_port_id
.port_id
!= ha
.hard_addr
)) {
6587 fc_wwn_to_str(&pd
->pd_port_name
, ww_name
);
6589 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
6590 "NL_Port Identifier %x doesn't match"
6591 " with Hard Address %x, Will use Port"
6592 " WWN %s", pd
->pd_port_id
.port_id
,
6593 ha
.hard_addr
, ww_name
);
6595 pd
->pd_hard_addr
.hard_addr
= 0;
6597 pd
->pd_hard_addr
.hard_addr
= ha
.hard_addr
;
6599 mutex_exit(&pd
->pd_mutex
);
6601 if (fp_common_intr(pkt
, 0) == FC_SUCCESS
) {
6606 if (fp_common_intr(pkt
, 0) == FC_SUCCESS
) {
6610 mutex_enter(&port
->fp_mutex
);
6611 if (port
->fp_statec_busy
<= 1) {
6612 mutex_exit(&port
->fp_mutex
);
6613 if (pkt
->pkt_state
== FC_PKT_LS_RJT
&&
6614 pkt
->pkt_reason
== FC_REASON_CMD_UNABLE
) {
6619 class = fp_get_nextclass(port
,
6620 FC_TRAN_CLASS_INVALID
);
6621 if (class == FC_TRAN_CLASS_INVALID
) {
6626 FP_TRACE(FP_NHEAD1(1, 0), "ADISC re-login; "
6627 "fp_state=0x%x, pkt_state=0x%x, "
6628 "reason=0x%x, class=0x%x",
6629 port
->fp_state
, pkt
->pkt_state
,
6630 pkt
->pkt_reason
, class);
6631 cmd_flag
= FP_CMD_PLOGI_RETAIN
;
6633 logi_cmd
= fp_alloc_pkt(port
,
6634 sizeof (la_els_logi_t
),
6635 sizeof (la_els_logi_t
), KM_SLEEP
, pd
);
6636 if (logi_cmd
== NULL
) {
6641 logi_cmd
->cmd_pkt
.pkt_tran_flags
=
6642 FC_TRAN_INTR
| class;
6643 logi_cmd
->cmd_pkt
.pkt_tran_type
=
6645 logi_cmd
->cmd_flags
= cmd_flag
;
6646 logi_cmd
->cmd_retry_count
= fp_retry_count
;
6647 logi_cmd
->cmd_ulp_pkt
= NULL
;
6649 mutex_enter(&port
->fp_mutex
);
6650 src_id
= port
->fp_port_id
.port_id
;
6651 mutex_exit(&port
->fp_mutex
);
6653 fp_xlogi_init(port
, logi_cmd
, src_id
,
6654 pkt
->pkt_cmd_fhdr
.d_id
, fp_plogi_intr
,
6655 cmd
->cmd_job
, LA_ELS_PLOGI
);
6657 mutex_enter(&pd
->pd_mutex
);
6658 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
6659 mutex_exit(&pd
->pd_mutex
);
6662 if (fp_sendcmd(port
, logi_cmd
,
6663 port
->fp_fca_handle
) == FC_SUCCESS
) {
6667 fp_free_pkt(logi_cmd
);
6670 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, pkt
,
6671 "ADISC to %x failed, cmd_flags=%x",
6672 pkt
->pkt_cmd_fhdr
.d_id
, cmd
->cmd_flags
);
6673 cmd
->cmd_flags
&= ~FP_CMD_PLOGI_RETAIN
;
6677 mutex_exit(&port
->fp_mutex
);
6681 if (cmd
->cmd_ulp_pkt
) {
6682 cmd
->cmd_ulp_pkt
->pkt_state
= pkt
->pkt_state
;
6683 cmd
->cmd_ulp_pkt
->pkt_action
= pkt
->pkt_action
;
6684 cmd
->cmd_ulp_pkt
->pkt_expln
= pkt
->pkt_expln
;
6685 if (cmd
->cmd_ulp_pkt
->pkt_pd
== NULL
) {
6686 cmd
->cmd_ulp_pkt
->pkt_pd
= pd
;
6687 FP_TRACE(FP_NHEAD1(9, 0),
6689 "ulp_pkt's pd is NULL, get a pd %p",
6693 bcopy((caddr_t
)&pkt
->pkt_resp_fhdr
,
6694 (caddr_t
)&cmd
->cmd_ulp_pkt
->pkt_resp_fhdr
,
6695 sizeof (fc_frame_hdr_t
));
6696 bcopy((caddr_t
)pkt
->pkt_resp
,
6697 (caddr_t
)cmd
->cmd_ulp_pkt
->pkt_resp
,
6698 sizeof (la_els_adisc_t
));
6701 if ((cmd
->cmd_flags
& FP_CMD_PLOGI_RETAIN
) == 0) {
6702 FP_TRACE(FP_NHEAD1(9, 0),
6703 "fp_adisc_intr: Perform LOGO.cmd_flags=%x, "
6704 "fp_retry_count=%x, ulp_pkt=%p",
6705 cmd
->cmd_flags
, fp_retry_count
, cmd
->cmd_ulp_pkt
);
6707 mutex_enter(&port
->fp_mutex
);
6708 mutex_enter(&pd
->pd_mutex
);
6710 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
6711 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
6712 cmd
->cmd_retry_count
= fp_retry_count
;
6714 fp_logo_init(pd
, cmd
, cmd
->cmd_job
);
6716 pkt
->pkt_cmdlen
= sizeof (la_els_logo_t
);
6717 pkt
->pkt_rsplen
= FP_PORT_IDENTIFIER_LEN
;
6719 mutex_exit(&pd
->pd_mutex
);
6720 mutex_exit(&port
->fp_mutex
);
6722 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
6724 mutex_enter(&pd
->pd_mutex
);
6726 ((pd
->pd_recepient
== PD_PLOGI_INITIATOR
) ? 1 : 0);
6727 pd
->pd_state
= PORT_DEVICE_VALID
;
6728 pd
->pd_aux_flags
|= PD_LOGGED_OUT
;
6729 if (pd
->pd_aux_flags
& PD_DISABLE_RELOGIN
) {
6730 pd
->pd_type
= PORT_DEVICE_NEW
;
6732 pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
6734 mutex_exit(&pd
->pd_mutex
);
6737 kmem_zalloc(sizeof (*changelist
), KM_SLEEP
);
6740 fp_unregister_login(pd
);
6741 fctl_copy_portmap(changelist
, pd
);
6743 fp_fillout_old_map(changelist
, pd
, 0);
6746 FP_TRACE(FP_NHEAD1(9, 0),
6747 "fp_adisc_intr: Dev change notification "
6748 "to ULP port=%p, pd=%p, map_type=%x map_state=%x "
6749 "map_flags=%x initiator=%d", port
, pd
,
6750 changelist
->map_type
, changelist
->map_state
,
6751 changelist
->map_flags
, initiator
);
6753 (void) fp_ulp_devc_cb(port
, changelist
,
6756 if (rval
== FC_SUCCESS
) {
6765 * Handle solicited LOGO response
6768 fp_logo_intr(fc_packet_t
*pkt
)
6771 fc_local_port_t
*port
= ((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
;
6773 mutex_enter(&((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
->fp_mutex
);
6774 ((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
->fp_out_fpcmds
--;
6775 mutex_exit(&((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
->fp_mutex
);
6777 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&resp
,
6778 (uint8_t *)pkt
->pkt_resp
, sizeof (resp
), DDI_DEV_AUTOINCR
);
6780 if (FP_IS_PKT_ERROR(pkt
)) {
6781 (void) fp_common_intr(pkt
, 1);
6785 ASSERT(resp
.ls_code
== LA_ELS_ACC
);
6786 if (resp
.ls_code
!= LA_ELS_ACC
) {
6787 (void) fp_common_intr(pkt
, 1);
6791 if (pkt
->pkt_pd
!= NULL
) {
6792 fp_unregister_login(pkt
->pkt_pd
);
6795 fp_iodone(pkt
->pkt_ulp_private
);
6800 * Handle solicited RNID response
6803 fp_rnid_intr(fc_packet_t
*pkt
)
6808 la_els_rnid_acc_t
*acc
;
6809 fc_local_port_t
*port
= ((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
;
6811 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&resp
,
6812 (uint8_t *)pkt
->pkt_resp
, sizeof (resp
), DDI_DEV_AUTOINCR
);
6813 cmd
= pkt
->pkt_ulp_private
;
6815 mutex_enter(&cmd
->cmd_port
->fp_mutex
);
6816 cmd
->cmd_port
->fp_out_fpcmds
--;
6817 mutex_exit(&cmd
->cmd_port
->fp_mutex
);
6820 ASSERT(job
->job_private
!= NULL
);
6822 /* If failure or LS_RJT then retry the packet, if needed */
6823 if (pkt
->pkt_state
!= FC_PKT_SUCCESS
|| resp
.ls_code
!= LA_ELS_ACC
) {
6824 (void) fp_common_intr(pkt
, 1);
6828 /* Save node_id memory allocated in ioctl code */
6829 acc
= (la_els_rnid_acc_t
*)pkt
->pkt_resp
;
6831 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)job
->job_private
,
6832 (uint8_t *)acc
, sizeof (la_els_rnid_acc_t
), DDI_DEV_AUTOINCR
);
6834 /* wakeup the ioctl thread and free the pkt */
6840 * Handle solicited RLS response
6843 fp_rls_intr(fc_packet_t
*pkt
)
6848 la_els_rls_acc_t
*acc
;
6849 fc_local_port_t
*port
= ((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
;
6851 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&resp
,
6852 (uint8_t *)pkt
->pkt_resp
, sizeof (resp
), DDI_DEV_AUTOINCR
);
6853 cmd
= pkt
->pkt_ulp_private
;
6855 mutex_enter(&cmd
->cmd_port
->fp_mutex
);
6856 cmd
->cmd_port
->fp_out_fpcmds
--;
6857 mutex_exit(&cmd
->cmd_port
->fp_mutex
);
6860 ASSERT(job
->job_private
!= NULL
);
6862 /* If failure or LS_RJT then retry the packet, if needed */
6863 if (FP_IS_PKT_ERROR(pkt
) || resp
.ls_code
!= LA_ELS_ACC
) {
6864 (void) fp_common_intr(pkt
, 1);
6868 /* Save link error status block in memory allocated in ioctl code */
6869 acc
= (la_els_rls_acc_t
*)pkt
->pkt_resp
;
6871 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)job
->job_private
,
6872 (uint8_t *)&acc
->rls_link_params
, sizeof (fc_rls_acc_t
),
6875 /* wakeup the ioctl thread and free the pkt */
6881 * A solicited command completion interrupt (mostly for commands
6882 * that require almost no post processing such as SCR ELS)
6885 fp_intr(fc_packet_t
*pkt
)
6887 mutex_enter(&((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
->fp_mutex
);
6888 ((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
->fp_out_fpcmds
--;
6889 mutex_exit(&((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
->fp_mutex
);
6891 if (FP_IS_PKT_ERROR(pkt
)) {
6892 (void) fp_common_intr(pkt
, 1);
6895 fp_iodone(pkt
->pkt_ulp_private
);
6900 * Handle the underlying port's state change
6903 fp_statec_cb(opaque_t port_handle
, uint32_t state
)
6905 fc_local_port_t
*port
= port_handle
;
6909 * If it is not possible to process the callbacks
6910 * just drop the callback on the floor; Don't bother
6911 * to do something that isn't safe at this time
6913 mutex_enter(&port
->fp_mutex
);
6914 if ((port
->fp_soft_state
&
6915 (FP_SOFT_IN_DETACH
| FP_SOFT_SUSPEND
| FP_SOFT_POWER_DOWN
)) ||
6916 (FC_PORT_STATE_MASK(port
->fp_state
) == FC_PORT_STATE_MASK(state
))) {
6917 mutex_exit(&port
->fp_mutex
);
6921 if (port
->fp_statec_busy
== 0) {
6922 port
->fp_soft_state
|= FP_SOFT_IN_STATEC_CB
;
6925 ASSERT(port
->fp_soft_state
& FP_SOFT_IN_STATEC_CB
);
6929 port
->fp_statec_busy
++;
6932 * For now, force the trusted method of device authentication (by
6933 * PLOGI) when LIPs do not involve OFFLINE to ONLINE transition.
6935 if (FC_PORT_STATE_MASK(state
) == FC_STATE_LIP
||
6936 FC_PORT_STATE_MASK(state
) == FC_STATE_LIP_LBIT_SET
) {
6937 state
= FC_PORT_SPEED_MASK(port
->fp_state
) | FC_STATE_LOOP
;
6938 fp_port_offline(port
, 0);
6940 mutex_exit(&port
->fp_mutex
);
6942 switch (FC_PORT_STATE_MASK(state
)) {
6943 case FC_STATE_OFFLINE
:
6944 job
= fctl_alloc_job(JOB_PORT_OFFLINE
,
6945 JOB_TYPE_FCTL_ASYNC
, NULL
, NULL
, KM_NOSLEEP
);
6947 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
6948 " fp_statec_cb() couldn't submit a job "
6949 " to the thread: failing..");
6950 mutex_enter(&port
->fp_mutex
);
6951 if (--port
->fp_statec_busy
== 0) {
6952 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
6954 mutex_exit(&port
->fp_mutex
);
6957 mutex_enter(&port
->fp_mutex
);
6959 * Zero out this field so that we do not retain
6960 * the fabric name as its no longer valid
6962 bzero(&port
->fp_fabric_name
, sizeof (la_wwn_t
));
6963 port
->fp_state
= state
;
6964 mutex_exit(&port
->fp_mutex
);
6966 fctl_enque_job(port
, job
);
6969 case FC_STATE_ONLINE
:
6971 mutex_enter(&port
->fp_mutex
);
6972 port
->fp_state
= state
;
6974 if (port
->fp_offline_tid
) {
6977 tid
= port
->fp_offline_tid
;
6978 port
->fp_offline_tid
= NULL
;
6979 mutex_exit(&port
->fp_mutex
);
6980 (void) untimeout(tid
);
6982 mutex_exit(&port
->fp_mutex
);
6985 job
= fctl_alloc_job(JOB_PORT_ONLINE
,
6986 JOB_TYPE_FCTL_ASYNC
, NULL
, NULL
, KM_NOSLEEP
);
6988 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
6989 "fp_statec_cb() couldn't submit a job "
6990 "to the thread: failing..");
6992 mutex_enter(&port
->fp_mutex
);
6993 if (--port
->fp_statec_busy
== 0) {
6994 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
6996 mutex_exit(&port
->fp_mutex
);
6999 fctl_enque_job(port
, job
);
7002 case FC_STATE_RESET_REQUESTED
:
7003 mutex_enter(&port
->fp_mutex
);
7004 port
->fp_state
= FC_STATE_OFFLINE
;
7005 port
->fp_soft_state
|= FP_SOFT_IN_FCA_RESET
;
7006 mutex_exit(&port
->fp_mutex
);
7009 case FC_STATE_RESET
:
7010 job
= fctl_alloc_job(JOB_ULP_NOTIFY
,
7011 JOB_TYPE_FCTL_ASYNC
, NULL
, NULL
, KM_NOSLEEP
);
7013 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
7014 "fp_statec_cb() couldn't submit a job"
7015 " to the thread: failing..");
7017 mutex_enter(&port
->fp_mutex
);
7018 if (--port
->fp_statec_busy
== 0) {
7019 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
7021 mutex_exit(&port
->fp_mutex
);
7025 /* squeeze into some field in the job structure */
7026 job
->job_ulp_listlen
= FC_PORT_STATE_MASK(state
);
7027 fctl_enque_job(port
, job
);
7030 case FC_STATE_TARGET_PORT_RESET
:
7031 (void) fp_ulp_notify(port
, state
, KM_NOSLEEP
);
7034 case FC_STATE_NAMESERVICE
:
7038 mutex_enter(&port
->fp_mutex
);
7039 if (--port
->fp_statec_busy
== 0) {
7040 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
7042 mutex_exit(&port
->fp_mutex
);
7049 * Register with the Name Server for RSCNs
7052 fp_ns_scr(fc_local_port_t
*port
, job_request_t
*job
, uchar_t scr_func
,
7057 fc_scr_req_t payload
;
7061 mutex_enter(&port
->fp_mutex
);
7062 s_id
= port
->fp_port_id
.port_id
;
7063 class = port
->fp_ns_login_class
;
7064 mutex_exit(&port
->fp_mutex
);
7066 cmd
= fp_alloc_pkt(port
, sizeof (fc_scr_req_t
),
7067 sizeof (fc_scr_resp_t
), sleep
, NULL
);
7072 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| class;
7073 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
7074 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
7075 cmd
->cmd_retry_count
= fp_retry_count
;
7076 cmd
->cmd_ulp_pkt
= NULL
;
7078 pkt
= &cmd
->cmd_pkt
;
7079 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
7081 fp_els_init(cmd
, s_id
, 0xFFFFFD, fp_intr
, job
);
7083 payload
.ls_code
.ls_code
= LA_ELS_SCR
;
7084 payload
.ls_code
.mbz
= 0;
7085 payload
.scr_rsvd
= 0;
7086 payload
.scr_func
= scr_func
;
7088 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
7089 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
7091 job
->job_counter
= 1;
7093 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
) {
7097 return (FC_SUCCESS
);
7102 * There are basically two methods to determine the total number of
7103 * devices out in the NS database; Reading the details of the two
7104 * methods described below, it shouldn't be hard to identify which
7105 * of the two methods is better.
7108 * Iteratively issue GANs until all ports identifiers are walked
7111 * Issue GID_PT (get port Identifiers) with Maximum residual
7112 * field in the request CT HEADER set to accommodate only the
7113 * CT HEADER in the response frame. And if FC-GS2 has been
7114 * carefully read, the NS here has a chance to FS_ACC the
7115 * request and indicate the residual size in the FS_ACC.
7117 * Method 2 is wonderful, although it's not mandatory for the NS
7118 * to update the Maximum/Residual Field as can be seen in 4.3.1.6
7119 * (note with particular care the use of the auxiliary verb 'may')
7123 fp_ns_get_devcount(fc_local_port_t
*port
, job_request_t
*job
, int create
,
7129 fctl_ns_req_t
*ns_cmd
;
7131 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
7133 mutex_enter(&port
->fp_mutex
);
7134 src_id
= port
->fp_port_id
.port_id
;
7135 mutex_exit(&port
->fp_mutex
);
7137 if (!create
&& (port
->fp_options
& FP_NS_SMART_COUNT
)) {
7138 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gid_pt_t
),
7139 sizeof (ns_resp_gid_pt_t
), 0,
7140 (FCTL_NS_GET_DEV_COUNT
| FCTL_NS_NO_DATA_BUF
), sleep
);
7142 if (ns_cmd
== NULL
) {
7146 ns_cmd
->ns_cmd_code
= NS_GID_PT
;
7147 ((ns_req_gid_pt_t
*)(ns_cmd
->ns_cmd_buf
))->port_type
.port_type
7148 = FC_NS_PORT_NX
; /* All port types */
7149 ((ns_req_gid_pt_t
*)(ns_cmd
->ns_cmd_buf
))->port_type
.rsvd
= 0;
7154 ns_flags
= FCTL_NS_GET_DEV_COUNT
| FCTL_NS_NO_DATA_BUF
;
7156 ns_flags
|= FCTL_NS_CREATE_DEVICE
;
7158 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gan_t
),
7159 sizeof (ns_resp_gan_t
), sizeof (int), ns_flags
, sleep
);
7161 if (ns_cmd
== NULL
) {
7164 ns_cmd
->ns_gan_index
= 0;
7165 ns_cmd
->ns_gan_sid
= FCTL_GAN_START_ID
;
7166 ns_cmd
->ns_cmd_code
= NS_GA_NXT
;
7167 ns_cmd
->ns_gan_max
= 0xFFFF;
7169 ((ns_req_gan_t
*)(ns_cmd
->ns_cmd_buf
))->pid
.port_id
= src_id
;
7170 ((ns_req_gan_t
*)(ns_cmd
->ns_cmd_buf
))->pid
.priv_lilp_posit
= 0;
7173 flags
= job
->job_flags
;
7174 job
->job_flags
&= ~JOB_TYPE_FP_ASYNC
;
7175 job
->job_counter
= 1;
7177 rval
= fp_ns_query(port
, ns_cmd
, job
, 1, sleep
);
7178 job
->job_flags
= flags
;
7180 if (!create
&& (port
->fp_options
& FP_NS_SMART_COUNT
)) {
7184 * Revert to scanning the NS if NS_GID_PT isn't
7185 * helping us figure out total number of devices.
7187 if (job
->job_result
!= FC_SUCCESS
||
7188 ns_cmd
->ns_resp_hdr
.ct_cmdrsp
!= FS_ACC_IU
) {
7189 mutex_enter(&port
->fp_mutex
);
7190 port
->fp_options
&= ~FP_NS_SMART_COUNT
;
7191 mutex_exit(&port
->fp_mutex
);
7193 fctl_free_ns_cmd(ns_cmd
);
7194 return (fp_ns_get_devcount(port
, job
, create
, sleep
));
7197 mutex_enter(&port
->fp_mutex
);
7198 port
->fp_total_devices
= 1;
7199 max_resid
= ns_cmd
->ns_resp_hdr
.ct_aiusize
;
7202 * Since port identifier is 4 bytes and max_resid
7203 * is also in WORDS, max_resid simply indicates
7204 * the total number of port identifiers not
7207 port
->fp_total_devices
+= max_resid
;
7209 mutex_exit(&port
->fp_mutex
);
7211 mutex_enter(&port
->fp_mutex
);
7212 port
->fp_total_devices
= *((int *)ns_cmd
->ns_data_buf
);
7213 mutex_exit(&port
->fp_mutex
);
7214 fctl_free_ns_cmd(ns_cmd
);
7220 * One heck of a function to serve userland.
7223 fp_fciocmd(fc_local_port_t
*port
, intptr_t data
, int mode
, fcio_t
*fcio
)
7231 boolean_t use32
= B_FALSE
;
7233 #ifdef _MULTI_DATAMODEL
7234 switch (ddi_model_convert_from(mode
& FMODELS
)) {
7235 case DDI_MODEL_ILP32
:
7239 case DDI_MODEL_NONE
:
7245 mutex_enter(&port
->fp_mutex
);
7246 if (port
->fp_soft_state
& (FP_SOFT_IN_STATEC_CB
|
7247 FP_SOFT_IN_UNSOL_CB
)) {
7248 fcio
->fcio_errno
= FC_STATEC_BUSY
;
7249 mutex_exit(&port
->fp_mutex
);
7251 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7256 open_flag
= port
->fp_flag
;
7257 mutex_exit(&port
->fp_mutex
);
7259 if (fp_check_perms(open_flag
, fcio
->fcio_cmd
) != FC_SUCCESS
) {
7260 fcio
->fcio_errno
= FC_FAILURE
;
7262 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7269 * If an exclusive open was demanded during open, don't let
7270 * either innocuous or devil threads to share the file
7271 * descriptor and fire down exclusive access commands
7273 mutex_enter(&port
->fp_mutex
);
7274 if (port
->fp_flag
& FP_EXCL
) {
7275 if (port
->fp_flag
& FP_EXCL_BUSY
) {
7276 mutex_exit(&port
->fp_mutex
);
7277 fcio
->fcio_errno
= FC_FAILURE
;
7280 port
->fp_flag
|= FP_EXCL_BUSY
;
7282 mutex_exit(&port
->fp_mutex
);
7284 fcio
->fcio_errno
= FC_SUCCESS
;
7286 switch (fcio
->fcio_cmd
) {
7287 case FCIO_GET_HOST_PARAMS
: {
7289 fc_port_dev32_t
*val32
;
7291 int lilp_device_count
;
7292 fc_lilpmap_t
*lilp_map
;
7295 if (use32
== B_TRUE
) {
7296 if (fcio
->fcio_olen
!= sizeof (*val32
) ||
7297 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7302 if (fcio
->fcio_olen
!= sizeof (*val
) ||
7303 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7309 val
= kmem_zalloc(sizeof (*val
), KM_SLEEP
);
7311 mutex_enter(&port
->fp_mutex
);
7312 val
->dev_did
= port
->fp_port_id
;
7313 val
->dev_hard_addr
= port
->fp_hard_addr
;
7314 val
->dev_pwwn
= port
->fp_service_params
.nport_ww_name
;
7315 val
->dev_nwwn
= port
->fp_service_params
.node_ww_name
;
7316 val
->dev_state
= port
->fp_state
;
7318 lilp_map
= &port
->fp_lilp_map
;
7319 alpa_list
= &lilp_map
->lilp_alpalist
[0];
7320 lilp_device_count
= lilp_map
->lilp_length
;
7321 for (index
= 0; index
< lilp_device_count
; index
++) {
7324 d_id
= alpa_list
[index
];
7325 if (d_id
== port
->fp_port_id
.port_id
) {
7329 val
->dev_did
.priv_lilp_posit
= (uint8_t)(index
& 0xff);
7331 bcopy(port
->fp_fc4_types
, val
->dev_type
,
7332 sizeof (port
->fp_fc4_types
));
7333 mutex_exit(&port
->fp_mutex
);
7335 if (use32
== B_TRUE
) {
7336 val32
= kmem_zalloc(sizeof (*val32
), KM_SLEEP
);
7338 val32
->dev_did
= val
->dev_did
;
7339 val32
->dev_hard_addr
= val
->dev_hard_addr
;
7340 val32
->dev_pwwn
= val
->dev_pwwn
;
7341 val32
->dev_nwwn
= val
->dev_nwwn
;
7342 val32
->dev_state
= val
->dev_state
;
7343 val32
->dev_did
.priv_lilp_posit
=
7344 val
->dev_did
.priv_lilp_posit
;
7346 bcopy(val
->dev_type
, val32
->dev_type
,
7347 sizeof (port
->fp_fc4_types
));
7349 if (fp_copyout((void *)val32
, (void *)fcio
->fcio_obuf
,
7350 fcio
->fcio_olen
, mode
) == 0) {
7351 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7358 kmem_free(val32
, sizeof (*val32
));
7360 if (fp_copyout((void *)val
, (void *)fcio
->fcio_obuf
,
7361 fcio
->fcio_olen
, mode
) == 0) {
7362 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7370 /* need to free "val" here */
7371 kmem_free(val
, sizeof (*val
));
7375 case FCIO_GET_OTHER_ADAPTER_PORTS
: {
7378 fc_local_port_t
*tmpPort
;
7380 if (fcio
->fcio_olen
< MAXPATHLEN
||
7381 fcio
->fcio_ilen
!= sizeof (uint32_t)) {
7385 if (ddi_copyin(fcio
->fcio_ibuf
, &index
, sizeof (index
), mode
)) {
7390 tmpPort
= fctl_get_adapter_port_by_index(port
, index
);
7391 if (tmpPort
== NULL
) {
7392 FP_TRACE(FP_NHEAD1(9, 0),
7393 "User supplied index out of range");
7394 fcio
->fcio_errno
= FC_BADPORT
;
7396 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7402 tmpPath
= kmem_zalloc(MAXPATHLEN
, KM_SLEEP
);
7403 (void) ddi_pathname(tmpPort
->fp_port_dip
, tmpPath
);
7404 if (fp_copyout((void *)tmpPath
, (void *)fcio
->fcio_obuf
,
7405 MAXPATHLEN
, mode
) == 0) {
7406 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7412 kmem_free(tmpPath
, MAXPATHLEN
);
7416 case FCIO_NPIV_GET_ADAPTER_ATTRIBUTES
:
7417 case FCIO_GET_ADAPTER_ATTRIBUTES
: {
7418 fc_hba_adapter_attributes_t
*val
;
7419 fc_hba_adapter_attributes32_t
*val32
;
7421 if (use32
== B_TRUE
) {
7422 if (fcio
->fcio_olen
< sizeof (*val32
) ||
7423 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7428 if (fcio
->fcio_olen
< sizeof (*val
) ||
7429 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7435 val
= kmem_zalloc(sizeof (*val
), KM_SLEEP
);
7436 val
->version
= FC_HBA_ADAPTER_ATTRIBUTES_VERSION
;
7437 mutex_enter(&port
->fp_mutex
);
7438 bcopy(port
->fp_hba_port_attrs
.manufacturer
,
7440 sizeof (val
->Manufacturer
));
7441 bcopy(port
->fp_hba_port_attrs
.serial_number
,
7443 sizeof (val
->SerialNumber
));
7444 bcopy(port
->fp_hba_port_attrs
.model
,
7446 sizeof (val
->Model
));
7447 bcopy(port
->fp_hba_port_attrs
.model_description
,
7448 val
->ModelDescription
,
7449 sizeof (val
->ModelDescription
));
7450 bcopy(port
->fp_sym_node_name
, val
->NodeSymbolicName
,
7451 port
->fp_sym_node_namelen
);
7452 bcopy(port
->fp_hba_port_attrs
.hardware_version
,
7453 val
->HardwareVersion
,
7454 sizeof (val
->HardwareVersion
));
7455 bcopy(port
->fp_hba_port_attrs
.option_rom_version
,
7456 val
->OptionROMVersion
,
7457 sizeof (val
->OptionROMVersion
));
7458 bcopy(port
->fp_hba_port_attrs
.firmware_version
,
7459 val
->FirmwareVersion
,
7460 sizeof (val
->FirmwareVersion
));
7461 val
->VendorSpecificID
=
7462 port
->fp_hba_port_attrs
.vendor_specific_id
;
7463 bcopy(&port
->fp_service_params
.node_ww_name
.raw_wwn
,
7464 &val
->NodeWWN
.raw_wwn
,
7465 sizeof (val
->NodeWWN
.raw_wwn
));
7468 bcopy(port
->fp_hba_port_attrs
.driver_name
,
7470 sizeof (val
->DriverName
));
7471 bcopy(port
->fp_hba_port_attrs
.driver_version
,
7473 sizeof (val
->DriverVersion
));
7474 mutex_exit(&port
->fp_mutex
);
7476 if (fcio
->fcio_cmd
== FCIO_GET_ADAPTER_ATTRIBUTES
) {
7477 val
->NumberOfPorts
= fctl_count_fru_ports(port
, 0);
7479 val
->NumberOfPorts
= fctl_count_fru_ports(port
, 1);
7482 if (use32
== B_TRUE
) {
7483 val32
= kmem_zalloc(sizeof (*val32
), KM_SLEEP
);
7484 val32
->version
= val
->version
;
7485 bcopy(val
->Manufacturer
, val32
->Manufacturer
,
7486 sizeof (val
->Manufacturer
));
7487 bcopy(val
->SerialNumber
, val32
->SerialNumber
,
7488 sizeof (val
->SerialNumber
));
7489 bcopy(val
->Model
, val32
->Model
,
7490 sizeof (val
->Model
));
7491 bcopy(val
->ModelDescription
, val32
->ModelDescription
,
7492 sizeof (val
->ModelDescription
));
7493 bcopy(val
->NodeSymbolicName
, val32
->NodeSymbolicName
,
7494 sizeof (val
->NodeSymbolicName
));
7495 bcopy(val
->HardwareVersion
, val32
->HardwareVersion
,
7496 sizeof (val
->HardwareVersion
));
7497 bcopy(val
->OptionROMVersion
, val32
->OptionROMVersion
,
7498 sizeof (val
->OptionROMVersion
));
7499 bcopy(val
->FirmwareVersion
, val32
->FirmwareVersion
,
7500 sizeof (val
->FirmwareVersion
));
7501 val32
->VendorSpecificID
= val
->VendorSpecificID
;
7502 bcopy(&val
->NodeWWN
.raw_wwn
, &val32
->NodeWWN
.raw_wwn
,
7503 sizeof (val
->NodeWWN
.raw_wwn
));
7504 bcopy(val
->DriverName
, val32
->DriverName
,
7505 sizeof (val
->DriverName
));
7506 bcopy(val
->DriverVersion
, val32
->DriverVersion
,
7507 sizeof (val
->DriverVersion
));
7509 val32
->NumberOfPorts
= val
->NumberOfPorts
;
7511 if (fp_copyout((void *)val32
, (void *)fcio
->fcio_obuf
,
7512 fcio
->fcio_olen
, mode
) == 0) {
7513 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7520 kmem_free(val32
, sizeof (*val32
));
7522 if (fp_copyout((void *)val
, (void *)fcio
->fcio_obuf
,
7523 fcio
->fcio_olen
, mode
) == 0) {
7524 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7532 kmem_free(val
, sizeof (*val
));
7536 case FCIO_GET_NPIV_ATTRIBUTES
: {
7537 fc_hba_npiv_attributes_t
*attrs
;
7539 attrs
= kmem_zalloc(sizeof (*attrs
), KM_SLEEP
);
7540 mutex_enter(&port
->fp_mutex
);
7541 bcopy(&port
->fp_service_params
.node_ww_name
.raw_wwn
,
7542 &attrs
->NodeWWN
.raw_wwn
,
7543 sizeof (attrs
->NodeWWN
.raw_wwn
));
7544 bcopy(&port
->fp_service_params
.nport_ww_name
.raw_wwn
,
7545 &attrs
->PortWWN
.raw_wwn
,
7546 sizeof (attrs
->PortWWN
.raw_wwn
));
7547 mutex_exit(&port
->fp_mutex
);
7548 if (fp_copyout((void *)attrs
, (void *)fcio
->fcio_obuf
,
7549 fcio
->fcio_olen
, mode
) == 0) {
7550 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7556 kmem_free(attrs
, sizeof (*attrs
));
7560 case FCIO_DELETE_NPIV_PORT
: {
7561 fc_local_port_t
*tmpport
;
7565 FP_TRACE(FP_NHEAD1(1, 0), "Delete NPIV Port");
7566 if (ddi_copyin(fcio
->fcio_ibuf
,
7567 &vwwn
, sizeof (la_wwn_t
), mode
)) {
7572 fc_wwn_to_str(&vwwn
[0], ww_pname
);
7573 FP_TRACE(FP_NHEAD1(3, 0),
7574 "Delete NPIV Port %s", ww_pname
);
7575 tmpport
= fc_delete_npiv_port(port
, &vwwn
[0]);
7576 if (tmpport
== NULL
) {
7577 FP_TRACE(FP_NHEAD1(3, 0),
7578 "Delete NPIV Port : no found");
7581 fc_local_port_t
*nextport
= tmpport
->fp_port_next
;
7582 fc_local_port_t
*prevport
= tmpport
->fp_port_prev
;
7583 int portlen
, portindex
, ret
;
7585 portlen
= sizeof (portindex
);
7586 ret
= ddi_prop_op(DDI_DEV_T_ANY
,
7587 tmpport
->fp_port_dip
, PROP_LEN_AND_VAL_BUF
,
7588 DDI_PROP_DONTPASS
| DDI_PROP_CANSLEEP
, "port",
7589 (caddr_t
)&portindex
, &portlen
);
7590 if (ret
!= DDI_SUCCESS
) {
7594 if (ndi_devi_offline(tmpport
->fp_port_dip
,
7595 NDI_DEVI_REMOVE
) != DDI_SUCCESS
) {
7596 FP_TRACE(FP_NHEAD1(1, 0),
7597 "Delete NPIV Port failed");
7598 mutex_enter(&port
->fp_mutex
);
7599 tmpport
->fp_npiv_state
= 0;
7600 mutex_exit(&port
->fp_mutex
);
7603 mutex_enter(&port
->fp_mutex
);
7604 nextport
->fp_port_prev
= prevport
;
7605 prevport
->fp_port_next
= nextport
;
7606 if (port
== port
->fp_port_next
) {
7607 port
->fp_port_next
=
7608 port
->fp_port_prev
= NULL
;
7610 port
->fp_npiv_portnum
--;
7611 FP_TRACE(FP_NHEAD1(3, 0),
7612 "Delete NPIV Port %d", portindex
);
7613 port
->fp_npiv_portindex
[portindex
-1] = 0;
7614 mutex_exit(&port
->fp_mutex
);
7620 case FCIO_CREATE_NPIV_PORT
: {
7621 char ww_nname
[17], ww_pname
[17];
7622 la_npiv_create_entry_t entrybuf
;
7623 uint32_t vportindex
= 0;
7625 char *portname
, *fcaname
;
7627 portname
= kmem_zalloc(MAXPATHLEN
, KM_SLEEP
);
7628 (void) ddi_pathname(port
->fp_port_dip
, portname
);
7629 fcaname
= kmem_zalloc(MAXPATHLEN
, KM_SLEEP
);
7630 (void) ddi_pathname(port
->fp_fca_dip
, fcaname
);
7631 FP_TRACE(FP_NHEAD1(1, 0),
7632 "Create NPIV port %s %s %s", portname
, fcaname
,
7633 ddi_driver_name(port
->fp_fca_dip
));
7634 kmem_free(portname
, MAXPATHLEN
);
7635 kmem_free(fcaname
, MAXPATHLEN
);
7636 if (ddi_copyin(fcio
->fcio_ibuf
,
7637 &entrybuf
, sizeof (la_npiv_create_entry_t
), mode
)) {
7642 fc_wwn_to_str(&entrybuf
.VNodeWWN
, ww_nname
);
7643 fc_wwn_to_str(&entrybuf
.VPortWWN
, ww_pname
);
7644 vportindex
= entrybuf
.vindex
;
7645 FP_TRACE(FP_NHEAD1(3, 0),
7646 "Create NPIV Port %s %s %d",
7647 ww_nname
, ww_pname
, vportindex
);
7649 if (fc_get_npiv_port(port
, &entrybuf
.VPortWWN
)) {
7653 npiv_ret
= fctl_fca_create_npivport(port
->fp_fca_dip
,
7654 port
->fp_port_dip
, ww_nname
, ww_pname
, &vportindex
);
7655 if (npiv_ret
== NDI_SUCCESS
) {
7656 mutex_enter(&port
->fp_mutex
);
7657 port
->fp_npiv_portnum
++;
7658 mutex_exit(&port
->fp_mutex
);
7659 if (fp_copyout((void *)&vportindex
,
7660 (void *)fcio
->fcio_obuf
,
7661 fcio
->fcio_olen
, mode
) == 0) {
7662 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7671 FP_TRACE(FP_NHEAD1(3, 0),
7672 "Create NPIV Port %d %d", npiv_ret
, vportindex
);
7676 case FCIO_GET_NPIV_PORT_LIST
: {
7677 fc_hba_npiv_port_list_t
*list
;
7680 if ((fcio
->fcio_xfer
!= FCIO_XFER_READ
) ||
7681 (fcio
->fcio_olen
== 0) || (fcio
->fcio_obuf
== 0)) {
7686 list
= kmem_zalloc(fcio
->fcio_olen
, KM_SLEEP
);
7687 list
->version
= FC_HBA_LIST_VERSION
;
7689 count
= (fcio
->fcio_olen
-
7690 (int)sizeof (fc_hba_npiv_port_list_t
))/MAXPATHLEN
+ 1;
7691 if (port
->fp_npiv_portnum
> count
) {
7692 list
->numAdapters
= port
->fp_npiv_portnum
;
7694 /* build npiv port list */
7695 count
= fc_ulp_get_npiv_port_list(port
,
7696 (char *)list
->hbaPaths
);
7699 FP_TRACE(FP_NHEAD1(1, 0),
7700 "Build NPIV Port List error");
7701 kmem_free(list
, fcio
->fcio_olen
);
7704 list
->numAdapters
= count
;
7707 if (fp_copyout((void *)list
, (void *)fcio
->fcio_obuf
,
7708 fcio
->fcio_olen
, mode
) == 0) {
7709 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7710 FP_TRACE(FP_NHEAD1(1, 0),
7711 "Copy NPIV Port data error");
7715 FP_TRACE(FP_NHEAD1(1, 0), "Copy NPIV Port List error");
7718 kmem_free(list
, fcio
->fcio_olen
);
7722 case FCIO_GET_ADAPTER_PORT_NPIV_ATTRIBUTES
: {
7723 fc_hba_port_npiv_attributes_t
*val
;
7725 val
= kmem_zalloc(sizeof (*val
), KM_SLEEP
);
7726 val
->version
= FC_HBA_PORT_NPIV_ATTRIBUTES_VERSION
;
7728 mutex_enter(&port
->fp_mutex
);
7729 val
->npivflag
= port
->fp_npiv_flag
;
7730 val
->lastChange
= port
->fp_last_change
;
7731 bcopy(&port
->fp_service_params
.nport_ww_name
.raw_wwn
,
7732 &val
->PortWWN
.raw_wwn
,
7733 sizeof (val
->PortWWN
.raw_wwn
));
7734 bcopy(&port
->fp_service_params
.node_ww_name
.raw_wwn
,
7735 &val
->NodeWWN
.raw_wwn
,
7736 sizeof (val
->NodeWWN
.raw_wwn
));
7737 mutex_exit(&port
->fp_mutex
);
7739 val
->NumberOfNPIVPorts
= fc_ulp_get_npiv_port_num(port
);
7740 if (port
->fp_npiv_type
!= FC_NPIV_PORT
) {
7741 val
->MaxNumberOfNPIVPorts
=
7742 port
->fp_fca_tran
->fca_num_npivports
;
7744 val
->MaxNumberOfNPIVPorts
= 0;
7747 if (fp_copyout((void *)val
, (void *)fcio
->fcio_obuf
,
7748 fcio
->fcio_olen
, mode
) == 0) {
7749 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7755 kmem_free(val
, sizeof (*val
));
7759 case FCIO_GET_ADAPTER_PORT_ATTRIBUTES
: {
7760 fc_hba_port_attributes_t
*val
;
7761 fc_hba_port_attributes32_t
*val32
;
7763 if (use32
== B_TRUE
) {
7764 if (fcio
->fcio_olen
< sizeof (*val32
) ||
7765 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7770 if (fcio
->fcio_olen
< sizeof (*val
) ||
7771 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7777 val
= kmem_zalloc(sizeof (*val
), KM_SLEEP
);
7778 val
->version
= FC_HBA_PORT_ATTRIBUTES_VERSION
;
7779 mutex_enter(&port
->fp_mutex
);
7780 val
->lastChange
= port
->fp_last_change
;
7781 val
->fp_minor
= port
->fp_instance
;
7783 bcopy(&port
->fp_service_params
.nport_ww_name
.raw_wwn
,
7784 &val
->PortWWN
.raw_wwn
,
7785 sizeof (val
->PortWWN
.raw_wwn
));
7786 bcopy(&port
->fp_service_params
.node_ww_name
.raw_wwn
,
7787 &val
->NodeWWN
.raw_wwn
,
7788 sizeof (val
->NodeWWN
.raw_wwn
));
7789 bcopy(&port
->fp_fabric_name
, &val
->FabricName
.raw_wwn
,
7790 sizeof (val
->FabricName
.raw_wwn
));
7792 val
->PortFcId
= port
->fp_port_id
.port_id
;
7794 switch (FC_PORT_STATE_MASK(port
->fp_state
)) {
7795 case FC_STATE_OFFLINE
:
7796 val
->PortState
= FC_HBA_PORTSTATE_OFFLINE
;
7798 case FC_STATE_ONLINE
:
7800 case FC_STATE_NAMESERVICE
:
7801 val
->PortState
= FC_HBA_PORTSTATE_ONLINE
;
7804 val
->PortState
= FC_HBA_PORTSTATE_UNKNOWN
;
7808 /* Translate from LV to FC-HBA port type codes */
7809 switch (port
->fp_port_type
.port_type
) {
7811 val
->PortType
= FC_HBA_PORTTYPE_NPORT
;
7814 /* Actually means loop for us */
7815 val
->PortType
= FC_HBA_PORTTYPE_LPORT
;
7818 val
->PortType
= FC_HBA_PORTTYPE_FPORT
;
7821 val
->PortType
= FC_HBA_PORTTYPE_FLPORT
;
7824 val
->PortType
= FC_HBA_PORTTYPE_EPORT
;
7827 val
->PortType
= FC_HBA_PORTTYPE_OTHER
;
7833 * If fp has decided that the topology is public loop,
7834 * we will indicate that using the appropriate
7835 * FC HBA API constant.
7837 switch (port
->fp_topology
) {
7838 case FC_TOP_PUBLIC_LOOP
:
7839 val
->PortType
= FC_HBA_PORTTYPE_NLPORT
;
7843 val
->PortType
= FC_HBA_PORTTYPE_PTP
;
7846 case FC_TOP_UNKNOWN
:
7848 * This should cover the case where nothing is connected
7849 * to the port. Crystal+ is p'bly an exception here.
7850 * For Crystal+, port 0 will come up as private loop
7851 * (i.e fp_bind_state will be FC_STATE_LOOP) even when
7852 * nothing is connected to it.
7853 * Current plan is to let userland handle this.
7855 if (port
->fp_bind_state
== FC_STATE_OFFLINE
) {
7856 val
->PortType
= FC_HBA_PORTTYPE_UNKNOWN
;
7864 * val->PortType = FC_HBA_PORTTYPE_GPORT;
7869 val
->PortSupportedClassofService
=
7870 port
->fp_hba_port_attrs
.supported_cos
;
7871 val
->PortSupportedFc4Types
[0] = 0;
7872 bcopy(port
->fp_fc4_types
, val
->PortActiveFc4Types
,
7873 sizeof (val
->PortActiveFc4Types
));
7874 bcopy(port
->fp_sym_port_name
, val
->PortSymbolicName
,
7875 port
->fp_sym_port_namelen
);
7876 val
->PortSupportedSpeed
=
7877 port
->fp_hba_port_attrs
.supported_speed
;
7879 switch (FC_PORT_SPEED_MASK(port
->fp_state
)) {
7880 case FC_STATE_1GBIT_SPEED
:
7881 val
->PortSpeed
= FC_HBA_PORTSPEED_1GBIT
;
7883 case FC_STATE_2GBIT_SPEED
:
7884 val
->PortSpeed
= FC_HBA_PORTSPEED_2GBIT
;
7886 case FC_STATE_4GBIT_SPEED
:
7887 val
->PortSpeed
= FC_HBA_PORTSPEED_4GBIT
;
7889 case FC_STATE_8GBIT_SPEED
:
7890 val
->PortSpeed
= FC_HBA_PORTSPEED_8GBIT
;
7892 case FC_STATE_10GBIT_SPEED
:
7893 val
->PortSpeed
= FC_HBA_PORTSPEED_10GBIT
;
7895 case FC_STATE_16GBIT_SPEED
:
7896 val
->PortSpeed
= FC_HBA_PORTSPEED_16GBIT
;
7899 val
->PortSpeed
= FC_HBA_PORTSPEED_UNKNOWN
;
7902 val
->PortMaxFrameSize
= port
->fp_hba_port_attrs
.max_frame_size
;
7903 val
->NumberofDiscoveredPorts
= port
->fp_dev_count
;
7904 mutex_exit(&port
->fp_mutex
);
7906 if (use32
== B_TRUE
) {
7907 val32
= kmem_zalloc(sizeof (*val32
), KM_SLEEP
);
7908 val32
->version
= val
->version
;
7909 val32
->lastChange
= val
->lastChange
;
7910 val32
->fp_minor
= val
->fp_minor
;
7912 bcopy(&val
->PortWWN
.raw_wwn
, &val32
->PortWWN
.raw_wwn
,
7913 sizeof (val
->PortWWN
.raw_wwn
));
7914 bcopy(&val
->NodeWWN
.raw_wwn
, &val32
->NodeWWN
.raw_wwn
,
7915 sizeof (val
->NodeWWN
.raw_wwn
));
7916 val32
->PortFcId
= val
->PortFcId
;
7917 val32
->PortState
= val
->PortState
;
7918 val32
->PortType
= val
->PortType
;
7920 val32
->PortSupportedClassofService
=
7921 val
->PortSupportedClassofService
;
7922 bcopy(val
->PortActiveFc4Types
,
7923 val32
->PortActiveFc4Types
,
7924 sizeof (val
->PortActiveFc4Types
));
7925 bcopy(val
->PortSymbolicName
, val32
->PortSymbolicName
,
7926 sizeof (val
->PortSymbolicName
));
7927 bcopy(&val
->FabricName
, &val32
->FabricName
,
7928 sizeof (val
->FabricName
.raw_wwn
));
7929 val32
->PortSupportedSpeed
= val
->PortSupportedSpeed
;
7930 val32
->PortSpeed
= val
->PortSpeed
;
7932 val32
->PortMaxFrameSize
= val
->PortMaxFrameSize
;
7933 val32
->NumberofDiscoveredPorts
=
7934 val
->NumberofDiscoveredPorts
;
7936 if (fp_copyout((void *)val32
, (void *)fcio
->fcio_obuf
,
7937 fcio
->fcio_olen
, mode
) == 0) {
7938 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7945 kmem_free(val32
, sizeof (*val32
));
7947 if (fp_copyout((void *)val
, (void *)fcio
->fcio_obuf
,
7948 fcio
->fcio_olen
, mode
) == 0) {
7949 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7957 kmem_free(val
, sizeof (*val
));
7961 case FCIO_GET_DISCOVERED_PORT_ATTRIBUTES
: {
7962 fc_hba_port_attributes_t
*val
;
7963 fc_hba_port_attributes32_t
*val32
;
7965 fc_remote_port_t
*tmp_pd
;
7967 if (use32
== B_TRUE
) {
7968 if (fcio
->fcio_olen
< sizeof (*val32
) ||
7969 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7974 if (fcio
->fcio_olen
< sizeof (*val
) ||
7975 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
7981 if (ddi_copyin(fcio
->fcio_ibuf
, &index
, sizeof (index
), mode
)) {
7986 if (index
>= port
->fp_dev_count
) {
7987 FP_TRACE(FP_NHEAD1(9, 0),
7988 "User supplied index out of range");
7989 fcio
->fcio_errno
= FC_OUTOFBOUNDS
;
7991 if (fp_fcio_copyout(fcio
, data
, mode
)) {
7997 val
= kmem_zalloc(sizeof (*val
), KM_SLEEP
);
7998 val
->version
= FC_HBA_PORT_ATTRIBUTES_VERSION
;
8000 mutex_enter(&port
->fp_mutex
);
8001 tmp_pd
= fctl_lookup_pd_by_index(port
, index
);
8003 if (tmp_pd
== NULL
) {
8004 fcio
->fcio_errno
= FC_BADPORT
;
8007 val
->lastChange
= port
->fp_last_change
;
8008 val
->fp_minor
= port
->fp_instance
;
8010 mutex_enter(&tmp_pd
->pd_mutex
);
8011 bcopy(&tmp_pd
->pd_port_name
.raw_wwn
,
8012 &val
->PortWWN
.raw_wwn
,
8013 sizeof (val
->PortWWN
.raw_wwn
));
8014 bcopy(&tmp_pd
->pd_remote_nodep
->fd_node_name
.raw_wwn
,
8015 &val
->NodeWWN
.raw_wwn
,
8016 sizeof (val
->NodeWWN
.raw_wwn
));
8017 val
->PortFcId
= tmp_pd
->pd_port_id
.port_id
;
8018 bcopy(tmp_pd
->pd_spn
, val
->PortSymbolicName
,
8019 tmp_pd
->pd_spn_len
);
8020 val
->PortSupportedClassofService
= tmp_pd
->pd_cos
;
8022 * we will assume the sizeof these pd_fc4types and
8023 * portActiveFc4Types will remain the same. we could
8024 * add in a check for it, but we decided it was unneeded
8026 bcopy((caddr_t
)tmp_pd
->pd_fc4types
,
8027 val
->PortActiveFc4Types
,
8028 sizeof (tmp_pd
->pd_fc4types
));
8030 fp_map_remote_port_state(tmp_pd
->pd_state
);
8031 mutex_exit(&tmp_pd
->pd_mutex
);
8033 val
->PortType
= FC_HBA_PORTTYPE_UNKNOWN
;
8034 val
->PortSupportedFc4Types
[0] = 0;
8035 val
->PortSupportedSpeed
= FC_HBA_PORTSPEED_UNKNOWN
;
8036 val
->PortSpeed
= FC_HBA_PORTSPEED_UNKNOWN
;
8037 val
->PortMaxFrameSize
= 0;
8038 val
->NumberofDiscoveredPorts
= 0;
8040 if (use32
== B_TRUE
) {
8041 val32
= kmem_zalloc(sizeof (*val32
), KM_SLEEP
);
8042 val32
->version
= val
->version
;
8043 val32
->lastChange
= val
->lastChange
;
8044 val32
->fp_minor
= val
->fp_minor
;
8046 bcopy(&val
->PortWWN
.raw_wwn
,
8047 &val32
->PortWWN
.raw_wwn
,
8048 sizeof (val
->PortWWN
.raw_wwn
));
8049 bcopy(&val
->NodeWWN
.raw_wwn
,
8050 &val32
->NodeWWN
.raw_wwn
,
8051 sizeof (val
->NodeWWN
.raw_wwn
));
8052 val32
->PortFcId
= val
->PortFcId
;
8053 bcopy(val
->PortSymbolicName
,
8054 val32
->PortSymbolicName
,
8055 sizeof (val
->PortSymbolicName
));
8056 val32
->PortSupportedClassofService
=
8057 val
->PortSupportedClassofService
;
8058 bcopy(val
->PortActiveFc4Types
,
8059 val32
->PortActiveFc4Types
,
8060 sizeof (tmp_pd
->pd_fc4types
));
8062 val32
->PortType
= val
->PortType
;
8063 val32
->PortState
= val
->PortState
;
8064 val32
->PortSupportedFc4Types
[0] =
8065 val
->PortSupportedFc4Types
[0];
8066 val32
->PortSupportedSpeed
=
8067 val
->PortSupportedSpeed
;
8068 val32
->PortSpeed
= val
->PortSpeed
;
8069 val32
->PortMaxFrameSize
=
8070 val
->PortMaxFrameSize
;
8071 val32
->NumberofDiscoveredPorts
=
8072 val
->NumberofDiscoveredPorts
;
8074 if (fp_copyout((void *)val32
,
8075 (void *)fcio
->fcio_obuf
,
8076 fcio
->fcio_olen
, mode
) == 0) {
8077 if (fp_fcio_copyout(fcio
,
8085 kmem_free(val32
, sizeof (*val32
));
8087 if (fp_copyout((void *)val
,
8088 (void *)fcio
->fcio_obuf
,
8089 fcio
->fcio_olen
, mode
) == 0) {
8090 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8099 mutex_exit(&port
->fp_mutex
);
8100 kmem_free(val
, sizeof (*val
));
8104 case FCIO_GET_PORT_ATTRIBUTES
: {
8105 fc_hba_port_attributes_t
*val
;
8106 fc_hba_port_attributes32_t
*val32
;
8108 fc_remote_port_t
*tmp_pd
;
8110 if (use32
== B_TRUE
) {
8111 if (fcio
->fcio_olen
< sizeof (*val32
) ||
8112 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
8117 if (fcio
->fcio_olen
< sizeof (*val
) ||
8118 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
8124 if (ddi_copyin(fcio
->fcio_ibuf
, &wwn
, sizeof (wwn
), mode
)) {
8129 val
= kmem_zalloc(sizeof (*val
), KM_SLEEP
);
8130 val
->version
= FC_HBA_PORT_ATTRIBUTES_VERSION
;
8132 mutex_enter(&port
->fp_mutex
);
8133 tmp_pd
= fctl_lookup_pd_by_wwn(port
, wwn
);
8134 val
->lastChange
= port
->fp_last_change
;
8135 val
->fp_minor
= port
->fp_instance
;
8136 mutex_exit(&port
->fp_mutex
);
8138 if (tmp_pd
== NULL
) {
8139 fcio
->fcio_errno
= FC_BADWWN
;
8142 mutex_enter(&tmp_pd
->pd_mutex
);
8143 bcopy(&tmp_pd
->pd_port_name
.raw_wwn
,
8144 &val
->PortWWN
.raw_wwn
,
8145 sizeof (val
->PortWWN
.raw_wwn
));
8146 bcopy(&tmp_pd
->pd_remote_nodep
->fd_node_name
.raw_wwn
,
8147 &val
->NodeWWN
.raw_wwn
,
8148 sizeof (val
->NodeWWN
.raw_wwn
));
8149 val
->PortFcId
= tmp_pd
->pd_port_id
.port_id
;
8150 bcopy(tmp_pd
->pd_spn
, val
->PortSymbolicName
,
8151 tmp_pd
->pd_spn_len
);
8152 val
->PortSupportedClassofService
= tmp_pd
->pd_cos
;
8153 val
->PortType
= FC_HBA_PORTTYPE_UNKNOWN
;
8155 fp_map_remote_port_state(tmp_pd
->pd_state
);
8156 val
->PortSupportedFc4Types
[0] = 0;
8158 * we will assume the sizeof these pd_fc4types and
8159 * portActiveFc4Types will remain the same. we could
8160 * add in a check for it, but we decided it was unneeded
8162 bcopy((caddr_t
)tmp_pd
->pd_fc4types
,
8163 val
->PortActiveFc4Types
,
8164 sizeof (tmp_pd
->pd_fc4types
));
8165 val
->PortSupportedSpeed
= FC_HBA_PORTSPEED_UNKNOWN
;
8166 val
->PortSpeed
= FC_HBA_PORTSPEED_UNKNOWN
;
8167 val
->PortMaxFrameSize
= 0;
8168 val
->NumberofDiscoveredPorts
= 0;
8169 mutex_exit(&tmp_pd
->pd_mutex
);
8171 if (use32
== B_TRUE
) {
8172 val32
= kmem_zalloc(sizeof (*val32
), KM_SLEEP
);
8173 val32
->version
= val
->version
;
8174 val32
->lastChange
= val
->lastChange
;
8175 val32
->fp_minor
= val
->fp_minor
;
8176 bcopy(&val
->PortWWN
.raw_wwn
,
8177 &val32
->PortWWN
.raw_wwn
,
8178 sizeof (val
->PortWWN
.raw_wwn
));
8179 bcopy(&val
->NodeWWN
.raw_wwn
,
8180 &val32
->NodeWWN
.raw_wwn
,
8181 sizeof (val
->NodeWWN
.raw_wwn
));
8182 val32
->PortFcId
= val
->PortFcId
;
8183 bcopy(val
->PortSymbolicName
,
8184 val32
->PortSymbolicName
,
8185 sizeof (val
->PortSymbolicName
));
8186 val32
->PortSupportedClassofService
=
8187 val
->PortSupportedClassofService
;
8188 val32
->PortType
= val
->PortType
;
8189 val32
->PortState
= val
->PortState
;
8190 val32
->PortSupportedFc4Types
[0] =
8191 val
->PortSupportedFc4Types
[0];
8192 bcopy(val
->PortActiveFc4Types
,
8193 val32
->PortActiveFc4Types
,
8194 sizeof (tmp_pd
->pd_fc4types
));
8195 val32
->PortSupportedSpeed
=
8196 val
->PortSupportedSpeed
;
8197 val32
->PortSpeed
= val
->PortSpeed
;
8198 val32
->PortMaxFrameSize
= val
->PortMaxFrameSize
;
8199 val32
->NumberofDiscoveredPorts
=
8200 val
->NumberofDiscoveredPorts
;
8202 if (fp_copyout((void *)val32
,
8203 (void *)fcio
->fcio_obuf
,
8204 fcio
->fcio_olen
, mode
) == 0) {
8205 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8212 kmem_free(val32
, sizeof (*val32
));
8214 if (fp_copyout((void *)val
,
8215 (void *)fcio
->fcio_obuf
,
8216 fcio
->fcio_olen
, mode
) == 0) {
8217 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8225 kmem_free(val
, sizeof (*val
));
8229 case FCIO_GET_NUM_DEVS
: {
8232 if (fcio
->fcio_olen
!= sizeof (num_devices
) ||
8233 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
8238 mutex_enter(&port
->fp_mutex
);
8239 switch (port
->fp_topology
) {
8240 case FC_TOP_PRIVATE_LOOP
:
8242 num_devices
= port
->fp_total_devices
;
8243 fcio
->fcio_errno
= FC_SUCCESS
;
8246 case FC_TOP_PUBLIC_LOOP
:
8248 mutex_exit(&port
->fp_mutex
);
8249 job
= fctl_alloc_job(JOB_NS_CMD
, 0, NULL
,
8251 ASSERT(job
!= NULL
);
8254 * In FC-GS-2 the Name Server doesn't send out
8255 * RSCNs for any Name Server Database updates
8256 * When it is finally fixed there is no need
8257 * to probe as below and should be removed.
8259 (void) fp_ns_get_devcount(port
, job
, 0, KM_SLEEP
);
8260 fctl_dealloc_job(job
);
8262 mutex_enter(&port
->fp_mutex
);
8263 num_devices
= port
->fp_total_devices
;
8264 fcio
->fcio_errno
= FC_SUCCESS
;
8269 case FC_TOP_UNKNOWN
:
8273 fcio
->fcio_errno
= FC_SUCCESS
;
8276 mutex_exit(&port
->fp_mutex
);
8278 if (fp_copyout((void *)&num_devices
,
8279 (void *)fcio
->fcio_obuf
, fcio
->fcio_olen
,
8281 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8290 case FCIO_GET_DEV_LIST
: {
8295 if (fcio
->fcio_xfer
!= FCIO_XFER_READ
||
8296 fcio
->fcio_alen
!= sizeof (new_count
)) {
8301 num_devices
= fcio
->fcio_olen
/ sizeof (fc_port_dev_t
);
8303 mutex_enter(&port
->fp_mutex
);
8304 if (num_devices
< port
->fp_total_devices
) {
8305 fcio
->fcio_errno
= FC_TOOMANY
;
8306 new_count
= port
->fp_total_devices
;
8307 mutex_exit(&port
->fp_mutex
);
8309 if (fp_copyout((void *)&new_count
,
8310 (void *)fcio
->fcio_abuf
,
8311 sizeof (new_count
), mode
)) {
8316 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8324 if (port
->fp_total_devices
<= 0) {
8325 fcio
->fcio_errno
= FC_NO_MAP
;
8326 new_count
= port
->fp_total_devices
;
8327 mutex_exit(&port
->fp_mutex
);
8329 if (fp_copyout((void *)&new_count
,
8330 (void *)fcio
->fcio_abuf
,
8331 sizeof (new_count
), mode
)) {
8336 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8344 switch (port
->fp_topology
) {
8345 case FC_TOP_PRIVATE_LOOP
:
8346 if (fp_fillout_loopmap(port
, fcio
,
8347 mode
) != FC_SUCCESS
) {
8351 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8357 if (fp_fillout_p2pmap(port
, fcio
,
8358 mode
) != FC_SUCCESS
) {
8362 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8367 case FC_TOP_PUBLIC_LOOP
:
8368 case FC_TOP_FABRIC
: {
8369 fctl_ns_req_t
*ns_cmd
;
8372 sizeof (fc_port_dev_t
) * port
->fp_total_devices
;
8374 mutex_exit(&port
->fp_mutex
);
8376 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gan_t
),
8377 sizeof (ns_resp_gan_t
), map_size
,
8378 (FCTL_NS_FILL_NS_MAP
| FCTL_NS_BUF_IS_USERLAND
),
8380 ASSERT(ns_cmd
!= NULL
);
8382 ns_cmd
->ns_gan_index
= 0;
8383 ns_cmd
->ns_gan_sid
= FCTL_GAN_START_ID
;
8384 ns_cmd
->ns_cmd_code
= NS_GA_NXT
;
8385 ns_cmd
->ns_gan_max
= map_size
/ sizeof (fc_port_dev_t
);
8387 job
= fctl_alloc_job(JOB_PORT_GETMAP
, 0, NULL
,
8389 ASSERT(job
!= NULL
);
8391 ret
= fp_ns_query(port
, ns_cmd
, job
, 1, KM_SLEEP
);
8393 if (ret
!= FC_SUCCESS
||
8394 job
->job_result
!= FC_SUCCESS
) {
8395 fctl_free_ns_cmd(ns_cmd
);
8397 fcio
->fcio_errno
= job
->job_result
;
8399 if (fp_copyout((void *)&new_count
,
8400 (void *)fcio
->fcio_abuf
,
8401 sizeof (new_count
), mode
)) {
8402 fctl_dealloc_job(job
);
8403 mutex_enter(&port
->fp_mutex
);
8408 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8409 fctl_dealloc_job(job
);
8410 mutex_enter(&port
->fp_mutex
);
8415 mutex_enter(&port
->fp_mutex
);
8418 fctl_dealloc_job(job
);
8420 new_count
= ns_cmd
->ns_gan_index
;
8421 if (fp_copyout((void *)&new_count
,
8422 (void *)fcio
->fcio_abuf
, sizeof (new_count
),
8425 fctl_free_ns_cmd(ns_cmd
);
8426 mutex_enter(&port
->fp_mutex
);
8430 if (fp_copyout((void *)ns_cmd
->ns_data_buf
,
8431 (void *)fcio
->fcio_obuf
, sizeof (fc_port_dev_t
) *
8432 ns_cmd
->ns_gan_index
, mode
)) {
8434 fctl_free_ns_cmd(ns_cmd
);
8435 mutex_enter(&port
->fp_mutex
);
8438 fctl_free_ns_cmd(ns_cmd
);
8440 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8443 mutex_enter(&port
->fp_mutex
);
8449 case FC_TOP_UNKNOWN
:
8452 fcio
->fcio_errno
= FC_NO_MAP
;
8453 num_devices
= port
->fp_total_devices
;
8455 if (fp_copyout((void *)&new_count
,
8456 (void *)fcio
->fcio_abuf
,
8457 sizeof (new_count
), mode
)) {
8462 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8469 mutex_exit(&port
->fp_mutex
);
8473 case FCIO_GET_SYM_PNAME
: {
8478 case FCIO_GET_SYM_NNAME
: {
8483 case FCIO_SET_SYM_PNAME
: {
8488 case FCIO_SET_SYM_NNAME
: {
8493 case FCIO_GET_LOGI_PARAMS
: {
8496 la_els_logi_t
*params
;
8497 la_els_logi32_t
*params32
;
8498 fc_remote_node_t
*node
;
8499 fc_remote_port_t
*pd
;
8501 if (fcio
->fcio_ilen
!= sizeof (la_wwn_t
) ||
8502 (fcio
->fcio_xfer
& FCIO_XFER_READ
) == 0 ||
8503 (fcio
->fcio_xfer
& FCIO_XFER_WRITE
) == 0) {
8508 if (use32
== B_TRUE
) {
8509 if (fcio
->fcio_olen
!= sizeof (la_els_logi32_t
)) {
8514 if (fcio
->fcio_olen
!= sizeof (la_els_logi_t
)) {
8520 if (ddi_copyin(fcio
->fcio_ibuf
, &pwwn
, sizeof (pwwn
), mode
)) {
8525 pd
= fctl_hold_remote_port_by_pwwn(port
, &pwwn
);
8527 mutex_enter(&port
->fp_mutex
);
8528 my_pwwn
= &port
->fp_service_params
.nport_ww_name
;
8529 mutex_exit(&port
->fp_mutex
);
8531 if (fctl_wwn_cmp(&pwwn
, my_pwwn
) != 0) {
8536 params
= kmem_zalloc(sizeof (*params
), KM_SLEEP
);
8537 mutex_enter(&port
->fp_mutex
);
8538 *params
= port
->fp_service_params
;
8539 mutex_exit(&port
->fp_mutex
);
8541 params
= kmem_zalloc(sizeof (*params
), KM_SLEEP
);
8543 mutex_enter(&pd
->pd_mutex
);
8544 params
->ls_code
.mbz
= params
->ls_code
.ls_code
= 0;
8545 params
->common_service
= pd
->pd_csp
;
8546 params
->nport_ww_name
= pd
->pd_port_name
;
8547 params
->class_1
= pd
->pd_clsp1
;
8548 params
->class_2
= pd
->pd_clsp2
;
8549 params
->class_3
= pd
->pd_clsp3
;
8550 node
= pd
->pd_remote_nodep
;
8551 mutex_exit(&pd
->pd_mutex
);
8553 bzero(params
->reserved
, sizeof (params
->reserved
));
8555 mutex_enter(&node
->fd_mutex
);
8556 bcopy(node
->fd_vv
, params
->vendor_version
,
8557 sizeof (node
->fd_vv
));
8558 params
->node_ww_name
= node
->fd_node_name
;
8559 mutex_exit(&node
->fd_mutex
);
8561 fctl_release_remote_port(pd
);
8564 if (use32
== B_TRUE
) {
8565 params32
= kmem_zalloc(sizeof (*params32
), KM_SLEEP
);
8567 params32
->ls_code
.mbz
= params
->ls_code
.mbz
;
8568 params32
->common_service
= params
->common_service
;
8569 params32
->nport_ww_name
= params
->nport_ww_name
;
8570 params32
->class_1
= params
->class_1
;
8571 params32
->class_2
= params
->class_2
;
8572 params32
->class_3
= params
->class_3
;
8573 bzero(params32
->reserved
, sizeof (params32
->reserved
));
8574 bcopy(params
->vendor_version
, params32
->vendor_version
,
8575 sizeof (node
->fd_vv
));
8576 params32
->node_ww_name
= params
->node_ww_name
;
8578 if (ddi_copyout((void *)params32
,
8579 (void *)fcio
->fcio_obuf
,
8580 sizeof (*params32
), mode
)) {
8584 kmem_free(params32
, sizeof (*params32
));
8586 if (ddi_copyout((void *)params
, (void *)fcio
->fcio_obuf
,
8587 sizeof (*params
), mode
)) {
8592 kmem_free(params
, sizeof (*params
));
8593 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8599 case FCIO_DEV_LOGOUT
:
8600 case FCIO_DEV_LOGIN
:
8601 if (fcio
->fcio_ilen
!= sizeof (la_wwn_t
) ||
8602 fcio
->fcio_xfer
!= FCIO_XFER_WRITE
) {
8605 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8611 if (fcio
->fcio_cmd
== FCIO_DEV_LOGIN
) {
8612 jcode
= JOB_FCIO_LOGIN
;
8614 jcode
= JOB_FCIO_LOGOUT
;
8617 kfcio
= kmem_zalloc(sizeof (*kfcio
), KM_SLEEP
);
8618 bcopy(fcio
, kfcio
, sizeof (*fcio
));
8620 if (kfcio
->fcio_ilen
) {
8621 kfcio
->fcio_ibuf
= kmem_zalloc(kfcio
->fcio_ilen
,
8624 if (ddi_copyin((void *)fcio
->fcio_ibuf
,
8625 (void *)kfcio
->fcio_ibuf
, kfcio
->fcio_ilen
,
8629 kmem_free(kfcio
->fcio_ibuf
, kfcio
->fcio_ilen
);
8630 kmem_free(kfcio
, sizeof (*kfcio
));
8631 fcio
->fcio_errno
= job
->job_result
;
8632 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8639 job
= fctl_alloc_job(jcode
, 0, NULL
, NULL
, KM_SLEEP
);
8640 job
->job_private
= kfcio
;
8642 fctl_enque_job(port
, job
);
8645 rval
= job
->job_result
;
8647 fcio
->fcio_errno
= kfcio
->fcio_errno
;
8648 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8652 kmem_free(kfcio
->fcio_ibuf
, kfcio
->fcio_ilen
);
8653 kmem_free(kfcio
, sizeof (*kfcio
));
8654 fctl_dealloc_job(job
);
8657 case FCIO_GET_STATE
: {
8660 fc_remote_port_t
*pd
;
8661 fctl_ns_req_t
*ns_cmd
;
8663 if (fcio
->fcio_ilen
!= sizeof (la_wwn_t
) ||
8664 fcio
->fcio_olen
!= sizeof (state
) ||
8665 (fcio
->fcio_xfer
& FCIO_XFER_WRITE
) == 0 ||
8666 (fcio
->fcio_xfer
& FCIO_XFER_READ
) == 0) {
8671 if (ddi_copyin(fcio
->fcio_ibuf
, &pwwn
, sizeof (pwwn
), mode
)) {
8675 fcio
->fcio_errno
= 0;
8677 pd
= fctl_hold_remote_port_by_pwwn(port
, &pwwn
);
8679 mutex_enter(&port
->fp_mutex
);
8680 if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
8681 mutex_exit(&port
->fp_mutex
);
8682 job
= fctl_alloc_job(JOB_PLOGI_ONE
, 0,
8683 NULL
, NULL
, KM_SLEEP
);
8685 job
->job_counter
= 1;
8686 job
->job_result
= FC_SUCCESS
;
8688 ns_cmd
= fctl_alloc_ns_cmd(
8689 sizeof (ns_req_gid_pn_t
),
8690 sizeof (ns_resp_gid_pn_t
),
8691 sizeof (ns_resp_gid_pn_t
),
8692 FCTL_NS_BUF_IS_USERLAND
, KM_SLEEP
);
8693 ASSERT(ns_cmd
!= NULL
);
8695 ns_cmd
->ns_cmd_code
= NS_GID_PN
;
8696 ((ns_req_gid_pn_t
*)
8697 (ns_cmd
->ns_cmd_buf
))->pwwn
= pwwn
;
8699 ret
= fp_ns_query(port
, ns_cmd
, job
,
8702 if (ret
!= FC_SUCCESS
|| job
->job_result
!=
8704 if (ret
!= FC_SUCCESS
) {
8705 fcio
->fcio_errno
= ret
;
8712 state
= PORT_DEVICE_INVALID
;
8714 fctl_free_ns_cmd(ns_cmd
);
8715 fctl_dealloc_job(job
);
8717 mutex_exit(&port
->fp_mutex
);
8718 fcio
->fcio_errno
= FC_BADWWN
;
8722 mutex_enter(&pd
->pd_mutex
);
8723 state
= pd
->pd_state
;
8724 mutex_exit(&pd
->pd_mutex
);
8726 fctl_release_remote_port(pd
);
8730 if (ddi_copyout((void *)&state
,
8731 (void *)fcio
->fcio_obuf
, sizeof (state
),
8736 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8742 case FCIO_DEV_REMOVE
: {
8744 fc_portmap_t
*changelist
;
8745 fc_remote_port_t
*pd
;
8747 if (fcio
->fcio_ilen
!= sizeof (la_wwn_t
) ||
8748 fcio
->fcio_xfer
!= FCIO_XFER_WRITE
) {
8753 if (ddi_copyin(fcio
->fcio_ibuf
, &pwwn
, sizeof (pwwn
), mode
)) {
8758 pd
= fctl_hold_remote_port_by_pwwn(port
, &pwwn
);
8761 fcio
->fcio_errno
= FC_BADWWN
;
8762 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8768 mutex_enter(&pd
->pd_mutex
);
8769 if (pd
->pd_ref_count
> 1) {
8770 mutex_exit(&pd
->pd_mutex
);
8773 fcio
->fcio_errno
= FC_FAILURE
;
8774 fctl_release_remote_port(pd
);
8776 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8781 mutex_exit(&pd
->pd_mutex
);
8783 changelist
= kmem_zalloc(sizeof (*changelist
), KM_SLEEP
);
8785 fctl_copy_portmap(changelist
, pd
);
8786 changelist
->map_type
= PORT_DEVICE_USER_LOGOUT
;
8787 (void) fp_ulp_devc_cb(port
, changelist
, 1, 1, KM_SLEEP
, 1);
8789 fctl_release_remote_port(pd
);
8793 case FCIO_GET_FCODE_REV
: {
8797 if (fcio
->fcio_olen
< FC_FCODE_REV_SIZE
||
8798 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
8802 bzero((caddr_t
)&pm
, sizeof (pm
));
8804 fcode_rev
= kmem_zalloc(fcio
->fcio_olen
, KM_SLEEP
);
8806 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
8807 pm
.pm_cmd_code
= FC_PORT_GET_FCODE_REV
;
8808 pm
.pm_data_len
= fcio
->fcio_olen
;
8809 pm
.pm_data_buf
= fcode_rev
;
8811 ret
= port
->fp_fca_tran
->fca_port_manage(
8812 port
->fp_fca_handle
, &pm
);
8814 if (ret
== FC_SUCCESS
) {
8815 if (ddi_copyout((void *)fcode_rev
,
8816 (void *)fcio
->fcio_obuf
,
8817 fcio
->fcio_olen
, mode
) == 0) {
8818 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8826 * check if buffer was not large enough to obtain
8829 if (pm
.pm_data_len
> fcio
->fcio_olen
) {
8834 fcio
->fcio_errno
= ret
;
8835 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8839 kmem_free(fcode_rev
, fcio
->fcio_olen
);
8843 case FCIO_GET_FW_REV
: {
8847 if (fcio
->fcio_olen
< FC_FW_REV_SIZE
||
8848 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
8852 bzero((caddr_t
)&pm
, sizeof (pm
));
8854 fw_rev
= kmem_zalloc(fcio
->fcio_olen
, KM_SLEEP
);
8856 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
8857 pm
.pm_cmd_code
= FC_PORT_GET_FW_REV
;
8858 pm
.pm_data_len
= fcio
->fcio_olen
;
8859 pm
.pm_data_buf
= fw_rev
;
8861 ret
= port
->fp_fca_tran
->fca_port_manage(
8862 port
->fp_fca_handle
, &pm
);
8864 if (ret
== FC_SUCCESS
) {
8865 if (ddi_copyout((void *)fw_rev
,
8866 (void *)fcio
->fcio_obuf
,
8867 fcio
->fcio_olen
, mode
) == 0) {
8868 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8875 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8880 kmem_free(fw_rev
, fcio
->fcio_olen
);
8884 case FCIO_GET_DUMP_SIZE
: {
8888 if (fcio
->fcio_olen
!= sizeof (dump_size
) ||
8889 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
8893 bzero((caddr_t
)&pm
, sizeof (pm
));
8894 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
8895 pm
.pm_cmd_code
= FC_PORT_GET_DUMP_SIZE
;
8896 pm
.pm_data_len
= sizeof (dump_size
);
8897 pm
.pm_data_buf
= (caddr_t
)&dump_size
;
8899 ret
= port
->fp_fca_tran
->fca_port_manage(
8900 port
->fp_fca_handle
, &pm
);
8902 if (ret
== FC_SUCCESS
) {
8903 if (ddi_copyout((void *)&dump_size
,
8904 (void *)fcio
->fcio_obuf
, sizeof (dump_size
),
8906 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8913 fcio
->fcio_errno
= ret
;
8915 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8922 case FCIO_DOWNLOAD_FW
: {
8926 if (fcio
->fcio_ilen
<= 0 ||
8927 fcio
->fcio_xfer
!= FCIO_XFER_WRITE
) {
8932 firmware
= kmem_zalloc(fcio
->fcio_ilen
, KM_SLEEP
);
8933 if (ddi_copyin(fcio
->fcio_ibuf
, firmware
,
8934 fcio
->fcio_ilen
, mode
)) {
8936 kmem_free(firmware
, fcio
->fcio_ilen
);
8940 bzero((caddr_t
)&pm
, sizeof (pm
));
8941 pm
.pm_cmd_flags
= FC_FCA_PM_WRITE
;
8942 pm
.pm_cmd_code
= FC_PORT_DOWNLOAD_FW
;
8943 pm
.pm_data_len
= fcio
->fcio_ilen
;
8944 pm
.pm_data_buf
= firmware
;
8946 ret
= port
->fp_fca_tran
->fca_port_manage(
8947 port
->fp_fca_handle
, &pm
);
8949 kmem_free(firmware
, fcio
->fcio_ilen
);
8951 if (ret
!= FC_SUCCESS
) {
8952 fcio
->fcio_errno
= ret
;
8954 if (fp_fcio_copyout(fcio
, data
, mode
)) {
8961 case FCIO_DOWNLOAD_FCODE
: {
8965 if (fcio
->fcio_ilen
<= 0 ||
8966 fcio
->fcio_xfer
!= FCIO_XFER_WRITE
) {
8971 fcode
= kmem_zalloc(fcio
->fcio_ilen
, KM_SLEEP
);
8972 if (ddi_copyin(fcio
->fcio_ibuf
, fcode
,
8973 fcio
->fcio_ilen
, mode
)) {
8975 kmem_free(fcode
, fcio
->fcio_ilen
);
8979 bzero((caddr_t
)&pm
, sizeof (pm
));
8980 pm
.pm_cmd_flags
= FC_FCA_PM_WRITE
;
8981 pm
.pm_cmd_code
= FC_PORT_DOWNLOAD_FCODE
;
8982 pm
.pm_data_len
= fcio
->fcio_ilen
;
8983 pm
.pm_data_buf
= fcode
;
8985 ret
= port
->fp_fca_tran
->fca_port_manage(
8986 port
->fp_fca_handle
, &pm
);
8988 kmem_free(fcode
, fcio
->fcio_ilen
);
8990 if (ret
!= FC_SUCCESS
) {
8991 fcio
->fcio_errno
= ret
;
8993 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9000 case FCIO_FORCE_DUMP
:
9001 ret
= port
->fp_fca_tran
->fca_reset(
9002 port
->fp_fca_handle
, FC_FCA_CORE
);
9004 if (ret
!= FC_SUCCESS
) {
9005 fcio
->fcio_errno
= ret
;
9007 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9013 case FCIO_GET_DUMP
: {
9018 if (fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
9022 bzero((caddr_t
)&pm
, sizeof (pm
));
9024 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
9025 pm
.pm_cmd_code
= FC_PORT_GET_DUMP_SIZE
;
9026 pm
.pm_data_len
= sizeof (dump_size
);
9027 pm
.pm_data_buf
= (caddr_t
)&dump_size
;
9029 ret
= port
->fp_fca_tran
->fca_port_manage(
9030 port
->fp_fca_handle
, &pm
);
9032 if (ret
!= FC_SUCCESS
) {
9033 fcio
->fcio_errno
= ret
;
9035 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9040 if (fcio
->fcio_olen
!= dump_size
) {
9041 fcio
->fcio_errno
= FC_NOMEM
;
9043 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9049 dump
= kmem_zalloc(dump_size
, KM_SLEEP
);
9051 bzero((caddr_t
)&pm
, sizeof (pm
));
9052 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
9053 pm
.pm_cmd_code
= FC_PORT_GET_DUMP
;
9054 pm
.pm_data_len
= dump_size
;
9055 pm
.pm_data_buf
= dump
;
9057 ret
= port
->fp_fca_tran
->fca_port_manage(
9058 port
->fp_fca_handle
, &pm
);
9060 if (ret
== FC_SUCCESS
) {
9061 if (ddi_copyout((void *)dump
, (void *)fcio
->fcio_obuf
,
9062 dump_size
, mode
) == 0) {
9063 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9070 fcio
->fcio_errno
= ret
;
9072 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9076 kmem_free(dump
, dump_size
);
9080 case FCIO_GET_TOPOLOGY
: {
9081 uint32_t user_topology
;
9083 if (fcio
->fcio_xfer
!= FCIO_XFER_READ
||
9084 fcio
->fcio_olen
!= sizeof (user_topology
)) {
9089 mutex_enter(&port
->fp_mutex
);
9090 if (FC_PORT_STATE_MASK(port
->fp_state
) == FC_STATE_OFFLINE
) {
9091 user_topology
= FC_TOP_UNKNOWN
;
9093 user_topology
= port
->fp_topology
;
9095 mutex_exit(&port
->fp_mutex
);
9097 if (ddi_copyout((void *)&user_topology
,
9098 (void *)fcio
->fcio_obuf
, sizeof (user_topology
),
9105 case FCIO_RESET_LINK
: {
9109 * Look at the output buffer field; if this field has zero
9110 * bytes then attempt to reset the local link/loop. If the
9111 * fcio_ibuf field points to a WWN, see if it's an NL_Port,
9112 * and if yes, determine the LFA and reset the remote LIP
9116 if (fcio
->fcio_xfer
!= FCIO_XFER_WRITE
||
9117 fcio
->fcio_ilen
!= sizeof (pwwn
)) {
9122 if (ddi_copyin(fcio
->fcio_ibuf
, &pwwn
,
9123 sizeof (pwwn
), mode
)) {
9128 mutex_enter(&port
->fp_mutex
);
9129 if (port
->fp_soft_state
& FP_SOFT_IN_LINK_RESET
) {
9130 mutex_exit(&port
->fp_mutex
);
9133 port
->fp_soft_state
|= FP_SOFT_IN_LINK_RESET
;
9134 mutex_exit(&port
->fp_mutex
);
9136 job
= fctl_alloc_job(JOB_LINK_RESET
, 0, NULL
, NULL
, KM_SLEEP
);
9141 job
->job_counter
= 1;
9142 job
->job_private
= (void *)&pwwn
;
9144 fctl_enque_job(port
, job
);
9147 mutex_enter(&port
->fp_mutex
);
9148 port
->fp_soft_state
&= ~FP_SOFT_IN_LINK_RESET
;
9149 mutex_exit(&port
->fp_mutex
);
9151 if (job
->job_result
!= FC_SUCCESS
) {
9152 fcio
->fcio_errno
= job
->job_result
;
9154 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9158 fctl_dealloc_job(job
);
9162 case FCIO_RESET_HARD
:
9163 ret
= port
->fp_fca_tran
->fca_reset(
9164 port
->fp_fca_handle
, FC_FCA_RESET
);
9165 if (ret
!= FC_SUCCESS
) {
9166 fcio
->fcio_errno
= ret
;
9168 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9174 case FCIO_RESET_HARD_CORE
:
9175 ret
= port
->fp_fca_tran
->fca_reset(
9176 port
->fp_fca_handle
, FC_FCA_RESET_CORE
);
9177 if (ret
!= FC_SUCCESS
) {
9179 fcio
->fcio_errno
= ret
;
9180 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9189 bzero((caddr_t
)&pm
, sizeof (fc_fca_pm_t
));
9191 /* Validate user buffer from ioctl call. */
9192 if (((fcio
->fcio_ilen
> 0) && (fcio
->fcio_ibuf
== NULL
)) ||
9193 ((fcio
->fcio_ilen
<= 0) && (fcio
->fcio_ibuf
!= NULL
)) ||
9194 ((fcio
->fcio_alen
> 0) && (fcio
->fcio_abuf
== NULL
)) ||
9195 ((fcio
->fcio_alen
<= 0) && (fcio
->fcio_abuf
!= NULL
)) ||
9196 ((fcio
->fcio_olen
> 0) && (fcio
->fcio_obuf
== NULL
)) ||
9197 ((fcio
->fcio_olen
<= 0) && (fcio
->fcio_obuf
!= NULL
))) {
9202 if ((pm
.pm_cmd_len
= fcio
->fcio_ilen
) > 0) {
9203 pm
.pm_cmd_buf
= kmem_zalloc(fcio
->fcio_ilen
, KM_SLEEP
);
9204 if (ddi_copyin(fcio
->fcio_ibuf
, pm
.pm_cmd_buf
,
9205 fcio
->fcio_ilen
, mode
)) {
9207 goto fp_fcio_diag_cleanup
;
9211 if ((pm
.pm_data_len
= fcio
->fcio_alen
) > 0) {
9212 pm
.pm_data_buf
= kmem_zalloc(fcio
->fcio_alen
, KM_SLEEP
);
9213 if (ddi_copyin(fcio
->fcio_abuf
, pm
.pm_data_buf
,
9214 fcio
->fcio_alen
, mode
)) {
9216 goto fp_fcio_diag_cleanup
;
9220 if ((pm
.pm_stat_len
= fcio
->fcio_olen
) > 0) {
9221 pm
.pm_stat_buf
= kmem_zalloc(fcio
->fcio_olen
, KM_SLEEP
);
9224 pm
.pm_cmd_code
= FC_PORT_DIAG
;
9225 pm
.pm_cmd_flags
= fcio
->fcio_cmd_flags
;
9227 ret
= port
->fp_fca_tran
->fca_port_manage(
9228 port
->fp_fca_handle
, &pm
);
9230 if (ret
!= FC_SUCCESS
) {
9231 if (ret
== FC_INVALID_REQUEST
) {
9237 fcio
->fcio_errno
= ret
;
9238 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9241 goto fp_fcio_diag_cleanup
;
9245 * pm_stat_len will contain the number of status bytes
9246 * an FCA driver requires to return the complete status
9247 * of the requested diag operation. If the user buffer
9248 * is not large enough to hold the entire status, We
9249 * copy only the portion of data the fits in the buffer and
9250 * return a ENOMEM to the user application.
9252 if (pm
.pm_stat_len
> fcio
->fcio_olen
) {
9253 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
9254 "fp:FCIO_DIAG:status buffer too small\n");
9257 if (ddi_copyout(pm
.pm_stat_buf
, fcio
->fcio_obuf
,
9258 fcio
->fcio_olen
, mode
)) {
9260 goto fp_fcio_diag_cleanup
;
9264 * Copy only data pm_stat_len bytes of data
9266 if (ddi_copyout(pm
.pm_stat_buf
, fcio
->fcio_obuf
,
9267 pm
.pm_stat_len
, mode
)) {
9269 goto fp_fcio_diag_cleanup
;
9273 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9277 fp_fcio_diag_cleanup
:
9278 if (pm
.pm_cmd_buf
!= NULL
) {
9279 kmem_free(pm
.pm_cmd_buf
, fcio
->fcio_ilen
);
9281 if (pm
.pm_data_buf
!= NULL
) {
9282 kmem_free(pm
.pm_data_buf
, fcio
->fcio_alen
);
9284 if (pm
.pm_stat_buf
!= NULL
) {
9285 kmem_free(pm
.pm_stat_buf
, fcio
->fcio_olen
);
9291 case FCIO_GET_NODE_ID
: {
9292 /* validate parameters */
9293 if (fcio
->fcio_xfer
!= FCIO_XFER_READ
||
9294 fcio
->fcio_olen
< sizeof (fc_rnid_t
)) {
9299 rval
= fp_get_rnid(port
, data
, mode
, fcio
);
9301 /* ioctl handling is over */
9305 case FCIO_SEND_NODE_ID
: {
9308 /* validate parameters */
9309 if (fcio
->fcio_ilen
!= sizeof (la_wwn_t
) ||
9310 fcio
->fcio_xfer
!= FCIO_XFER_READ
) {
9315 if (ddi_copyin(fcio
->fcio_ibuf
, &pwwn
,
9316 sizeof (la_wwn_t
), mode
)) {
9321 rval
= fp_send_rnid(port
, data
, mode
, fcio
, &pwwn
);
9323 /* ioctl handling is over */
9327 case FCIO_SET_NODE_ID
: {
9328 if (fcio
->fcio_ilen
!= sizeof (fc_rnid_t
) ||
9329 (fcio
->fcio_xfer
!= FCIO_XFER_WRITE
)) {
9334 rval
= fp_set_rnid(port
, data
, mode
, fcio
);
9338 case FCIO_LINK_STATUS
: {
9339 fc_portid_t rls_req
;
9340 fc_rls_acc_t
*rls_acc
;
9342 uint32_t dest
, src_id
;
9344 fc_remote_port_t
*pd
;
9347 /* validate parameters */
9348 if (fcio
->fcio_ilen
!= sizeof (fc_portid_t
) ||
9349 fcio
->fcio_olen
!= sizeof (fc_rls_acc_t
) ||
9350 fcio
->fcio_xfer
!= FCIO_XFER_RW
) {
9355 if ((fcio
->fcio_cmd_flags
!= FCIO_CFLAGS_RLS_DEST_FPORT
) &&
9356 (fcio
->fcio_cmd_flags
!= FCIO_CFLAGS_RLS_DEST_NPORT
)) {
9361 if (ddi_copyin((void *)fcio
->fcio_ibuf
, (void *)&rls_req
,
9362 sizeof (fc_portid_t
), mode
)) {
9368 /* Determine the destination of the RLS frame */
9369 if (fcio
->fcio_cmd_flags
== FCIO_CFLAGS_RLS_DEST_FPORT
) {
9370 dest
= FS_FABRIC_F_PORT
;
9372 dest
= rls_req
.port_id
;
9375 mutex_enter(&port
->fp_mutex
);
9376 src_id
= port
->fp_port_id
.port_id
;
9377 mutex_exit(&port
->fp_mutex
);
9379 /* If dest is zero OR same as FCA ID, then use port_manage() */
9380 if (dest
== 0 || dest
== src_id
) {
9382 /* Allocate memory for link error status block */
9383 rls_acc
= kmem_zalloc(sizeof (*rls_acc
), KM_SLEEP
);
9384 ASSERT(rls_acc
!= NULL
);
9386 /* Prepare the port management structure */
9387 bzero((caddr_t
)&pm
, sizeof (pm
));
9389 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
9390 pm
.pm_cmd_code
= FC_PORT_RLS
;
9391 pm
.pm_data_len
= sizeof (*rls_acc
);
9392 pm
.pm_data_buf
= (caddr_t
)rls_acc
;
9394 /* Get the adapter's link error status block */
9395 ret
= port
->fp_fca_tran
->fca_port_manage(
9396 port
->fp_fca_handle
, &pm
);
9398 if (ret
== FC_SUCCESS
) {
9399 /* xfer link status block to userland */
9400 if (ddi_copyout((void *)rls_acc
,
9401 (void *)fcio
->fcio_obuf
,
9402 sizeof (*rls_acc
), mode
) == 0) {
9403 if (fp_fcio_copyout(fcio
, data
,
9412 fcio
->fcio_errno
= ret
;
9413 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9418 kmem_free(rls_acc
, sizeof (*rls_acc
));
9420 /* ioctl handling is over */
9425 * Send RLS to the destination port.
9426 * Having RLS frame destination is as FPORT is not yet
9427 * supported and will be implemented in future, if needed.
9428 * Following call to get "pd" will fail if dest is FPORT
9430 pd
= fctl_hold_remote_port_by_did(port
, dest
);
9432 fcio
->fcio_errno
= FC_BADOBJECT
;
9434 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9440 mutex_enter(&pd
->pd_mutex
);
9441 if (pd
->pd_state
!= PORT_DEVICE_LOGGED_IN
) {
9442 mutex_exit(&pd
->pd_mutex
);
9443 fctl_release_remote_port(pd
);
9445 fcio
->fcio_errno
= FC_LOGINREQ
;
9447 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9452 ASSERT(pd
->pd_login_count
>= 1);
9453 mutex_exit(&pd
->pd_mutex
);
9456 * Allocate job structure and set job_code as DUMMY,
9457 * because we will not go through the job thread.
9458 * Instead fp_sendcmd() is called directly here.
9460 job
= fctl_alloc_job(JOB_DUMMY
, JOB_TYPE_FP_ASYNC
,
9461 NULL
, NULL
, KM_SLEEP
);
9462 ASSERT(job
!= NULL
);
9464 job
->job_counter
= 1;
9466 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rls_t
),
9467 sizeof (la_els_rls_acc_t
), KM_SLEEP
, pd
);
9469 fcio
->fcio_errno
= FC_NOMEM
;
9472 fctl_release_remote_port(pd
);
9474 fctl_dealloc_job(job
);
9475 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9481 /* Allocate memory for link error status block */
9482 rls_acc
= kmem_zalloc(sizeof (*rls_acc
), KM_SLEEP
);
9484 mutex_enter(&port
->fp_mutex
);
9485 mutex_enter(&pd
->pd_mutex
);
9487 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
9488 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
9489 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
9490 cmd
->cmd_retry_count
= 1;
9491 cmd
->cmd_ulp_pkt
= NULL
;
9493 fp_rls_init(cmd
, job
);
9495 job
->job_private
= (void *)rls_acc
;
9497 pd_flags
= pd
->pd_flags
;
9498 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
9500 mutex_exit(&pd
->pd_mutex
);
9501 mutex_exit(&port
->fp_mutex
);
9503 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) == FC_SUCCESS
) {
9506 fcio
->fcio_errno
= job
->job_result
;
9507 if (job
->job_result
== FC_SUCCESS
) {
9510 * link error status block is now available.
9511 * Copy it to userland
9513 ASSERT(job
->job_private
== (void *)rls_acc
);
9514 if (ddi_copyout((void *)rls_acc
,
9515 (void *)fcio
->fcio_obuf
,
9516 sizeof (*rls_acc
), mode
) == 0) {
9517 if (fp_fcio_copyout(fcio
, data
,
9533 mutex_enter(&port
->fp_mutex
);
9534 mutex_enter(&pd
->pd_mutex
);
9535 if (pd
->pd_flags
== PD_ELS_IN_PROGRESS
) {
9536 pd
->pd_flags
= pd_flags
;
9538 mutex_exit(&pd
->pd_mutex
);
9539 mutex_exit(&port
->fp_mutex
);
9542 fctl_release_remote_port(pd
);
9543 fctl_dealloc_job(job
);
9544 kmem_free(rls_acc
, sizeof (*rls_acc
));
9546 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9553 fc_ns_cmd_t
*ns_req
;
9554 fc_ns_cmd32_t
*ns_req32
;
9555 fctl_ns_req_t
*ns_cmd
;
9557 if (use32
== B_TRUE
) {
9558 if (fcio
->fcio_ilen
!= sizeof (*ns_req32
)) {
9563 ns_req
= kmem_zalloc(sizeof (*ns_req
), KM_SLEEP
);
9564 ns_req32
= kmem_zalloc(sizeof (*ns_req32
), KM_SLEEP
);
9566 if (ddi_copyin(fcio
->fcio_ibuf
, ns_req32
,
9567 sizeof (*ns_req32
), mode
)) {
9569 kmem_free(ns_req
, sizeof (*ns_req
));
9570 kmem_free(ns_req32
, sizeof (*ns_req32
));
9574 ns_req
->ns_flags
= ns_req32
->ns_flags
;
9575 ns_req
->ns_cmd
= ns_req32
->ns_cmd
;
9576 ns_req
->ns_req_len
= ns_req32
->ns_req_len
;
9577 ns_req
->ns_req_payload
= ns_req32
->ns_req_payload
;
9578 ns_req
->ns_resp_len
= ns_req32
->ns_resp_len
;
9579 ns_req
->ns_resp_payload
= ns_req32
->ns_resp_payload
;
9580 ns_req
->ns_fctl_private
= ns_req32
->ns_fctl_private
;
9581 ns_req
->ns_resp_hdr
= ns_req32
->ns_resp_hdr
;
9583 kmem_free(ns_req32
, sizeof (*ns_req32
));
9585 if (fcio
->fcio_ilen
!= sizeof (*ns_req
)) {
9590 ns_req
= kmem_zalloc(sizeof (*ns_req
), KM_SLEEP
);
9592 if (ddi_copyin(fcio
->fcio_ibuf
, ns_req
,
9593 sizeof (fc_ns_cmd_t
), mode
)) {
9595 kmem_free(ns_req
, sizeof (*ns_req
));
9600 if (ns_req
->ns_req_len
<= 0) {
9602 kmem_free(ns_req
, sizeof (*ns_req
));
9606 job
= fctl_alloc_job(JOB_NS_CMD
, 0, NULL
, NULL
, KM_SLEEP
);
9607 ASSERT(job
!= NULL
);
9609 ns_cmd
= fctl_alloc_ns_cmd(ns_req
->ns_req_len
,
9610 ns_req
->ns_resp_len
, ns_req
->ns_resp_len
,
9611 FCTL_NS_FILL_NS_MAP
, KM_SLEEP
);
9612 ASSERT(ns_cmd
!= NULL
);
9613 ns_cmd
->ns_cmd_code
= ns_req
->ns_cmd
;
9615 if (ns_cmd
->ns_cmd_code
== NS_GA_NXT
) {
9616 ns_cmd
->ns_gan_max
= 1;
9617 ns_cmd
->ns_gan_index
= 0;
9618 ns_cmd
->ns_gan_sid
= FCTL_GAN_START_ID
;
9621 if (ddi_copyin(ns_req
->ns_req_payload
,
9622 ns_cmd
->ns_cmd_buf
, ns_req
->ns_req_len
, mode
)) {
9624 fctl_free_ns_cmd(ns_cmd
);
9625 fctl_dealloc_job(job
);
9626 kmem_free(ns_req
, sizeof (*ns_req
));
9630 job
->job_private
= (void *)ns_cmd
;
9631 fctl_enque_job(port
, job
);
9633 rval
= job
->job_result
;
9635 if (rval
== FC_SUCCESS
) {
9636 if (ns_req
->ns_resp_len
) {
9637 if (ddi_copyout(ns_cmd
->ns_data_buf
,
9638 ns_req
->ns_resp_payload
,
9639 ns_cmd
->ns_data_len
, mode
)) {
9641 fctl_free_ns_cmd(ns_cmd
);
9642 fctl_dealloc_job(job
);
9643 kmem_free(ns_req
, sizeof (*ns_req
));
9650 ns_req
->ns_resp_hdr
= ns_cmd
->ns_resp_hdr
;
9651 fctl_free_ns_cmd(ns_cmd
);
9652 fctl_dealloc_job(job
);
9653 kmem_free(ns_req
, sizeof (*ns_req
));
9655 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9667 * If set, reset the EXCL busy bit to
9668 * receive other exclusive access commands
9670 mutex_enter(&port
->fp_mutex
);
9671 if (port
->fp_flag
& FP_EXCL_BUSY
) {
9672 port
->fp_flag
&= ~FP_EXCL_BUSY
;
9674 mutex_exit(&port
->fp_mutex
);
9681 * This function assumes that the response length
9682 * is same regardless of data model (LP32 or LP64)
9683 * which is true for all the ioctls currently
9687 fp_copyout(void *from
, void *to
, size_t len
, int mode
)
9689 return (ddi_copyout(from
, to
, len
, mode
));
9693 * This function does the set rnid
9696 fp_set_rnid(fc_local_port_t
*port
, intptr_t data
, int mode
, fcio_t
*fcio
)
9702 /* Allocate memory for node id block */
9703 rnid
= kmem_zalloc(sizeof (fc_rnid_t
), KM_SLEEP
);
9705 if (ddi_copyin(fcio
->fcio_ibuf
, rnid
, sizeof (fc_rnid_t
), mode
)) {
9706 FP_TRACE(FP_NHEAD1(3, 0), "fp_set_rnid: failed = %d", EFAULT
);
9707 kmem_free(rnid
, sizeof (fc_rnid_t
));
9711 /* Prepare the port management structure */
9712 bzero((caddr_t
)&pm
, sizeof (pm
));
9714 pm
.pm_cmd_flags
= FC_FCA_PM_WRITE
;
9715 pm
.pm_cmd_code
= FC_PORT_SET_NODE_ID
;
9716 pm
.pm_data_len
= sizeof (*rnid
);
9717 pm
.pm_data_buf
= (caddr_t
)rnid
;
9719 /* Get the adapter's node data */
9720 rval
= port
->fp_fca_tran
->fca_port_manage(
9721 port
->fp_fca_handle
, &pm
);
9723 if (rval
!= FC_SUCCESS
) {
9724 fcio
->fcio_errno
= rval
;
9726 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9730 mutex_enter(&port
->fp_mutex
);
9731 /* copy to the port structure */
9732 bcopy(rnid
, &port
->fp_rnid_params
,
9733 sizeof (port
->fp_rnid_params
));
9734 mutex_exit(&port
->fp_mutex
);
9737 kmem_free(rnid
, sizeof (fc_rnid_t
));
9739 if (rval
!= FC_SUCCESS
) {
9740 FP_TRACE(FP_NHEAD1(3, 0), "fp_set_rnid: failed = %d", rval
);
9747 * This function does the local pwwn get rnid
9750 fp_get_rnid(fc_local_port_t
*port
, intptr_t data
, int mode
, fcio_t
*fcio
)
9757 /* Allocate memory for rnid data block */
9758 rnid
= kmem_zalloc(sizeof (fc_rnid_t
), KM_SLEEP
);
9760 mutex_enter(&port
->fp_mutex
);
9761 if (port
->fp_rnid_init
== 1) {
9762 bcopy(&port
->fp_rnid_params
, rnid
, sizeof (fc_rnid_t
));
9763 mutex_exit(&port
->fp_mutex
);
9764 /* xfer node info to userland */
9765 if (ddi_copyout((void *)rnid
, (void *)fcio
->fcio_obuf
,
9766 sizeof (*rnid
), mode
) == 0) {
9767 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9774 kmem_free(rnid
, sizeof (fc_rnid_t
));
9776 if (rval
!= FC_SUCCESS
) {
9777 FP_TRACE(FP_NHEAD1(3, 0), "fp_get_rnid: failed = %d",
9783 mutex_exit(&port
->fp_mutex
);
9785 /* Prepare the port management structure */
9786 bzero((caddr_t
)&pm
, sizeof (pm
));
9788 pm
.pm_cmd_flags
= FC_FCA_PM_READ
;
9789 pm
.pm_cmd_code
= FC_PORT_GET_NODE_ID
;
9790 pm
.pm_data_len
= sizeof (fc_rnid_t
);
9791 pm
.pm_data_buf
= (caddr_t
)rnid
;
9793 /* Get the adapter's node data */
9794 ret
= port
->fp_fca_tran
->fca_port_manage(
9795 port
->fp_fca_handle
,
9798 if (ret
== FC_SUCCESS
) {
9799 /* initialize in the port_info */
9800 mutex_enter(&port
->fp_mutex
);
9801 port
->fp_rnid_init
= 1;
9802 bcopy(rnid
, &port
->fp_rnid_params
, sizeof (*rnid
));
9803 mutex_exit(&port
->fp_mutex
);
9805 /* xfer node info to userland */
9806 if (ddi_copyout((void *)rnid
,
9807 (void *)fcio
->fcio_obuf
,
9808 sizeof (*rnid
), mode
) == 0) {
9809 if (fp_fcio_copyout(fcio
, data
,
9818 fcio
->fcio_errno
= ret
;
9819 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9824 kmem_free(rnid
, sizeof (fc_rnid_t
));
9826 if (rval
!= FC_SUCCESS
) {
9827 FP_TRACE(FP_NHEAD1(3, 0), "fp_get_rnid: failed = %d", rval
);
9834 fp_send_rnid(fc_local_port_t
*port
, intptr_t data
, int mode
, fcio_t
*fcio
,
9838 fc_remote_port_t
*pd
;
9841 la_els_rnid_acc_t
*rnid_acc
;
9843 pd
= fctl_get_remote_port_by_pwwn(port
, pwwn
);
9846 * We can safely assume that the destination port
9847 * is logged in. Either the user land will explicitly
9848 * login before issuing RNID ioctl or the device would
9849 * have been configured, meaning already logged in.
9852 FP_TRACE(FP_NHEAD1(3, 0), "fp_send_rnid: failed = %d", ENXIO
);
9857 * Allocate job structure and set job_code as DUMMY,
9858 * because we will not go thorugh the job thread.
9859 * Instead fp_sendcmd() is called directly here.
9861 job
= fctl_alloc_job(JOB_DUMMY
, JOB_TYPE_FP_ASYNC
,
9862 NULL
, NULL
, KM_SLEEP
);
9864 ASSERT(job
!= NULL
);
9866 job
->job_counter
= 1;
9868 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rnid_t
),
9869 sizeof (la_els_rnid_acc_t
), KM_SLEEP
, pd
);
9871 fcio
->fcio_errno
= FC_NOMEM
;
9874 fctl_dealloc_job(job
);
9875 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9879 FP_TRACE(FP_NHEAD1(3, 0), "fp_send_rnid: failed = %d", rval
);
9884 /* Allocate memory for node id accept block */
9885 rnid_acc
= kmem_zalloc(sizeof (la_els_rnid_acc_t
), KM_SLEEP
);
9887 mutex_enter(&port
->fp_mutex
);
9888 mutex_enter(&pd
->pd_mutex
);
9890 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
9891 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
9892 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
9893 cmd
->cmd_retry_count
= 1;
9894 cmd
->cmd_ulp_pkt
= NULL
;
9896 fp_rnid_init(cmd
, fcio
->fcio_cmd_flags
, job
);
9898 job
->job_private
= (void *)rnid_acc
;
9900 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
9902 mutex_exit(&pd
->pd_mutex
);
9903 mutex_exit(&port
->fp_mutex
);
9905 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) == FC_SUCCESS
) {
9907 fcio
->fcio_errno
= job
->job_result
;
9908 if (job
->job_result
== FC_SUCCESS
) {
9912 * node id block is now available.
9913 * Copy it to userland
9915 ASSERT(job
->job_private
== (void *)rnid_acc
);
9917 /* get the response length */
9918 rnid_cnt
= sizeof (ls_code_t
) + sizeof (fc_rnid_hdr_t
) +
9919 rnid_acc
->hdr
.cmn_len
+
9920 rnid_acc
->hdr
.specific_len
;
9922 if (fcio
->fcio_olen
< rnid_cnt
) {
9924 } else if (ddi_copyout((void *)rnid_acc
,
9925 (void *)fcio
->fcio_obuf
,
9926 rnid_cnt
, mode
) == 0) {
9927 if (fp_fcio_copyout(fcio
, data
,
9940 mutex_enter(&pd
->pd_mutex
);
9941 pd
->pd_flags
= PD_IDLE
;
9942 mutex_exit(&pd
->pd_mutex
);
9947 fctl_dealloc_job(job
);
9948 kmem_free(rnid_acc
, sizeof (la_els_rnid_acc_t
));
9950 if (fp_fcio_copyout(fcio
, data
, mode
)) {
9954 if (rval
!= FC_SUCCESS
) {
9955 FP_TRACE(FP_NHEAD1(3, 0), "fp_send_rnid: failed = %d", rval
);
9962 * Copy out to userland
9965 fp_fcio_copyout(fcio_t
*fcio
, intptr_t data
, int mode
)
9969 #ifdef _MULTI_DATAMODEL
9970 switch (ddi_model_convert_from(mode
& FMODELS
)) {
9971 case DDI_MODEL_ILP32
: {
9972 struct fcio32 fcio32
;
9974 fcio32
.fcio_xfer
= fcio
->fcio_xfer
;
9975 fcio32
.fcio_cmd
= fcio
->fcio_cmd
;
9976 fcio32
.fcio_flags
= fcio
->fcio_flags
;
9977 fcio32
.fcio_cmd_flags
= fcio
->fcio_cmd_flags
;
9978 fcio32
.fcio_ilen
= fcio
->fcio_ilen
;
9980 (caddr32_t
)(uintptr_t)fcio
->fcio_ibuf
;
9981 fcio32
.fcio_olen
= fcio
->fcio_olen
;
9983 (caddr32_t
)(uintptr_t)fcio
->fcio_obuf
;
9984 fcio32
.fcio_alen
= fcio
->fcio_alen
;
9986 (caddr32_t
)(uintptr_t)fcio
->fcio_abuf
;
9987 fcio32
.fcio_errno
= fcio
->fcio_errno
;
9989 rval
= ddi_copyout((void *)&fcio32
, (void *)data
,
9990 sizeof (struct fcio32
), mode
);
9993 case DDI_MODEL_NONE
:
9994 rval
= ddi_copyout((void *)fcio
, (void *)data
,
9995 sizeof (fcio_t
), mode
);
9999 rval
= ddi_copyout((void *)fcio
, (void *)data
, sizeof (fcio_t
), mode
);
10007 fp_p2p_online(fc_local_port_t
*port
, job_request_t
*job
)
10010 fc_portmap_t
*changelist
;
10012 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
10013 ASSERT(port
->fp_topology
== FC_TOP_PT_PT
);
10014 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
10019 if ((job
->job_flags
& JOB_CANCEL_ULP_NOTIFICATION
) == 0) {
10020 if (port
->fp_statec_busy
> 1) {
10021 job
->job_flags
|= JOB_CANCEL_ULP_NOTIFICATION
;
10024 mutex_exit(&port
->fp_mutex
);
10026 if ((job
->job_flags
& JOB_CANCEL_ULP_NOTIFICATION
) == 0) {
10027 fctl_fillout_map(port
, &changelist
, &listlen
, 1, 0, 0);
10028 (void) fp_ulp_statec_cb(port
, FC_STATE_ONLINE
, changelist
,
10029 listlen
, listlen
, KM_SLEEP
);
10031 mutex_enter(&port
->fp_mutex
);
10033 ASSERT(changelist
== NULL
&& listlen
== 0);
10034 mutex_enter(&port
->fp_mutex
);
10035 if (--port
->fp_statec_busy
== 0) {
10036 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
10042 fp_fillout_p2pmap(fc_local_port_t
*port
, fcio_t
*fcio
, int mode
)
10048 fc_remote_node_t
*node
;
10049 fc_port_dev_t
*devlist
;
10050 struct pwwn_hash
*head
;
10051 fc_remote_port_t
*pd
;
10053 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
10055 num_devices
= fcio
->fcio_olen
/ sizeof (fc_port_dev_t
);
10057 devlist
= kmem_zalloc(sizeof (fc_port_dev_t
) * num_devices
, KM_SLEEP
);
10059 for (count
= index
= 0; index
< pwwn_table_size
; index
++) {
10060 head
= &port
->fp_pwwn_table
[index
];
10061 pd
= head
->pwwn_head
;
10062 while (pd
!= NULL
) {
10063 mutex_enter(&pd
->pd_mutex
);
10064 if (pd
->pd_state
== PORT_DEVICE_INVALID
) {
10065 mutex_exit(&pd
->pd_mutex
);
10066 pd
= pd
->pd_wwn_hnext
;
10070 devlist
[count
].dev_state
= pd
->pd_state
;
10071 devlist
[count
].dev_hard_addr
= pd
->pd_hard_addr
;
10072 devlist
[count
].dev_did
= pd
->pd_port_id
;
10073 devlist
[count
].dev_did
.priv_lilp_posit
=
10074 (uint8_t)(index
& 0xff);
10075 bcopy((caddr_t
)pd
->pd_fc4types
,
10076 (caddr_t
)devlist
[count
].dev_type
,
10077 sizeof (pd
->pd_fc4types
));
10079 bcopy((caddr_t
)&pd
->pd_port_name
,
10080 (caddr_t
)&devlist
[count
].dev_pwwn
,
10081 sizeof (la_wwn_t
));
10083 node
= pd
->pd_remote_nodep
;
10084 mutex_exit(&pd
->pd_mutex
);
10087 mutex_enter(&node
->fd_mutex
);
10088 bcopy((caddr_t
)&node
->fd_node_name
,
10089 (caddr_t
)&devlist
[count
].dev_nwwn
,
10090 sizeof (la_wwn_t
));
10091 mutex_exit(&node
->fd_mutex
);
10094 if (count
>= num_devices
) {
10100 if (fp_copyout((void *)&count
, (void *)fcio
->fcio_abuf
,
10101 sizeof (count
), mode
)) {
10103 } else if (fp_copyout((void *)devlist
, (void *)fcio
->fcio_obuf
,
10104 sizeof (fc_port_dev_t
) * num_devices
, mode
)) {
10110 kmem_free(devlist
, sizeof (fc_port_dev_t
) * num_devices
);
10117 * Handle Fabric ONLINE
10120 fp_fabric_online(fc_local_port_t
*port
, job_request_t
*job
)
10129 fctl_ns_req_t
*ns_cmd
;
10130 struct pwwn_hash
*head
;
10131 fc_remote_port_t
*pd
;
10132 fc_remote_port_t
*npd
;
10133 fc_portmap_t
*changelist
;
10135 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
10136 ASSERT(FC_IS_TOP_SWITCH(port
->fp_topology
));
10137 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
10139 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gid_pn_t
),
10140 sizeof (ns_resp_gid_pn_t
), sizeof (ns_resp_gid_pn_t
),
10143 ASSERT(ns_cmd
!= NULL
);
10145 ns_cmd
->ns_cmd_code
= NS_GID_PN
;
10148 * Check if orphans are showing up now
10150 if (port
->fp_orphan_count
) {
10152 fc_orphan_t
*norp
= NULL
;
10153 fc_orphan_t
*prev
= NULL
;
10155 for (orp
= port
->fp_orphan_list
; orp
; orp
= norp
) {
10156 norp
= orp
->orp_next
;
10157 mutex_exit(&port
->fp_mutex
);
10160 job
->job_counter
= 1;
10161 job
->job_result
= FC_SUCCESS
;
10163 ((ns_req_gid_pn_t
*)
10164 (ns_cmd
->ns_cmd_buf
))->pwwn
= orp
->orp_pwwn
;
10165 ((ns_resp_gid_pn_t
*)
10166 ns_cmd
->ns_data_buf
)->pid
.port_id
= 0;
10167 ((ns_resp_gid_pn_t
*)
10168 ns_cmd
->ns_data_buf
)->pid
.priv_lilp_posit
= 0;
10170 rval
= fp_ns_query(port
, ns_cmd
, job
, 1, KM_SLEEP
);
10171 if (rval
== FC_SUCCESS
) {
10173 BE_32(*((uint32_t *)ns_cmd
->ns_data_buf
));
10174 pd
= fp_create_remote_port_by_ns(port
,
10178 fc_wwn_to_str(&orp
->orp_pwwn
, ww_name
);
10180 fp_printf(port
, CE_WARN
, FP_LOG_ONLY
,
10181 0, NULL
, "N_x Port with D_ID=%x,"
10182 " PWWN=%s reappeared in fabric",
10185 mutex_enter(&port
->fp_mutex
);
10187 prev
->orp_next
= orp
->orp_next
;
10190 port
->fp_orphan_list
);
10191 port
->fp_orphan_list
=
10194 port
->fp_orphan_count
--;
10195 mutex_exit(&port
->fp_mutex
);
10196 kmem_free(orp
, sizeof (*orp
));
10199 mutex_enter(&pd
->pd_mutex
);
10200 pd
->pd_flags
= PD_ELS_MARK
;
10202 mutex_exit(&pd
->pd_mutex
);
10207 if (orp
->orp_nscan
== FC_ORPHAN_SCAN_LIMIT
) {
10208 fc_wwn_to_str(&orp
->orp_pwwn
, ww_name
);
10210 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0,
10212 " Port WWN %s removed from orphan"
10213 " list after %d scans", ww_name
,
10216 mutex_enter(&port
->fp_mutex
);
10218 prev
->orp_next
= orp
->orp_next
;
10221 port
->fp_orphan_list
);
10222 port
->fp_orphan_list
=
10225 port
->fp_orphan_count
--;
10226 mutex_exit(&port
->fp_mutex
);
10228 kmem_free(orp
, sizeof (*orp
));
10233 mutex_enter(&port
->fp_mutex
);
10238 * Walk the Port WWN hash table, reestablish LOGIN
10239 * if a LOGIN is already performed on a particular
10240 * device; Any failure to LOGIN should mark the
10243 for (index
= 0; index
< pwwn_table_size
; index
++) {
10244 head
= &port
->fp_pwwn_table
[index
];
10245 npd
= head
->pwwn_head
;
10247 while ((pd
= npd
) != NULL
) {
10250 npd
= pd
->pd_wwn_hnext
;
10253 * Don't count in the port devices that are new
10254 * unless the total number of devices visible
10255 * through this port is less than FP_MAX_DEVICES
10257 mutex_enter(&pd
->pd_mutex
);
10258 if (port
->fp_dev_count
>= FP_MAX_DEVICES
||
10259 (port
->fp_options
& FP_TARGET_MODE
)) {
10260 if (pd
->pd_type
== PORT_DEVICE_NEW
||
10261 pd
->pd_flags
== PD_ELS_MARK
||
10262 pd
->pd_recepient
!= PD_PLOGI_INITIATOR
) {
10263 mutex_exit(&pd
->pd_mutex
);
10267 if (pd
->pd_flags
== PD_ELS_MARK
||
10268 pd
->pd_recepient
!= PD_PLOGI_INITIATOR
) {
10269 mutex_exit(&pd
->pd_mutex
);
10272 pd
->pd_type
= PORT_DEVICE_OLD
;
10277 * Consult with the name server about D_ID changes
10279 job
->job_counter
= 1;
10280 job
->job_result
= FC_SUCCESS
;
10282 ((ns_req_gid_pn_t
*)
10283 (ns_cmd
->ns_cmd_buf
))->pwwn
= pd
->pd_port_name
;
10284 ((ns_resp_gid_pn_t
*)
10285 ns_cmd
->ns_data_buf
)->pid
.port_id
= 0;
10287 ((ns_resp_gid_pn_t
*)ns_cmd
->ns_data_buf
)->
10288 pid
.priv_lilp_posit
= 0;
10290 pwwn
= &pd
->pd_port_name
;
10291 pd
->pd_flags
= PD_ELS_MARK
;
10293 mutex_exit(&pd
->pd_mutex
);
10294 mutex_exit(&port
->fp_mutex
);
10296 rval
= fp_ns_query(port
, ns_cmd
, job
, 1, KM_SLEEP
);
10297 if (rval
!= FC_SUCCESS
) {
10298 fc_wwn_to_str(pwwn
, ww_name
);
10300 mutex_enter(&pd
->pd_mutex
);
10301 d_id
= pd
->pd_port_id
.port_id
;
10302 pd
->pd_type
= PORT_DEVICE_DELETE
;
10303 mutex_exit(&pd
->pd_mutex
);
10305 FP_TRACE(FP_NHEAD1(3, 0),
10306 "fp_fabric_online: PD "
10307 "disappeared; d_id=%x, PWWN=%s",
10310 FP_TRACE(FP_NHEAD2(9, 0),
10311 "N_x Port with D_ID=%x, PWWN=%s"
10312 " disappeared from fabric", d_id
,
10315 mutex_enter(&port
->fp_mutex
);
10319 d_id
= BE_32(*((uint32_t *)ns_cmd
->ns_data_buf
));
10321 mutex_enter(&port
->fp_mutex
);
10322 mutex_enter(&pd
->pd_mutex
);
10323 if (d_id
!= pd
->pd_port_id
.port_id
) {
10324 fctl_delist_did_table(port
, pd
);
10325 fc_wwn_to_str(pwwn
, ww_name
);
10327 FP_TRACE(FP_NHEAD2(9, 0),
10328 "D_ID of a device with PWWN %s changed."
10329 " New D_ID = %x, OLD D_ID = %x", ww_name
,
10330 d_id
, pd
->pd_port_id
.port_id
);
10332 pd
->pd_port_id
.port_id
= BE_32(d_id
);
10333 pd
->pd_type
= PORT_DEVICE_CHANGED
;
10334 fctl_enlist_did_table(port
, pd
);
10336 mutex_exit(&pd
->pd_mutex
);
10342 fctl_free_ns_cmd(ns_cmd
);
10348 if (port
->fp_soft_state
& FP_SOFT_IN_FCA_RESET
) {
10349 port
->fp_soft_state
&= ~FP_SOFT_IN_FCA_RESET
;
10350 mutex_exit(&port
->fp_mutex
);
10351 ddi_sleep(FLA_RR_TOV
);
10352 mutex_enter(&port
->fp_mutex
);
10357 job
->job_counter
= count
;
10359 for (index
= 0; index
< pwwn_table_size
; index
++) {
10360 head
= &port
->fp_pwwn_table
[index
];
10361 npd
= head
->pwwn_head
;
10363 while ((pd
= npd
) != NULL
) {
10364 npd
= pd
->pd_wwn_hnext
;
10366 mutex_enter(&pd
->pd_mutex
);
10367 if (pd
->pd_flags
!= PD_ELS_MARK
) {
10368 mutex_exit(&pd
->pd_mutex
);
10375 * If it is already marked deletion, nothing
10378 if (pd
->pd_type
== PORT_DEVICE_DELETE
) {
10379 pd
->pd_type
= PORT_DEVICE_OLD
;
10381 mutex_exit(&pd
->pd_mutex
);
10382 mutex_exit(&port
->fp_mutex
);
10384 mutex_enter(&port
->fp_mutex
);
10390 * If it is freshly discovered out of
10391 * the orphan list, nothing else to do
10393 if (pd
->pd_type
== PORT_DEVICE_NEW
) {
10394 pd
->pd_flags
= PD_IDLE
;
10396 mutex_exit(&pd
->pd_mutex
);
10397 mutex_exit(&port
->fp_mutex
);
10399 mutex_enter(&port
->fp_mutex
);
10404 pd
->pd_flags
= PD_IDLE
;
10405 d_id
= pd
->pd_port_id
.port_id
;
10408 * Explicitly mark all devices OLD; successful
10409 * PLOGI should reset this to either NO_CHANGE
10412 if (pd
->pd_type
!= PORT_DEVICE_CHANGED
) {
10413 pd
->pd_type
= PORT_DEVICE_OLD
;
10416 mutex_exit(&pd
->pd_mutex
);
10417 mutex_exit(&port
->fp_mutex
);
10419 rval
= fp_port_login(port
, d_id
, job
,
10420 FP_CMD_PLOGI_RETAIN
, KM_SLEEP
, pd
, NULL
);
10422 if (rval
!= FC_SUCCESS
) {
10425 mutex_enter(&port
->fp_mutex
);
10428 mutex_exit(&port
->fp_mutex
);
10430 ASSERT(dbg_count
== count
);
10433 mutex_enter(&port
->fp_mutex
);
10435 ASSERT(port
->fp_statec_busy
> 0);
10436 if ((job
->job_flags
& JOB_CANCEL_ULP_NOTIFICATION
) == 0) {
10437 if (port
->fp_statec_busy
> 1) {
10438 job
->job_flags
|= JOB_CANCEL_ULP_NOTIFICATION
;
10441 mutex_exit(&port
->fp_mutex
);
10443 ASSERT(port
->fp_statec_busy
> 0);
10444 if (port
->fp_statec_busy
> 1) {
10445 job
->job_flags
|= JOB_CANCEL_ULP_NOTIFICATION
;
10447 mutex_exit(&port
->fp_mutex
);
10450 if ((job
->job_flags
& JOB_CANCEL_ULP_NOTIFICATION
) == 0) {
10451 fctl_fillout_map(port
, &changelist
, &listlen
, 1, 0, 0);
10453 (void) fp_ulp_statec_cb(port
, FC_STATE_ONLINE
, changelist
,
10454 listlen
, listlen
, KM_SLEEP
);
10456 mutex_enter(&port
->fp_mutex
);
10458 ASSERT(changelist
== NULL
&& listlen
== 0);
10459 mutex_enter(&port
->fp_mutex
);
10460 if (--port
->fp_statec_busy
== 0) {
10461 port
->fp_soft_state
&= ~FP_SOFT_IN_STATEC_CB
;
10468 * Fill out device list for userland ioctl in private loop
10471 fp_fillout_loopmap(fc_local_port_t
*port
, fcio_t
*fcio
, int mode
)
10477 fc_remote_node_t
*node
;
10478 fc_port_dev_t
*devlist
;
10479 int lilp_device_count
;
10480 fc_lilpmap_t
*lilp_map
;
10481 uchar_t
*alpa_list
;
10483 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
10485 num_devices
= fcio
->fcio_olen
/ sizeof (fc_port_dev_t
);
10486 if (port
->fp_total_devices
> port
->fp_dev_count
&&
10487 num_devices
>= port
->fp_total_devices
) {
10488 job_request_t
*job
;
10490 mutex_exit(&port
->fp_mutex
);
10491 job
= fctl_alloc_job(JOB_PORT_GETMAP
, 0, NULL
, NULL
, KM_SLEEP
);
10492 job
->job_counter
= 1;
10494 mutex_enter(&port
->fp_mutex
);
10495 fp_get_loopmap(port
, job
);
10496 mutex_exit(&port
->fp_mutex
);
10499 fctl_dealloc_job(job
);
10501 mutex_exit(&port
->fp_mutex
);
10503 devlist
= kmem_zalloc(sizeof (*devlist
) * num_devices
, KM_SLEEP
);
10505 mutex_enter(&port
->fp_mutex
);
10508 * Applications are accustomed to getting the device list in
10509 * LILP map order. The HBA firmware usually returns the device
10510 * map in the LILP map order and diagnostic applications would
10511 * prefer to receive in the device list in that order too
10513 lilp_map
= &port
->fp_lilp_map
;
10514 alpa_list
= &lilp_map
->lilp_alpalist
[0];
10517 * the length field corresponds to the offset in the LILP frame
10518 * which begins with 1. The thing to note here is that the
10519 * lilp_device_count is 1 more than fp->fp_total_devices since
10520 * the host adapter's alpa also shows up in the lilp map. We
10521 * don't however return details of the host adapter since
10522 * fctl_get_remote_port_by_did fails for the host adapter's ALPA
10523 * and applications are required to issue the FCIO_GET_HOST_PARAMS
10524 * ioctl to obtain details about the host adapter port.
10526 lilp_device_count
= lilp_map
->lilp_length
;
10528 for (count
= index
= 0; index
< lilp_device_count
&&
10529 count
< num_devices
; index
++) {
10531 fc_remote_port_t
*pd
;
10533 d_id
= alpa_list
[index
];
10535 mutex_exit(&port
->fp_mutex
);
10536 pd
= fctl_get_remote_port_by_did(port
, d_id
);
10537 mutex_enter(&port
->fp_mutex
);
10540 mutex_enter(&pd
->pd_mutex
);
10542 if (pd
->pd_state
== PORT_DEVICE_INVALID
) {
10543 mutex_exit(&pd
->pd_mutex
);
10547 devlist
[count
].dev_state
= pd
->pd_state
;
10548 devlist
[count
].dev_hard_addr
= pd
->pd_hard_addr
;
10549 devlist
[count
].dev_did
= pd
->pd_port_id
;
10550 devlist
[count
].dev_did
.priv_lilp_posit
=
10551 (uint8_t)(index
& 0xff);
10552 bcopy((caddr_t
)pd
->pd_fc4types
,
10553 (caddr_t
)devlist
[count
].dev_type
,
10554 sizeof (pd
->pd_fc4types
));
10556 bcopy((caddr_t
)&pd
->pd_port_name
,
10557 (caddr_t
)&devlist
[count
].dev_pwwn
,
10558 sizeof (la_wwn_t
));
10560 node
= pd
->pd_remote_nodep
;
10561 mutex_exit(&pd
->pd_mutex
);
10564 mutex_enter(&node
->fd_mutex
);
10565 bcopy((caddr_t
)&node
->fd_node_name
,
10566 (caddr_t
)&devlist
[count
].dev_nwwn
,
10567 sizeof (la_wwn_t
));
10568 mutex_exit(&node
->fd_mutex
);
10574 if (fp_copyout((void *)&count
, (void *)fcio
->fcio_abuf
,
10575 sizeof (count
), mode
)) {
10579 if (fp_copyout((void *)devlist
, (void *)fcio
->fcio_obuf
,
10580 sizeof (fc_port_dev_t
) * num_devices
, mode
)) {
10586 kmem_free(devlist
, sizeof (*devlist
) * num_devices
);
10587 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
10594 * Completion function for responses to unsolicited commands
10597 fp_unsol_intr(fc_packet_t
*pkt
)
10600 fc_local_port_t
*port
;
10602 cmd
= pkt
->pkt_ulp_private
;
10603 port
= cmd
->cmd_port
;
10605 mutex_enter(&port
->fp_mutex
);
10606 port
->fp_out_fpcmds
--;
10607 mutex_exit(&port
->fp_mutex
);
10609 if (pkt
->pkt_state
!= FC_PKT_SUCCESS
) {
10610 fp_printf(port
, CE_WARN
, FP_LOG_ONLY
, 0, pkt
,
10611 "couldn't post response to unsolicited request;"
10612 " ox_id=%x rx_id=%x", pkt
->pkt_cmd_fhdr
.ox_id
,
10613 pkt
->pkt_resp_fhdr
.rx_id
);
10616 if (cmd
== port
->fp_els_resp_pkt
) {
10617 mutex_enter(&port
->fp_mutex
);
10618 port
->fp_els_resp_pkt_busy
= 0;
10619 mutex_exit(&port
->fp_mutex
);
10628 * solicited LINIT ELS completion function
10631 fp_linit_intr(fc_packet_t
*pkt
)
10634 job_request_t
*job
;
10635 fc_linit_resp_t acc
;
10636 fc_local_port_t
*port
= ((fp_cmd_t
*)pkt
->pkt_ulp_private
)->cmd_port
;
10638 cmd
= (fp_cmd_t
*)pkt
->pkt_ulp_private
;
10640 mutex_enter(&cmd
->cmd_port
->fp_mutex
);
10641 cmd
->cmd_port
->fp_out_fpcmds
--;
10642 mutex_exit(&cmd
->cmd_port
->fp_mutex
);
10644 if (FP_IS_PKT_ERROR(pkt
)) {
10645 (void) fp_common_intr(pkt
, 1);
10649 job
= cmd
->cmd_job
;
10651 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&acc
,
10652 (uint8_t *)pkt
->pkt_resp
, sizeof (acc
), DDI_DEV_AUTOINCR
);
10653 if (acc
.status
!= FC_LINIT_SUCCESS
) {
10654 job
->job_result
= FC_FAILURE
;
10656 job
->job_result
= FC_SUCCESS
;
10664 * Decode the unsolicited request; For FC-4 Device and Link data frames
10665 * notify the registered ULP of this FC-4 type right here. For Unsolicited
10666 * ELS requests, submit a request to the job_handler thread to work on it.
10667 * The intent is to act quickly on the FC-4 unsolicited link and data frames
10668 * and save much of the interrupt time processing of unsolicited ELS requests
10669 * and hand it off to the job_handler thread.
10672 fp_unsol_cb(opaque_t port_handle
, fc_unsol_buf_t
*buf
, uint32_t type
)
10677 uint32_t rscn_count
= FC_INVALID_RSCN_COUNT
;
10680 fc_local_port_t
*port
;
10681 job_request_t
*job
;
10682 fc_remote_port_t
*pd
;
10684 port
= port_handle
;
10686 FP_TRACE(FP_NHEAD1(1, 0), "fp_unsol_cb: s_id=%x,"
10687 " d_id=%x, type=%x, r_ctl=%x, f_ctl=%x"
10688 " seq_id=%x, df_ctl=%x, seq_cnt=%x, ox_id=%x, rx_id=%x"
10689 " ro=%x, buffer[0]:%x", buf
->ub_frame
.s_id
, buf
->ub_frame
.d_id
,
10690 buf
->ub_frame
.type
, buf
->ub_frame
.r_ctl
, buf
->ub_frame
.f_ctl
,
10691 buf
->ub_frame
.seq_id
, buf
->ub_frame
.df_ctl
, buf
->ub_frame
.seq_cnt
,
10692 buf
->ub_frame
.ox_id
, buf
->ub_frame
.rx_id
, buf
->ub_frame
.ro
,
10693 buf
->ub_buffer
[0]);
10695 if (type
& 0x80000000) {
10697 * Huh ? Nothing much can be done without
10698 * a valid buffer. So just exit.
10703 * If the unsolicited interrupts arrive while it isn't
10704 * safe to handle unsolicited callbacks; Drop them, yes,
10705 * drop them on the floor
10707 mutex_enter(&port
->fp_mutex
);
10708 port
->fp_active_ubs
++;
10709 if ((port
->fp_soft_state
&
10710 (FP_SOFT_IN_DETACH
| FP_SOFT_SUSPEND
| FP_SOFT_POWER_DOWN
)) ||
10711 FC_PORT_STATE_MASK(port
->fp_state
) == FC_STATE_OFFLINE
) {
10713 FP_TRACE(FP_NHEAD1(3, 0), "fp_unsol_cb: port state is "
10714 "not ONLINE. s_id=%x, d_id=%x, type=%x, "
10715 "seq_id=%x, ox_id=%x, rx_id=%x"
10716 "ro=%x", buf
->ub_frame
.s_id
, buf
->ub_frame
.d_id
,
10717 buf
->ub_frame
.type
, buf
->ub_frame
.seq_id
,
10718 buf
->ub_frame
.ox_id
, buf
->ub_frame
.rx_id
, buf
->ub_frame
.ro
);
10720 ASSERT(port
->fp_active_ubs
> 0);
10721 if (--(port
->fp_active_ubs
) == 0) {
10722 port
->fp_soft_state
&= ~FP_SOFT_IN_UNSOL_CB
;
10725 mutex_exit(&port
->fp_mutex
);
10727 port
->fp_fca_tran
->fca_ub_release(port
->fp_fca_handle
,
10728 1, &buf
->ub_token
);
10733 r_ctl
= buf
->ub_frame
.r_ctl
;
10734 s_id
= buf
->ub_frame
.s_id
;
10735 if (port
->fp_active_ubs
== 1) {
10736 port
->fp_soft_state
|= FP_SOFT_IN_UNSOL_CB
;
10739 if (r_ctl
== R_CTL_ELS_REQ
&& buf
->ub_buffer
[0] == LA_ELS_LOGO
&&
10740 port
->fp_statec_busy
) {
10741 mutex_exit(&port
->fp_mutex
);
10742 pd
= fctl_get_remote_port_by_did(port
, s_id
);
10744 mutex_enter(&pd
->pd_mutex
);
10745 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
10746 FP_TRACE(FP_NHEAD1(3, 0),
10747 "LOGO for LOGGED IN D_ID %x",
10748 buf
->ub_frame
.s_id
);
10749 pd
->pd_state
= PORT_DEVICE_VALID
;
10751 mutex_exit(&pd
->pd_mutex
);
10754 mutex_enter(&port
->fp_mutex
);
10755 ASSERT(port
->fp_active_ubs
> 0);
10756 if (--(port
->fp_active_ubs
) == 0) {
10757 port
->fp_soft_state
&= ~FP_SOFT_IN_UNSOL_CB
;
10759 mutex_exit(&port
->fp_mutex
);
10761 port
->fp_fca_tran
->fca_ub_release(port
->fp_fca_handle
,
10762 1, &buf
->ub_token
);
10764 FP_TRACE(FP_NHEAD1(3, 0),
10765 "fp_unsol_cb() bailing out LOGO for D_ID %x",
10766 buf
->ub_frame
.s_id
);
10770 if (port
->fp_els_resp_pkt_busy
== 0) {
10771 if (r_ctl
== R_CTL_ELS_REQ
) {
10772 ls_code
= buf
->ub_buffer
[0];
10777 port
->fp_els_resp_pkt_busy
= 1;
10778 mutex_exit(&port
->fp_mutex
);
10779 fp_i_handle_unsol_els(port
, buf
);
10781 mutex_enter(&port
->fp_mutex
);
10782 ASSERT(port
->fp_active_ubs
> 0);
10783 if (--(port
->fp_active_ubs
) == 0) {
10784 port
->fp_soft_state
&=
10785 ~FP_SOFT_IN_UNSOL_CB
;
10787 mutex_exit(&port
->fp_mutex
);
10788 port
->fp_fca_tran
->fca_ub_release(
10789 port
->fp_fca_handle
, 1, &buf
->ub_token
);
10793 if (++(port
)->fp_rscn_count
==
10794 FC_INVALID_RSCN_COUNT
) {
10795 ++(port
)->fp_rscn_count
;
10797 rscn_count
= port
->fp_rscn_count
;
10804 } else if ((r_ctl
== R_CTL_ELS_REQ
) &&
10805 (buf
->ub_buffer
[0] == LA_ELS_RSCN
)) {
10806 if (++port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
10807 ++port
->fp_rscn_count
;
10809 rscn_count
= port
->fp_rscn_count
;
10812 mutex_exit(&port
->fp_mutex
);
10814 switch (r_ctl
& R_CTL_ROUTING
) {
10815 case R_CTL_DEVICE_DATA
:
10817 * If the unsolicited buffer is a CT IU,
10818 * have the job_handler thread work on it.
10820 if (buf
->ub_frame
.type
== FC_TYPE_FC_SERVICES
) {
10825 case R_CTL_FC4_SVC
: {
10829 * If a LOGIN isn't performed before this request
10830 * shut the door on this port with a reply that a
10831 * LOGIN is required. We make an exception however
10832 * for IP broadcast packets and pass them through
10833 * to the IP ULP(s) to handle broadcast requests.
10834 * This is not a problem for private loop devices
10835 * but for fabric topologies we don't log into the
10836 * remote ports during port initialization and
10837 * the ULPs need to log into requesting ports on
10840 pd
= fctl_get_remote_port_by_did(port
, s_id
);
10842 mutex_enter(&pd
->pd_mutex
);
10843 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
10846 mutex_exit(&pd
->pd_mutex
);
10847 } else if ((pd
== NULL
) &&
10848 (buf
->ub_frame
.type
== FC_TYPE_IS8802_SNAP
) &&
10849 (buf
->ub_frame
.d_id
== 0xffffff ||
10850 buf
->ub_frame
.d_id
== 0x00)) {
10851 /* brodacst IP frame - so sendup via job thread */
10856 * Send all FC4 services via job thread too
10858 if ((r_ctl
& R_CTL_ROUTING
) == R_CTL_FC4_SVC
) {
10862 if (sendup
|| !FC_IS_REAL_DEVICE(s_id
)) {
10863 fctl_ulp_unsol_cb(port
, buf
, buf
->ub_frame
.type
);
10867 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
10868 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
),
10869 0, KM_NOSLEEP
, pd
);
10871 fp_els_rjt_init(port
, cmd
, buf
,
10872 FC_ACTION_NON_RETRYABLE
,
10873 FC_REASON_LOGIN_REQUIRED
, NULL
);
10875 if (fp_sendcmd(port
, cmd
,
10876 port
->fp_fca_handle
) != FC_SUCCESS
) {
10882 mutex_enter(&port
->fp_mutex
);
10883 ASSERT(port
->fp_active_ubs
> 0);
10884 if (--(port
->fp_active_ubs
) == 0) {
10885 port
->fp_soft_state
&= ~FP_SOFT_IN_UNSOL_CB
;
10887 mutex_exit(&port
->fp_mutex
);
10888 port
->fp_fca_tran
->fca_ub_release(port
->fp_fca_handle
,
10889 1, &buf
->ub_token
);
10899 * Submit a Request to the job_handler thread to work
10900 * on the unsolicited request. The potential side effect
10901 * of this is that the unsolicited buffer takes a little
10902 * longer to get released but we save interrupt time in
10905 cb_arg
= (rscn_count
== FC_INVALID_RSCN_COUNT
) ? 0 : rscn_count
;
10908 * One way that the rscn_count will get used is described below :
10910 * 1. fp_unsol_cb() gets an RSCN and updates fp_rscn_count.
10911 * 2. Before mutex is released, a copy of it is stored in rscn_count.
10912 * 3. The count is passed to job thread as JOB_UNSOL_REQUEST (below)
10913 * by overloading the job_cb_arg to pass the rscn_count
10914 * 4. When one of the routines processing the RSCN picks it up (ex:
10915 * fp_validate_rscn_page()), it passes this count in the map
10916 * structure (as part of the map_rscn_info structure member) to the
10918 * 5. When ULPs make calls back to the transport (example interfaces for
10919 * this are fc_ulp_transport(), fc_ulp_login(), fc_issue_els()), they
10920 * can now pass back this count as part of the fc_packet's
10921 * pkt_ulp_rscn_count member. fcp does this currently.
10922 * 6. When transport gets a call to transport a command on the wire, it
10923 * will check to see if there is a valid pkt_ulp_rsvd1 field in the
10924 * fc_packet. If there is, it will match that info with the current
10925 * rscn_count on that instance of the port. If they don't match up
10926 * then there was a newer RSCN. The ULP gets back an error code which
10927 * informs it about it - FC_DEVICE_BUSY_NEW_RSCN.
10928 * 7. At this point the ULP is free to make up its own mind as to how to
10929 * handle this. Currently, fcp will reset its retry counters and keep
10930 * retrying the operation it was doing in anticipation of getting a
10931 * new state change call back for the new RSCN.
10933 job
= fctl_alloc_job(JOB_UNSOL_REQUEST
, 0, NULL
,
10934 (opaque_t
)(uintptr_t)cb_arg
, KM_NOSLEEP
);
10936 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
, "fp_unsol_cb() "
10937 "couldn't submit a job to the thread, failing..");
10939 mutex_enter(&port
->fp_mutex
);
10941 if (--port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
10942 --port
->fp_rscn_count
;
10945 ASSERT(port
->fp_active_ubs
> 0);
10946 if (--(port
->fp_active_ubs
) == 0) {
10947 port
->fp_soft_state
&= ~FP_SOFT_IN_UNSOL_CB
;
10950 mutex_exit(&port
->fp_mutex
);
10951 port
->fp_fca_tran
->fca_ub_release(port
->fp_fca_handle
,
10952 1, &buf
->ub_token
);
10956 job
->job_private
= (void *)buf
;
10957 fctl_enque_job(port
, job
);
10962 * Handle unsolicited requests
10965 fp_handle_unsol_buf(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
,
10966 job_request_t
*job
)
10972 fc_remote_port_t
*pd
;
10973 fp_unsol_spec_t
*ub_spec
;
10975 r_ctl
= buf
->ub_frame
.r_ctl
;
10976 s_id
= buf
->ub_frame
.s_id
;
10978 switch (r_ctl
& R_CTL_ROUTING
) {
10979 case R_CTL_EXTENDED_SVC
:
10980 if (r_ctl
!= R_CTL_ELS_REQ
) {
10984 ls_code
= buf
->ub_buffer
[0];
10989 pd
= fctl_get_remote_port_by_did(port
, s_id
);
10991 if (!FC_IS_REAL_DEVICE(s_id
)) {
10994 if (!FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
10997 if ((cmd
= fp_alloc_pkt(port
,
10998 sizeof (la_els_rjt_t
), 0, KM_SLEEP
,
11001 * Can this actually fail when
11002 * given KM_SLEEP? (Could be used
11003 * this way in a number of places.)
11008 fp_els_rjt_init(port
, cmd
, buf
,
11009 FC_ACTION_NON_RETRYABLE
,
11010 FC_REASON_INVALID_LINK_CTRL
, job
);
11012 if (fp_sendcmd(port
, cmd
,
11013 port
->fp_fca_handle
) != FC_SUCCESS
) {
11019 if (ls_code
== LA_ELS_LOGO
) {
11020 fp_handle_unsol_logo(port
, buf
, pd
, job
);
11021 } else if (ls_code
== LA_ELS_ADISC
) {
11022 fp_handle_unsol_adisc(port
, buf
, pd
, job
);
11024 fp_handle_unsol_prlo(port
, buf
, pd
, job
);
11029 fp_handle_unsol_plogi(port
, buf
, job
, KM_SLEEP
);
11033 fp_handle_unsol_flogi(port
, buf
, job
, KM_SLEEP
);
11037 fp_handle_unsol_rscn(port
, buf
, job
, KM_SLEEP
);
11041 ub_spec
= kmem_zalloc(sizeof (*ub_spec
), KM_SLEEP
);
11042 ub_spec
->port
= port
;
11043 ub_spec
->buf
= buf
;
11045 (void) taskq_dispatch(port
->fp_taskq
,
11046 fp_ulp_unsol_cb
, ub_spec
, KM_SLEEP
);
11051 case R_CTL_BASIC_SVC
:
11053 * The unsolicited basic link services could be ABTS
11054 * and RMC (Or even a NOP). Just BA_RJT them until
11055 * such time there arises a need to handle them more
11058 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11059 cmd
= fp_alloc_pkt(port
, sizeof (la_ba_rjt_t
),
11060 0, KM_SLEEP
, NULL
);
11062 fp_ba_rjt_init(port
, cmd
, buf
, job
);
11063 if (fp_sendcmd(port
, cmd
,
11064 port
->fp_fca_handle
) != FC_SUCCESS
) {
11071 case R_CTL_DEVICE_DATA
:
11072 if (buf
->ub_frame
.type
== FC_TYPE_FC_SERVICES
) {
11074 * Mostly this is of type FC_TYPE_FC_SERVICES.
11075 * As we don't like any Unsolicited FC services
11076 * requests, we would do well to RJT them as
11079 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11080 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
),
11081 0, KM_SLEEP
, NULL
);
11083 fp_els_rjt_init(port
, cmd
, buf
,
11084 FC_ACTION_NON_RETRYABLE
,
11085 FC_REASON_INVALID_LINK_CTRL
, job
);
11087 if (fp_sendcmd(port
, cmd
,
11088 port
->fp_fca_handle
) !=
11098 case R_CTL_FC4_SVC
:
11099 ub_spec
= kmem_zalloc(sizeof (*ub_spec
), KM_SLEEP
);
11100 ub_spec
->port
= port
;
11101 ub_spec
->buf
= buf
;
11103 (void) taskq_dispatch(port
->fp_taskq
,
11104 fp_ulp_unsol_cb
, ub_spec
, KM_SLEEP
);
11107 case R_CTL_LINK_CTL
:
11109 * Turn deaf ear on unsolicited link control frames.
11110 * Typical unsolicited link control Frame is an LCR
11111 * (to reset End to End credit to the default login
11112 * value and abort current sequences for all classes)
11113 * An intelligent microcode/firmware should handle
11114 * this transparently at its level and not pass all
11117 * Possible responses to LCR are R_RDY, F_RJT, P_RJT
11118 * or F_BSY. P_RJT is chosen to be the most appropriate
11125 * Just reject everything else as an invalid request.
11127 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11128 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
),
11129 0, KM_SLEEP
, NULL
);
11131 fp_els_rjt_init(port
, cmd
, buf
,
11132 FC_ACTION_NON_RETRYABLE
,
11133 FC_REASON_INVALID_LINK_CTRL
, job
);
11135 if (fp_sendcmd(port
, cmd
,
11136 port
->fp_fca_handle
) != FC_SUCCESS
) {
11144 mutex_enter(&port
->fp_mutex
);
11145 ASSERT(port
->fp_active_ubs
> 0);
11146 if (--(port
->fp_active_ubs
) == 0) {
11147 port
->fp_soft_state
&= ~FP_SOFT_IN_UNSOL_CB
;
11149 mutex_exit(&port
->fp_mutex
);
11150 port
->fp_fca_tran
->fca_ub_release(port
->fp_fca_handle
,
11151 1, &buf
->ub_token
);
11156 * Prepare a BA_RJT and send it over.
11159 fp_ba_rjt_init(fc_local_port_t
*port
, fp_cmd_t
*cmd
, fc_unsol_buf_t
*buf
,
11160 job_request_t
*job
)
11163 la_ba_rjt_t payload
;
11165 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
11167 cmd
->cmd_pkt
.pkt_tran_flags
= buf
->ub_class
;
11168 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_OUTBOUND
;
11169 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
11170 cmd
->cmd_retry_count
= 1;
11171 cmd
->cmd_ulp_pkt
= NULL
;
11173 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
11174 cmd
->cmd_job
= job
;
11176 pkt
= &cmd
->cmd_pkt
;
11178 fp_unsol_resp_init(pkt
, buf
, R_CTL_LS_BA_RJT
, FC_TYPE_BASIC_LS
);
11180 payload
.reserved
= 0;
11181 payload
.reason_code
= FC_REASON_CMD_UNSUPPORTED
;
11182 payload
.explanation
= FC_EXPLN_NONE
;
11183 payload
.vendor
= 0;
11185 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
11186 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
11191 * Prepare an LS_RJT and send it over
11194 fp_els_rjt_init(fc_local_port_t
*port
, fp_cmd_t
*cmd
, fc_unsol_buf_t
*buf
,
11195 uchar_t action
, uchar_t reason
, job_request_t
*job
)
11198 la_els_rjt_t payload
;
11200 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
11202 cmd
->cmd_pkt
.pkt_tran_flags
= buf
->ub_class
;
11203 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_OUTBOUND
;
11204 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
11205 cmd
->cmd_retry_count
= 1;
11206 cmd
->cmd_ulp_pkt
= NULL
;
11208 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
11209 cmd
->cmd_job
= job
;
11211 pkt
= &cmd
->cmd_pkt
;
11213 fp_unsol_resp_init(pkt
, buf
, R_CTL_ELS_RSP
, FC_TYPE_EXTENDED_LS
);
11215 payload
.ls_code
.ls_code
= LA_ELS_RJT
;
11216 payload
.ls_code
.mbz
= 0;
11217 payload
.action
= action
;
11218 payload
.reason
= reason
;
11219 payload
.reserved
= 0;
11222 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
11223 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
11227 * Function: fp_prlo_acc_init
11229 * Description: Initializes an Link Service Accept for a PRLO.
11231 * Arguments: *port Local port through which the PRLO was
11233 * cmd Command that will carry the accept.
11234 * *buf Unsolicited buffer containing the PRLO
11237 * sleep Allocation mode.
11239 * Return Value: *cmd Command containing the response.
11241 * Context: Depends on the parameter sleep.
11244 fp_prlo_acc_init(fc_local_port_t
*port
, fc_remote_port_t
*pd
,
11245 fc_unsol_buf_t
*buf
, job_request_t
*job
, int sleep
)
11249 la_els_prlo_t
*req
;
11253 req
= (la_els_prlo_t
*)buf
->ub_buffer
;
11254 len
= (size_t)ntohs(req
->payload_length
);
11257 * The payload of the accept to a PRLO has to be the exact match of
11258 * the payload of the request (at the exception of the code).
11260 cmd
= fp_alloc_pkt(port
, (int)len
, 0, sleep
, pd
);
11264 * The fp command was successfully allocated.
11266 cmd
->cmd_pkt
.pkt_tran_flags
= buf
->ub_class
;
11267 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_OUTBOUND
;
11268 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
11269 cmd
->cmd_retry_count
= 1;
11270 cmd
->cmd_ulp_pkt
= NULL
;
11272 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
11273 cmd
->cmd_job
= job
;
11275 pkt
= &cmd
->cmd_pkt
;
11277 fp_unsol_resp_init(pkt
, buf
, R_CTL_ELS_RSP
,
11278 FC_TYPE_EXTENDED_LS
);
11280 /* The code is overwritten for the copy. */
11281 req
->ls_code
= LA_ELS_ACC
;
11282 /* Response code is set. */
11283 flags
= ntohs(req
->flags
);
11284 flags
&= ~SP_RESP_CODE_MASK
;
11285 flags
|= SP_RESP_CODE_REQ_EXECUTED
;
11286 req
->flags
= htons(flags
);
11288 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)req
,
11289 (uint8_t *)pkt
->pkt_cmd
, len
, DDI_DEV_AUTOINCR
);
11295 * Prepare an ACC response to an ELS request
11298 fp_els_acc_init(fc_local_port_t
*port
, fp_cmd_t
*cmd
, fc_unsol_buf_t
*buf
,
11299 job_request_t
*job
)
11304 cmd
->cmd_pkt
.pkt_tran_flags
= buf
->ub_class
;
11305 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_OUTBOUND
;
11306 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
11307 cmd
->cmd_retry_count
= 1;
11308 cmd
->cmd_ulp_pkt
= NULL
;
11310 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
11311 cmd
->cmd_job
= job
;
11313 pkt
= &cmd
->cmd_pkt
;
11315 fp_unsol_resp_init(pkt
, buf
, R_CTL_ELS_RSP
, FC_TYPE_EXTENDED_LS
);
11317 payload
.ls_code
= LA_ELS_ACC
;
11320 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
11321 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
11325 * Unsolicited PRLO handler
11327 * A Process Logout should be handled by the ULP that established it. However,
11328 * some devices send a PRLO to trigger a PLOGI followed by a PRLI. This happens
11329 * when a device implicitly logs out an initiator (for whatever reason) and
11330 * tries to get that initiator to restablish the connection (PLOGI and PRLI).
11331 * The logical thing to do for the device would be to send a LOGO in response
11332 * to any FC4 frame sent by the initiator. Some devices choose, however, to send
11335 * From a Fibre Channel standpoint a PRLO calls for a PRLI. There's no reason to
11336 * think that the Port Login has been lost. If we follow the Fibre Channel
11337 * protocol to the letter a PRLI should be sent after accepting the PRLO. If
11338 * the Port Login has also been lost, the remote port will reject the PRLI
11339 * indicating that we must PLOGI first. The initiator will then turn around and
11340 * send a PLOGI. The way Leadville is layered and the way the ULP interface
11341 * is defined doesn't allow this scenario to be followed easily. If FCP were to
11342 * handle the PRLO and attempt the PRLI, the reject indicating that a PLOGI is
11343 * needed would be received by FCP. FCP would have, then, to tell the transport
11344 * (fp) to PLOGI. The problem is, the transport would still think the Port
11345 * Login is valid and there is no way for FCP to tell the transport: "PLOGI even
11346 * if you think it's not necessary". To work around that difficulty, the PRLO
11347 * is treated by the transport as a LOGO. The downside to it is a Port Login
11348 * may be disrupted (if a PLOGI wasn't actually needed) and another ULP (that
11349 * has nothing to do with the PRLO) may be impacted. However, this is a
11350 * scenario very unlikely to happen. As of today the only ULP in Leadville
11351 * using PRLI/PRLOs is FCP. For a PRLO to disrupt another ULP (that would be
11352 * FCIP), a SCSI target would have to be running FCP and FCIP (which is very
11356 fp_handle_unsol_prlo(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
,
11357 fc_remote_port_t
*pd
, job_request_t
*job
)
11363 fc_portmap_t
*listptr
;
11364 boolean_t tolerance
;
11365 la_els_prlo_t
*req
;
11367 req
= (la_els_prlo_t
*)buf
->ub_buffer
;
11369 if ((ntohs(req
->payload_length
) !=
11370 (sizeof (service_parameter_page_t
) + sizeof (ls_code_t
))) ||
11371 (req
->page_length
!= sizeof (service_parameter_page_t
))) {
11373 * We are being very restrictive. Only on page per
11374 * payload. If it is not the case we reject the ELS although
11375 * we should reply indicating we handle only single page
11378 goto fp_reject_prlo
;
11381 if (ntohs(req
->payload_length
) > buf
->ub_bufsize
) {
11383 * This is in case the payload advertizes a size bigger than
11384 * what it really is.
11386 goto fp_reject_prlo
;
11389 mutex_enter(&port
->fp_mutex
);
11390 busy
= port
->fp_statec_busy
;
11391 mutex_exit(&port
->fp_mutex
);
11393 mutex_enter(&pd
->pd_mutex
);
11394 tolerance
= fctl_tc_increment(&pd
->pd_logo_tc
);
11396 if (pd
->pd_state
!= PORT_DEVICE_LOGGED_IN
||
11397 pd
->pd_state
== PORT_DEVICE_INVALID
||
11398 pd
->pd_flags
== PD_ELS_IN_PROGRESS
||
11399 pd
->pd_type
== PORT_DEVICE_OLD
) {
11405 mutex_exit(&pd
->pd_mutex
);
11407 FP_TRACE(FP_NHEAD1(5, 0), "Logout; D_ID=%x,"
11409 pd
->pd_port_id
.port_id
, pd
);
11411 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11412 goto fp_reject_prlo
;
11415 retain
= (pd
->pd_recepient
== PD_PLOGI_INITIATOR
) ? 1 : 0;
11418 fctl_tc_reset(&pd
->pd_logo_tc
);
11420 pd
->pd_state
= PORT_DEVICE_INVALID
;
11423 FP_TRACE(FP_NHEAD1(5, 0), "Accepting LOGO; d_id=%x, pd=%p,"
11424 " tolerance=%d retain=%d", pd
->pd_port_id
.port_id
, pd
,
11425 tolerance
, retain
);
11427 pd
->pd_aux_flags
|= PD_LOGGED_OUT
;
11428 mutex_exit(&pd
->pd_mutex
);
11430 cmd
= fp_prlo_acc_init(port
, pd
, buf
, job
, KM_SLEEP
);
11435 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
11436 if (rval
!= FC_SUCCESS
) {
11441 listptr
= kmem_zalloc(sizeof (fc_portmap_t
), KM_SLEEP
);
11444 fp_unregister_login(pd
);
11445 fctl_copy_portmap(listptr
, pd
);
11450 mutex_enter(&pd
->pd_mutex
);
11451 d_id
= pd
->pd_port_id
.port_id
;
11452 fc_wwn_to_str(&pd
->pd_port_name
, ww_name
);
11453 mutex_exit(&pd
->pd_mutex
);
11455 FP_TRACE(FP_NHEAD2(9, 0),
11456 "N_x Port with D_ID=%x, PWWN=%s logged out"
11457 " %d times in %d us; Giving up", d_id
, ww_name
,
11458 FC_LOGO_TOLERANCE_LIMIT
,
11459 FC_LOGO_TOLERANCE_TIME_LIMIT
);
11461 fp_fillout_old_map(listptr
, pd
, 0);
11462 listptr
->map_type
= PORT_DEVICE_OLD
;
11465 (void) fp_ulp_devc_cb(port
, listptr
, 1, 1, KM_SLEEP
, 0);
11471 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
), 0, KM_SLEEP
, pd
);
11473 fp_els_rjt_init(port
, cmd
, buf
, FC_ACTION_NON_RETRYABLE
,
11474 FC_REASON_INVALID_LINK_CTRL
, job
);
11476 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
) {
11483 * Unsolicited LOGO handler
11486 fp_handle_unsol_logo(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
,
11487 fc_remote_port_t
*pd
, job_request_t
*job
)
11493 fc_portmap_t
*listptr
;
11494 boolean_t tolerance
;
11496 mutex_enter(&port
->fp_mutex
);
11497 busy
= port
->fp_statec_busy
;
11498 mutex_exit(&port
->fp_mutex
);
11500 mutex_enter(&pd
->pd_mutex
);
11501 tolerance
= fctl_tc_increment(&pd
->pd_logo_tc
);
11503 if (pd
->pd_state
!= PORT_DEVICE_LOGGED_IN
||
11504 pd
->pd_state
== PORT_DEVICE_INVALID
||
11505 pd
->pd_flags
== PD_ELS_IN_PROGRESS
||
11506 pd
->pd_type
== PORT_DEVICE_OLD
) {
11512 mutex_exit(&pd
->pd_mutex
);
11514 FP_TRACE(FP_NHEAD1(5, 0), "Logout; D_ID=%x,"
11516 pd
->pd_port_id
.port_id
, pd
);
11518 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11519 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
),
11522 fp_els_rjt_init(port
, cmd
, buf
,
11523 FC_ACTION_NON_RETRYABLE
,
11524 FC_REASON_INVALID_LINK_CTRL
, job
);
11526 if (fp_sendcmd(port
, cmd
,
11527 port
->fp_fca_handle
) != FC_SUCCESS
) {
11533 retain
= (pd
->pd_recepient
== PD_PLOGI_INITIATOR
) ? 1 : 0;
11536 fctl_tc_reset(&pd
->pd_logo_tc
);
11538 pd
->pd_state
= PORT_DEVICE_INVALID
;
11541 FP_TRACE(FP_NHEAD1(5, 0), "Accepting LOGO; d_id=%x, pd=%p,"
11542 " tolerance=%d retain=%d", pd
->pd_port_id
.port_id
, pd
,
11543 tolerance
, retain
);
11545 pd
->pd_aux_flags
|= PD_LOGGED_OUT
;
11546 mutex_exit(&pd
->pd_mutex
);
11548 cmd
= fp_alloc_pkt(port
, FP_PORT_IDENTIFIER_LEN
, 0,
11554 fp_els_acc_init(port
, cmd
, buf
, job
);
11556 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
11557 if (rval
!= FC_SUCCESS
) {
11562 listptr
= kmem_zalloc(sizeof (fc_portmap_t
), KM_SLEEP
);
11565 job_request_t
*job
;
11566 fctl_ns_req_t
*ns_cmd
;
11569 * when get LOGO, first try to get PID from nameserver
11570 * if failed, then we do not need
11571 * send PLOGI to that remote port
11573 job
= fctl_alloc_job(
11574 JOB_NS_CMD
, 0, NULL
, (opaque_t
)port
, KM_SLEEP
);
11577 ns_cmd
= fctl_alloc_ns_cmd(
11578 sizeof (ns_req_gid_pn_t
),
11579 sizeof (ns_resp_gid_pn_t
),
11580 sizeof (ns_resp_gid_pn_t
),
11582 if (ns_cmd
!= NULL
) {
11584 job
->job_result
= FC_SUCCESS
;
11585 ns_cmd
->ns_cmd_code
= NS_GID_PN
;
11586 ((ns_req_gid_pn_t
*)
11587 (ns_cmd
->ns_cmd_buf
))->pwwn
=
11590 port
, ns_cmd
, job
, 1, KM_SLEEP
);
11591 if ((ret
!= FC_SUCCESS
) ||
11592 (job
->job_result
!= FC_SUCCESS
)) {
11593 fctl_free_ns_cmd(ns_cmd
);
11594 fctl_dealloc_job(job
);
11595 FP_TRACE(FP_NHEAD2(9, 0),
11596 "NS query failed,",
11600 fctl_free_ns_cmd(ns_cmd
);
11602 fctl_dealloc_job(job
);
11604 fp_unregister_login(pd
);
11605 fctl_copy_portmap(listptr
, pd
);
11611 mutex_enter(&pd
->pd_mutex
);
11612 d_id
= pd
->pd_port_id
.port_id
;
11613 fc_wwn_to_str(&pd
->pd_port_name
, ww_name
);
11614 mutex_exit(&pd
->pd_mutex
);
11616 FP_TRACE(FP_NHEAD2(9, 0),
11617 "N_x Port with D_ID=%x, PWWN=%s logged out"
11618 " %d times in %d us; Giving up", d_id
, ww_name
,
11619 FC_LOGO_TOLERANCE_LIMIT
,
11620 FC_LOGO_TOLERANCE_TIME_LIMIT
);
11622 fp_fillout_old_map(listptr
, pd
, 0);
11623 listptr
->map_type
= PORT_DEVICE_OLD
;
11626 (void) fp_ulp_devc_cb(port
, listptr
, 1, 1, KM_SLEEP
, 0);
11632 * Perform general purpose preparation of a response to an unsolicited request
11635 fp_unsol_resp_init(fc_packet_t
*pkt
, fc_unsol_buf_t
*buf
,
11636 uchar_t r_ctl
, uchar_t type
)
11638 pkt
->pkt_cmd_fhdr
.r_ctl
= r_ctl
;
11639 pkt
->pkt_cmd_fhdr
.d_id
= buf
->ub_frame
.s_id
;
11640 pkt
->pkt_cmd_fhdr
.s_id
= buf
->ub_frame
.d_id
;
11641 pkt
->pkt_cmd_fhdr
.type
= type
;
11642 pkt
->pkt_cmd_fhdr
.f_ctl
= F_CTL_LAST_SEQ
| F_CTL_XCHG_CONTEXT
;
11643 pkt
->pkt_cmd_fhdr
.seq_id
= buf
->ub_frame
.seq_id
;
11644 pkt
->pkt_cmd_fhdr
.df_ctl
= buf
->ub_frame
.df_ctl
;
11645 pkt
->pkt_cmd_fhdr
.seq_cnt
= buf
->ub_frame
.seq_cnt
;
11646 pkt
->pkt_cmd_fhdr
.ox_id
= buf
->ub_frame
.ox_id
;
11647 pkt
->pkt_cmd_fhdr
.rx_id
= buf
->ub_frame
.rx_id
;
11648 pkt
->pkt_cmd_fhdr
.ro
= 0;
11649 pkt
->pkt_cmd_fhdr
.rsvd
= 0;
11650 pkt
->pkt_comp
= fp_unsol_intr
;
11651 pkt
->pkt_timeout
= FP_ELS_TIMEOUT
;
11652 pkt
->pkt_ub_resp_token
= (opaque_t
)buf
;
11656 * Immediate handling of unsolicited FLOGI and PLOGI requests. In the
11657 * early development days of public loop soc+ firmware, numerous problems
11658 * were encountered (the details are undocumented and history now) which
11659 * led to the birth of this function.
11661 * If a pre-allocated unsolicited response packet is free, send out an
11662 * immediate response, otherwise submit the request to the port thread
11663 * to do the deferred processing.
11666 fp_i_handle_unsol_els(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
)
11672 la_els_logi_t
*payload
;
11673 fc_remote_port_t
*pd
;
11676 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
11678 cmd
= port
->fp_els_resp_pkt
;
11680 mutex_enter(&port
->fp_mutex
);
11681 do_acc
= (port
->fp_statec_busy
== 0) ? 1 : 0;
11682 mutex_exit(&port
->fp_mutex
);
11684 switch (buf
->ub_buffer
[0]) {
11685 case LA_ELS_PLOGI
: {
11688 payload
= (la_els_logi_t
*)buf
->ub_buffer
;
11690 f_port
= FP_IS_F_PORT(payload
->
11691 common_service
.cmn_features
) ? 1 : 0;
11693 small
= fctl_wwn_cmp(&port
->fp_service_params
.nport_ww_name
,
11694 &payload
->nport_ww_name
);
11695 pd
= fctl_get_remote_port_by_pwwn(port
,
11696 &payload
->nport_ww_name
);
11698 mutex_enter(&pd
->pd_mutex
);
11699 sent
= (pd
->pd_flags
== PD_ELS_IN_PROGRESS
) ? 1 : 0;
11701 * Most likely this means a cross login is in
11702 * progress or a device about to be yanked out.
11703 * Only accept the plogi if my wwn is smaller.
11705 if (pd
->pd_type
== PORT_DEVICE_OLD
) {
11709 * Stop plogi request (if any)
11710 * attempt from local side to speedup
11711 * the discovery progress.
11712 * Mark the pd as PD_PLOGI_RECEPIENT.
11714 if (f_port
== 0 && small
< 0) {
11715 pd
->pd_recepient
= PD_PLOGI_RECEPIENT
;
11717 fc_wwn_to_str(&pd
->pd_port_name
, dww_name
);
11719 mutex_exit(&pd
->pd_mutex
);
11721 FP_TRACE(FP_NHEAD1(3, 0), "fp_i_handle_unsol_els: "
11722 "Unsol PLOGI received. PD still exists in the "
11723 "PWWN list. pd=%p PWWN=%s, sent=%x",
11724 pd
, dww_name
, sent
);
11726 if (f_port
== 0 && small
< 0) {
11727 FP_TRACE(FP_NHEAD1(3, 0),
11728 "fp_i_handle_unsol_els: Mark the pd"
11729 " as plogi recipient, pd=%p, PWWN=%s"
11731 pd
, dww_name
, sent
);
11738 * To avoid Login collisions, accept only if my WWN
11739 * is smaller than the requester (A curious side note
11740 * would be that this rule may not satisfy the PLOGIs
11741 * initiated by the switch from not-so-well known
11742 * ports such as 0xFFFC41)
11744 if ((f_port
== 0 && small
< 0) ||
11745 (((small
> 0 && do_acc
) ||
11746 FC_MUST_ACCEPT_D_ID(buf
->ub_frame
.s_id
)) && sent
== 0)) {
11747 if (fp_is_class_supported(port
->fp_cos
,
11748 buf
->ub_class
) == FC_FAILURE
) {
11749 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11750 cmd
->cmd_pkt
.pkt_cmdlen
=
11751 sizeof (la_els_rjt_t
);
11752 cmd
->cmd_pkt
.pkt_rsplen
= 0;
11753 fp_els_rjt_init(port
, cmd
, buf
,
11754 FC_ACTION_NON_RETRYABLE
,
11755 FC_REASON_CLASS_NOT_SUPP
, NULL
);
11756 FP_TRACE(FP_NHEAD1(3, 0),
11757 "fp_i_handle_unsol_els: "
11758 "Unsupported class. "
11759 "Rejecting PLOGI");
11762 mutex_enter(&port
->fp_mutex
);
11763 port
->fp_els_resp_pkt_busy
= 0;
11764 mutex_exit(&port
->fp_mutex
);
11768 cmd
->cmd_pkt
.pkt_cmdlen
=
11769 sizeof (la_els_logi_t
);
11770 cmd
->cmd_pkt
.pkt_rsplen
= 0;
11773 * If fp_port_id is zero and topology is
11774 * Point-to-Point, get the local port id from
11775 * the d_id in the PLOGI request.
11776 * If the outgoing FLOGI hasn't been accepted,
11777 * the topology will be unknown here. But it's
11778 * still safe to save the d_id to fp_port_id,
11779 * just because it will be overwritten later
11780 * if the topology is not Point-to-Point.
11782 mutex_enter(&port
->fp_mutex
);
11783 if ((port
->fp_port_id
.port_id
== 0) &&
11784 (port
->fp_topology
== FC_TOP_PT_PT
||
11785 port
->fp_topology
== FC_TOP_UNKNOWN
)) {
11786 port
->fp_port_id
.port_id
=
11787 buf
->ub_frame
.d_id
;
11789 mutex_exit(&port
->fp_mutex
);
11792 * Sometime later, we should validate
11793 * the service parameters instead of
11794 * just accepting it.
11796 fp_login_acc_init(port
, cmd
, buf
, NULL
,
11798 FP_TRACE(FP_NHEAD1(3, 0),
11799 "fp_i_handle_unsol_els: Accepting PLOGI,"
11800 " f_port=%d, small=%d, do_acc=%d,"
11801 " sent=%d.", f_port
, small
, do_acc
,
11805 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
) ||
11806 port
->fp_options
& FP_SEND_RJT
) {
11807 cmd
->cmd_pkt
.pkt_cmdlen
= sizeof (la_els_rjt_t
);
11808 cmd
->cmd_pkt
.pkt_rsplen
= 0;
11809 fp_els_rjt_init(port
, cmd
, buf
,
11810 FC_ACTION_NON_RETRYABLE
,
11811 FC_REASON_LOGICAL_BSY
, NULL
);
11812 FP_TRACE(FP_NHEAD1(3, 0),
11813 "fp_i_handle_unsol_els: "
11814 "Rejecting PLOGI with Logical Busy."
11815 "Possible Login collision.");
11817 mutex_enter(&port
->fp_mutex
);
11818 port
->fp_els_resp_pkt_busy
= 0;
11819 mutex_exit(&port
->fp_mutex
);
11827 if (fp_is_class_supported(port
->fp_cos
,
11828 buf
->ub_class
) == FC_FAILURE
) {
11829 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11830 cmd
->cmd_pkt
.pkt_cmdlen
= sizeof (la_els_rjt_t
);
11831 cmd
->cmd_pkt
.pkt_rsplen
= 0;
11832 fp_els_rjt_init(port
, cmd
, buf
,
11833 FC_ACTION_NON_RETRYABLE
,
11834 FC_REASON_CLASS_NOT_SUPP
, NULL
);
11835 FP_TRACE(FP_NHEAD1(3, 0),
11836 "fp_i_handle_unsol_els: "
11837 "Unsupported Class. Rejecting FLOGI.");
11839 mutex_enter(&port
->fp_mutex
);
11840 port
->fp_els_resp_pkt_busy
= 0;
11841 mutex_exit(&port
->fp_mutex
);
11845 mutex_enter(&port
->fp_mutex
);
11846 if (FC_PORT_STATE_MASK(port
->fp_state
) !=
11847 FC_STATE_ONLINE
|| (port
->fp_port_id
.port_id
&&
11848 buf
->ub_frame
.s_id
== port
->fp_port_id
.port_id
)) {
11849 mutex_exit(&port
->fp_mutex
);
11850 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
11851 cmd
->cmd_pkt
.pkt_cmdlen
=
11852 sizeof (la_els_rjt_t
);
11853 cmd
->cmd_pkt
.pkt_rsplen
= 0;
11854 fp_els_rjt_init(port
, cmd
, buf
,
11855 FC_ACTION_NON_RETRYABLE
,
11856 FC_REASON_INVALID_LINK_CTRL
,
11858 FP_TRACE(FP_NHEAD1(3, 0),
11859 "fp_i_handle_unsol_els: "
11860 "Invalid Link Ctrl. "
11861 "Rejecting FLOGI.");
11863 mutex_enter(&port
->fp_mutex
);
11864 port
->fp_els_resp_pkt_busy
= 0;
11865 mutex_exit(&port
->fp_mutex
);
11869 mutex_exit(&port
->fp_mutex
);
11870 cmd
->cmd_pkt
.pkt_cmdlen
=
11871 sizeof (la_els_logi_t
);
11872 cmd
->cmd_pkt
.pkt_rsplen
= 0;
11874 * Let's not aggressively validate the N_Port's
11875 * service parameters until PLOGI. Suffice it
11876 * to give a hint that we are an N_Port and we
11877 * are game to some serious stuff here.
11879 fp_login_acc_init(port
, cmd
, buf
,
11881 FP_TRACE(FP_NHEAD1(3, 0),
11882 "fp_i_handle_unsol_els: "
11883 "Accepting FLOGI.");
11892 if ((fp_sendcmd(port
, cmd
, port
->fp_fca_handle
)) != FC_SUCCESS
) {
11893 mutex_enter(&port
->fp_mutex
);
11894 port
->fp_els_resp_pkt_busy
= 0;
11895 mutex_exit(&port
->fp_mutex
);
11901 * Handle unsolicited PLOGI request
11904 fp_handle_unsol_plogi(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
,
11905 job_request_t
*job
, int sleep
)
11914 la_els_logi_t
*payload
;
11915 fc_remote_port_t
*pd
;
11918 payload
= (la_els_logi_t
*)buf
->ub_buffer
;
11919 f_port
= FP_IS_F_PORT(payload
->common_service
.cmn_features
) ? 1 : 0;
11921 mutex_enter(&port
->fp_mutex
);
11922 do_acc
= (port
->fp_statec_busy
== 0) ? 1 : 0;
11923 mutex_exit(&port
->fp_mutex
);
11925 FP_TRACE(FP_NHEAD1(3, 0), "fp_handle_unsol_plogi: s_id=%x, d_id=%x,"
11926 "type=%x, f_ctl=%x"
11927 " seq_id=%x, ox_id=%x, rx_id=%x"
11928 " ro=%x", buf
->ub_frame
.s_id
, buf
->ub_frame
.d_id
,
11929 buf
->ub_frame
.type
, buf
->ub_frame
.f_ctl
, buf
->ub_frame
.seq_id
,
11930 buf
->ub_frame
.ox_id
, buf
->ub_frame
.rx_id
, buf
->ub_frame
.ro
);
11932 swwn
= &port
->fp_service_params
.nport_ww_name
;
11933 dwwn
= &payload
->nport_ww_name
;
11934 small
= fctl_wwn_cmp(swwn
, dwwn
);
11935 pd
= fctl_get_remote_port_by_pwwn(port
, dwwn
);
11937 mutex_enter(&pd
->pd_mutex
);
11938 sent
= (pd
->pd_flags
== PD_ELS_IN_PROGRESS
) ? 1 : 0;
11940 * Most likely this means a cross login is in
11941 * progress or a device about to be yanked out.
11942 * Only accept the plogi if my wwn is smaller.
11945 if (pd
->pd_type
== PORT_DEVICE_OLD
) {
11949 * Stop plogi request (if any)
11950 * attempt from local side to speedup
11951 * the discovery progress.
11952 * Mark the pd as PD_PLOGI_RECEPIENT.
11954 if (f_port
== 0 && small
< 0) {
11955 pd
->pd_recepient
= PD_PLOGI_RECEPIENT
;
11957 fc_wwn_to_str(&pd
->pd_port_name
, dww_name
);
11959 mutex_exit(&pd
->pd_mutex
);
11961 FP_TRACE(FP_NHEAD1(3, 0), "fp_handle_unsol_plogi: Unsol PLOGI"
11962 " received. PD still exists in the PWWN list. pd=%p "
11963 "PWWN=%s, sent=%x", pd
, dww_name
, sent
);
11965 if (f_port
== 0 && small
< 0) {
11966 FP_TRACE(FP_NHEAD1(3, 0),
11967 "fp_handle_unsol_plogi: Mark the pd"
11968 " as plogi recipient, pd=%p, PWWN=%s"
11970 pd
, dww_name
, sent
);
11977 * Avoid Login collisions by accepting only if my WWN is smaller.
11979 * A side note: There is no need to start a PLOGI from this end in
11980 * this context if login isn't going to be accepted for the
11981 * above reason as either a LIP (in private loop), RSCN (in
11982 * fabric topology), or an FLOGI (in point to point - Huh ?
11983 * check FC-PH) would normally drive the PLOGI from this end.
11984 * At this point of time there is no need for an inbound PLOGI
11985 * to kick an outbound PLOGI when it is going to be rejected
11986 * for the reason of WWN being smaller. However it isn't hard
11987 * to do that either (when such a need arises, start a timer
11988 * for a duration that extends beyond a normal device discovery
11989 * time and check if an outbound PLOGI did go before that, if
11992 * Unfortunately, as it turned out, during booting, it is possible
11993 * to miss another initiator in the same loop as port driver
11994 * instances are serially attached. While preserving the above
11995 * comments for belly laughs, please kick an outbound PLOGI in
11996 * a non-switch environment (which is a pt pt between N_Ports or
11999 * While preserving the above comments for amusement, send an
12000 * ACC if the PLOGI is going to be rejected for WWN being smaller
12001 * when no discovery is in progress at this end. Turn around
12002 * and make the port device as the PLOGI initiator, so that
12003 * during subsequent link/loop initialization, this end drives
12004 * the PLOGI (In fact both ends do in this particular case, but
12007 * Make sure the PLOGIs initiated by the switch from not-so-well-known
12008 * ports (such as 0xFFFC41) are accepted too.
12010 if ((f_port
== 0 && small
< 0) || (((small
> 0 && do_acc
) ||
12011 FC_MUST_ACCEPT_D_ID(buf
->ub_frame
.s_id
)) && sent
== 0)) {
12012 if (fp_is_class_supported(port
->fp_cos
,
12013 buf
->ub_class
) == FC_FAILURE
) {
12014 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
12015 cmd
= fp_alloc_pkt(port
,
12016 sizeof (la_els_logi_t
), 0, sleep
, pd
);
12020 cmd
->cmd_pkt
.pkt_cmdlen
= sizeof (la_els_rjt_t
);
12021 cmd
->cmd_pkt
.pkt_rsplen
= 0;
12022 fp_els_rjt_init(port
, cmd
, buf
,
12023 FC_ACTION_NON_RETRYABLE
,
12024 FC_REASON_CLASS_NOT_SUPP
, job
);
12025 FP_TRACE(FP_NHEAD1(3, 0),
12026 "fp_handle_unsol_plogi: "
12027 "Unsupported class. rejecting PLOGI");
12030 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logi_t
),
12035 cmd
->cmd_pkt
.pkt_cmdlen
= sizeof (la_els_logi_t
);
12036 cmd
->cmd_pkt
.pkt_rsplen
= 0;
12039 * Sometime later, we should validate the service
12040 * parameters instead of just accepting it.
12042 fp_login_acc_init(port
, cmd
, buf
, job
, KM_SLEEP
);
12043 FP_TRACE(FP_NHEAD1(3, 0), "fp_handle_unsol_plogi: "
12044 "Accepting PLOGI, f_port=%d, small=%d, "
12045 "do_acc=%d, sent=%d.", f_port
, small
, do_acc
,
12049 * If fp_port_id is zero and topology is
12050 * Point-to-Point, get the local port id from
12051 * the d_id in the PLOGI request.
12052 * If the outgoing FLOGI hasn't been accepted,
12053 * the topology will be unknown here. But it's
12054 * still safe to save the d_id to fp_port_id,
12055 * just because it will be overwritten later
12056 * if the topology is not Point-to-Point.
12058 mutex_enter(&port
->fp_mutex
);
12059 if ((port
->fp_port_id
.port_id
== 0) &&
12060 (port
->fp_topology
== FC_TOP_PT_PT
||
12061 port
->fp_topology
== FC_TOP_UNKNOWN
)) {
12062 port
->fp_port_id
.port_id
=
12063 buf
->ub_frame
.d_id
;
12065 mutex_exit(&port
->fp_mutex
);
12068 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
) ||
12069 port
->fp_options
& FP_SEND_RJT
) {
12070 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logi_t
),
12075 cmd
->cmd_pkt
.pkt_cmdlen
= sizeof (la_els_rjt_t
);
12076 cmd
->cmd_pkt
.pkt_rsplen
= 0;
12078 * Send out Logical busy to indicate
12079 * the detection of PLOGI collision
12081 fp_els_rjt_init(port
, cmd
, buf
,
12082 FC_ACTION_NON_RETRYABLE
,
12083 FC_REASON_LOGICAL_BSY
, job
);
12085 fc_wwn_to_str(dwwn
, dww_name
);
12086 FP_TRACE(FP_NHEAD1(3, 0), "fp_handle_unsol_plogi: "
12087 "Rejecting Unsol PLOGI with Logical Busy."
12088 "possible PLOGI collision. PWWN=%s, sent=%x",
12095 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
) {
12102 * Handle mischievous turning over of our own FLOGI requests back to
12103 * us by the SOC+ microcode. In other words, look at the class of such
12104 * bone headed requests, if 1 or 2, bluntly P_RJT them, if 3 drop them
12108 fp_handle_unsol_flogi(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
,
12109 job_request_t
*job
, int sleep
)
12115 if (fp_is_class_supported(port
->fp_cos
, buf
->ub_class
) == FC_FAILURE
) {
12116 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
12117 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
),
12122 fp_els_rjt_init(port
, cmd
, buf
,
12123 FC_ACTION_NON_RETRYABLE
,
12124 FC_REASON_CLASS_NOT_SUPP
, job
);
12130 FP_TRACE(FP_NHEAD1(3, 0), "fp_handle_unsol_flogi:"
12131 " s_id=%x, d_id=%x, type=%x, f_ctl=%x"
12132 " seq_id=%x, ox_id=%x, rx_id=%x, ro=%x",
12133 buf
->ub_frame
.s_id
, buf
->ub_frame
.d_id
,
12134 buf
->ub_frame
.type
, buf
->ub_frame
.f_ctl
,
12135 buf
->ub_frame
.seq_id
, buf
->ub_frame
.ox_id
,
12136 buf
->ub_frame
.rx_id
, buf
->ub_frame
.ro
);
12138 mutex_enter(&port
->fp_mutex
);
12139 state
= FC_PORT_STATE_MASK(port
->fp_state
);
12140 s_id
= port
->fp_port_id
.port_id
;
12141 mutex_exit(&port
->fp_mutex
);
12143 if (state
!= FC_STATE_ONLINE
||
12144 (s_id
&& buf
->ub_frame
.s_id
== s_id
)) {
12145 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
12146 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
),
12151 fp_els_rjt_init(port
, cmd
, buf
,
12152 FC_ACTION_NON_RETRYABLE
,
12153 FC_REASON_INVALID_LINK_CTRL
, job
);
12154 FP_TRACE(FP_NHEAD1(3, 0),
12155 "fp_handle_unsol_flogi: "
12156 "Rejecting PLOGI. Invalid Link CTRL");
12161 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logi_t
),
12167 * Let's not aggressively validate the N_Port's
12168 * service parameters until PLOGI. Suffice it
12169 * to give a hint that we are an N_Port and we
12170 * are game to some serious stuff here.
12172 fp_login_acc_init(port
, cmd
, buf
, job
, KM_SLEEP
);
12173 FP_TRACE(FP_NHEAD1(3, 0), "fp_handle_unsol_flogi: "
12174 "Accepting PLOGI");
12178 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
) {
12185 * Perform PLOGI accept
12188 fp_login_acc_init(fc_local_port_t
*port
, fp_cmd_t
*cmd
, fc_unsol_buf_t
*buf
,
12189 job_request_t
*job
, int sleep
)
12192 fc_portmap_t
*listptr
;
12193 la_els_logi_t payload
;
12195 ASSERT(buf
!= NULL
);
12198 * If we are sending ACC to PLOGI and we haven't already
12199 * create port and node device handles, let's create them
12202 if (buf
->ub_buffer
[0] == LA_ELS_PLOGI
&&
12203 FC_IS_REAL_DEVICE(buf
->ub_frame
.s_id
)) {
12206 fc_remote_port_t
*pd
;
12207 la_els_logi_t
*req
;
12209 req
= (la_els_logi_t
*)buf
->ub_buffer
;
12210 small
= fctl_wwn_cmp(&port
->fp_service_params
.nport_ww_name
,
12211 &req
->nport_ww_name
);
12213 mutex_enter(&port
->fp_mutex
);
12214 do_acc
= (port
->fp_statec_busy
== 0) ? 1 : 0;
12215 mutex_exit(&port
->fp_mutex
);
12217 FP_TRACE(FP_NHEAD1(3, 0), "fp_plogi_acc_init fp %x, pd %x",
12218 port
->fp_port_id
.port_id
, buf
->ub_frame
.s_id
);
12219 pd
= fctl_create_remote_port(port
, &req
->node_ww_name
,
12220 &req
->nport_ww_name
, buf
->ub_frame
.s_id
,
12221 PD_PLOGI_RECEPIENT
, sleep
);
12223 FP_TRACE(FP_NHEAD1(3, 0), "login_acc_init: "
12224 "Couldn't create port device for d_id:0x%x",
12225 buf
->ub_frame
.s_id
);
12227 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
12228 "couldn't create port device d_id=%x",
12229 buf
->ub_frame
.s_id
);
12232 * usoc currently returns PLOGIs inline and
12233 * the maximum buffer size is 60 bytes or so.
12234 * So attempt not to look beyond what is in
12235 * the unsolicited buffer
12237 * JNI also traverses this path sometimes
12239 if (buf
->ub_bufsize
>= sizeof (la_els_logi_t
)) {
12240 fp_register_login(NULL
, pd
, req
, buf
->ub_class
);
12242 mutex_enter(&pd
->pd_mutex
);
12243 if (pd
->pd_login_count
== 0) {
12244 pd
->pd_login_count
++;
12246 pd
->pd_state
= PORT_DEVICE_LOGGED_IN
;
12247 pd
->pd_login_class
= buf
->ub_class
;
12248 mutex_exit(&pd
->pd_mutex
);
12251 listptr
= kmem_zalloc(sizeof (fc_portmap_t
), sleep
);
12252 if (listptr
!= NULL
) {
12253 fctl_copy_portmap(listptr
, pd
);
12254 (void) fp_ulp_devc_cb(port
, listptr
,
12258 if (small
> 0 && do_acc
) {
12259 mutex_enter(&pd
->pd_mutex
);
12260 pd
->pd_recepient
= PD_PLOGI_INITIATOR
;
12261 mutex_exit(&pd
->pd_mutex
);
12266 cmd
->cmd_pkt
.pkt_tran_flags
= buf
->ub_class
;
12267 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_OUTBOUND
;
12268 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
12269 cmd
->cmd_retry_count
= 1;
12270 cmd
->cmd_ulp_pkt
= NULL
;
12272 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
12273 cmd
->cmd_job
= job
;
12275 pkt
= &cmd
->cmd_pkt
;
12277 fp_unsol_resp_init(pkt
, buf
, R_CTL_ELS_RSP
, FC_TYPE_EXTENDED_LS
);
12279 payload
= port
->fp_service_params
;
12280 payload
.ls_code
.ls_code
= LA_ELS_ACC
;
12282 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
12283 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
12285 FP_TRACE(FP_NHEAD1(3, 0), "login_acc_init: ELS:0x%x d_id:0x%x "
12286 "bufsize:0x%x sizeof (la_els_logi):0x%x "
12287 "port's wwn:0x%01x%03x%04x%08x requestor's wwn:0x%01x%03x%04x%08x "
12288 "statec_busy:0x%x", buf
->ub_buffer
[0], buf
->ub_frame
.s_id
,
12289 buf
->ub_bufsize
, sizeof (la_els_logi_t
),
12290 port
->fp_service_params
.nport_ww_name
.w
.naa_id
,
12291 port
->fp_service_params
.nport_ww_name
.w
.nport_id
,
12292 port
->fp_service_params
.nport_ww_name
.w
.wwn_hi
,
12293 port
->fp_service_params
.nport_ww_name
.w
.wwn_lo
,
12294 ((la_els_logi_t
*)buf
->ub_buffer
)->nport_ww_name
.w
.naa_id
,
12295 ((la_els_logi_t
*)buf
->ub_buffer
)->nport_ww_name
.w
.nport_id
,
12296 ((la_els_logi_t
*)buf
->ub_buffer
)->nport_ww_name
.w
.wwn_hi
,
12297 ((la_els_logi_t
*)buf
->ub_buffer
)->nport_ww_name
.w
.wwn_lo
,
12298 port
->fp_statec_busy
);
12302 #define RSCN_EVENT_NAME_LEN 256
12308 fp_handle_unsol_rscn(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
,
12309 job_request_t
*job
, int sleep
)
12316 fc_rscn_t
*payload
;
12317 fc_portmap_t
*listptr
;
12318 fctl_ns_req_t
*ns_cmd
;
12319 fc_affected_id_t
*page
;
12321 nvlist_t
*attr_list
= NULL
;
12323 mutex_enter(&port
->fp_mutex
);
12324 if (!FC_IS_TOP_SWITCH(port
->fp_topology
)) {
12325 if (--port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
12326 --port
->fp_rscn_count
;
12328 mutex_exit(&port
->fp_mutex
);
12331 mutex_exit(&port
->fp_mutex
);
12333 cmd
= fp_alloc_pkt(port
, FP_PORT_IDENTIFIER_LEN
, 0, sleep
, NULL
);
12335 fp_els_acc_init(port
, cmd
, buf
, job
);
12336 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
) {
12341 payload
= (fc_rscn_t
*)buf
->ub_buffer
;
12342 ASSERT(payload
->rscn_code
== LA_ELS_RSCN
);
12343 ASSERT(payload
->rscn_len
== FP_PORT_IDENTIFIER_LEN
);
12345 len
= payload
->rscn_payload_len
- FP_PORT_IDENTIFIER_LEN
;
12348 mutex_enter(&port
->fp_mutex
);
12349 if (--port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
12350 --port
->fp_rscn_count
;
12352 mutex_exit(&port
->fp_mutex
);
12357 ASSERT((len
& 0x3) == 0); /* Must be power of 4 */
12358 count
= (len
>> 2) << 1; /* number of pages multiplied by 2 */
12360 listptr
= kmem_zalloc(sizeof (fc_portmap_t
) * count
, sleep
);
12361 page
= (fc_affected_id_t
*)(buf
->ub_buffer
+ sizeof (fc_rscn_t
));
12363 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
12365 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gpn_id_t
),
12366 sizeof (ns_resp_gpn_id_t
), sizeof (ns_resp_gpn_id_t
),
12368 if (ns_cmd
== NULL
) {
12369 kmem_free(listptr
, sizeof (fc_portmap_t
) * count
);
12371 mutex_enter(&port
->fp_mutex
);
12372 if (--port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
12373 --port
->fp_rscn_count
;
12375 mutex_exit(&port
->fp_mutex
);
12380 ns_cmd
->ns_cmd_code
= NS_GPN_ID
;
12382 FP_TRACE(FP_NHEAD1(3, 0), "fp_handle_unsol_rscn: s_id=%x, d_id=%x,"
12383 "type=%x, f_ctl=%x seq_id=%x, ox_id=%x, rx_id=%x"
12384 " ro=%x", buf
->ub_frame
.s_id
, buf
->ub_frame
.d_id
,
12385 buf
->ub_frame
.type
, buf
->ub_frame
.f_ctl
, buf
->ub_frame
.seq_id
,
12386 buf
->ub_frame
.ox_id
, buf
->ub_frame
.rx_id
, buf
->ub_frame
.ro
);
12388 /* Only proceed if we can allocate nvname and the nvlist */
12389 if ((nvname
= kmem_zalloc(RSCN_EVENT_NAME_LEN
, KM_NOSLEEP
)) != NULL
&&
12390 nvlist_alloc(&attr_list
, NV_UNIQUE_NAME_TYPE
,
12391 KM_NOSLEEP
) == DDI_SUCCESS
) {
12392 if (!(attr_list
&& nvlist_add_uint32(attr_list
, "instance",
12393 port
->fp_instance
) == DDI_SUCCESS
&&
12394 nvlist_add_byte_array(attr_list
, "port-wwn",
12395 port
->fp_service_params
.nport_ww_name
.raw_wwn
,
12396 sizeof (la_wwn_t
)) == DDI_SUCCESS
)) {
12397 nvlist_free(attr_list
);
12402 for (listindex
= 0; len
; len
-= FP_PORT_IDENTIFIER_LEN
, page
++) {
12403 /* Add affected page to the event payload */
12404 if (attr_list
!= NULL
) {
12405 (void) snprintf(nvname
, RSCN_EVENT_NAME_LEN
,
12406 "affected_page_%d", listindex
);
12407 if (attr_list
&& nvlist_add_uint32(attr_list
, nvname
,
12408 ntohl(*(uint32_t *)page
)) != DDI_SUCCESS
) {
12409 /* We don't send a partial event, so dump it */
12410 nvlist_free(attr_list
);
12415 * Query the NS to get the Port WWN for this
12419 switch (page
->aff_format
& FC_RSCN_ADDRESS_MASK
) {
12420 case FC_RSCN_PORT_ADDRESS
:
12421 fp_validate_rscn_page(port
, page
, job
, ns_cmd
,
12422 listptr
, &listindex
, sleep
);
12424 if (listindex
== 0) {
12426 * We essentially did not process this RSCN. So,
12427 * ULPs are not going to be called and so we
12428 * decrement the rscn_count
12430 mutex_enter(&port
->fp_mutex
);
12431 if (--port
->fp_rscn_count
==
12432 FC_INVALID_RSCN_COUNT
) {
12433 --port
->fp_rscn_count
;
12435 mutex_exit(&port
->fp_mutex
);
12439 case FC_RSCN_AREA_ADDRESS
:
12443 case FC_RSCN_DOMAIN_ADDRESS
:
12447 fp_validate_area_domain(port
, page
->aff_d_id
, mask
,
12451 case FC_RSCN_FABRIC_ADDRESS
:
12453 * We need to discover all the devices on this
12456 fp_validate_area_domain(port
, 0, 0, job
, sleep
);
12463 if (attr_list
!= NULL
) {
12464 (void) ddi_log_sysevent(port
->fp_port_dip
, DDI_VENDOR_SUNW
,
12465 EC_SUNFC
, ESC_SUNFC_PORT_RSCN
, attr_list
,
12467 nvlist_free(attr_list
);
12469 FP_TRACE(FP_NHEAD1(9, 0),
12470 "RSCN handled, but event not sent to userland");
12472 if (nvname
!= NULL
) {
12473 kmem_free(nvname
, RSCN_EVENT_NAME_LEN
);
12477 fctl_free_ns_cmd(ns_cmd
);
12482 page
= (fc_affected_id_t
*)(buf
->ub_buffer
+
12483 sizeof (fc_rscn_t
));
12485 if (listptr
->map_did
.port_id
!= page
->aff_d_id
) {
12486 FP_TRACE(FP_NHEAD1(9, 0),
12487 "PORT RSCN: processed=%x, reporting=%x",
12488 listptr
->map_did
.port_id
, page
->aff_d_id
);
12492 (void) fp_ulp_devc_cb(port
, listptr
, listindex
, count
,
12495 kmem_free(listptr
, sizeof (fc_portmap_t
) * count
);
12501 * Fill out old map for ULPs with fp_mutex, fd_mutex and pd_mutex held
12504 fp_fillout_old_map_held(fc_portmap_t
*map
, fc_remote_port_t
*pd
, uchar_t flag
)
12508 fc_local_port_t
*port
;
12510 port
= pd
->pd_port
;
12512 /* This function has the following bunch of assumptions */
12513 ASSERT(port
!= NULL
);
12514 ASSERT(MUTEX_HELD(&port
->fp_mutex
));
12515 ASSERT(MUTEX_HELD(&pd
->pd_remote_nodep
->fd_mutex
));
12516 ASSERT(MUTEX_HELD(&pd
->pd_mutex
));
12518 pd
->pd_state
= PORT_DEVICE_INVALID
;
12519 pd
->pd_type
= PORT_DEVICE_OLD
;
12520 initiator
= (pd
->pd_recepient
== PD_PLOGI_INITIATOR
) ? 1 : 0;
12521 is_switch
= FC_IS_TOP_SWITCH(port
->fp_topology
);
12523 fctl_delist_did_table(port
, pd
);
12524 fctl_delist_pwwn_table(port
, pd
);
12526 FP_TRACE(FP_NHEAD1(6, 0), "fp_fillout_old_map_held: port=%p, d_id=%x"
12527 " removed the PD=%p from DID and PWWN tables",
12528 port
, pd
->pd_port_id
.port_id
, pd
);
12530 if ((!flag
) && port
&& initiator
&& is_switch
) {
12531 (void) fctl_add_orphan_held(port
, pd
);
12533 fctl_copy_portmap_held(map
, pd
);
12538 * Fill out old map for ULPs
12541 fp_fillout_old_map(fc_portmap_t
*map
, fc_remote_port_t
*pd
, uchar_t flag
)
12545 fc_local_port_t
*port
;
12547 mutex_enter(&pd
->pd_mutex
);
12548 port
= pd
->pd_port
;
12549 mutex_exit(&pd
->pd_mutex
);
12551 mutex_enter(&port
->fp_mutex
);
12552 mutex_enter(&pd
->pd_mutex
);
12554 pd
->pd_state
= PORT_DEVICE_INVALID
;
12555 pd
->pd_type
= PORT_DEVICE_OLD
;
12556 initiator
= (pd
->pd_recepient
== PD_PLOGI_INITIATOR
) ? 1 : 0;
12557 is_switch
= FC_IS_TOP_SWITCH(port
->fp_topology
);
12559 fctl_delist_did_table(port
, pd
);
12560 fctl_delist_pwwn_table(port
, pd
);
12562 FP_TRACE(FP_NHEAD1(6, 0), "fp_fillout_old_map: port=%p, d_id=%x"
12563 " removed the PD=%p from DID and PWWN tables",
12564 port
, pd
->pd_port_id
.port_id
, pd
);
12566 mutex_exit(&pd
->pd_mutex
);
12567 mutex_exit(&port
->fp_mutex
);
12569 ASSERT(port
!= NULL
);
12570 if ((!flag
) && port
&& initiator
&& is_switch
) {
12571 (void) fctl_add_orphan(port
, pd
, KM_NOSLEEP
);
12573 fctl_copy_portmap(map
, pd
);
12579 * Fillout Changed Map for ULPs
12582 fp_fillout_changed_map(fc_portmap_t
*map
, fc_remote_port_t
*pd
,
12583 uint32_t *new_did
, la_wwn_t
*new_pwwn
)
12585 ASSERT(MUTEX_HELD(&pd
->pd_mutex
));
12587 pd
->pd_type
= PORT_DEVICE_CHANGED
;
12589 pd
->pd_port_id
.port_id
= *new_did
;
12592 pd
->pd_port_name
= *new_pwwn
;
12594 mutex_exit(&pd
->pd_mutex
);
12596 fctl_copy_portmap(map
, pd
);
12598 mutex_enter(&pd
->pd_mutex
);
12599 pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
12604 * Fillout New Name Server map
12607 fp_fillout_new_nsmap(fc_local_port_t
*port
, ddi_acc_handle_t
*handle
,
12608 fc_portmap_t
*port_map
, ns_resp_gan_t
*gan_resp
, uint32_t d_id
)
12610 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
12613 FC_GET_RSP(port
, *handle
, (uint8_t *)&port_map
->map_pwwn
,
12614 (uint8_t *)&gan_resp
->gan_pwwn
, sizeof (gan_resp
->gan_pwwn
),
12616 FC_GET_RSP(port
, *handle
, (uint8_t *)&port_map
->map_nwwn
,
12617 (uint8_t *)&gan_resp
->gan_nwwn
, sizeof (gan_resp
->gan_nwwn
),
12619 FC_GET_RSP(port
, *handle
, (uint8_t *)port_map
->map_fc4_types
,
12620 (uint8_t *)gan_resp
->gan_fc4types
,
12621 sizeof (gan_resp
->gan_fc4types
), DDI_DEV_AUTOINCR
);
12623 bcopy(&gan_resp
->gan_pwwn
, &port_map
->map_pwwn
,
12624 sizeof (gan_resp
->gan_pwwn
));
12625 bcopy(&gan_resp
->gan_nwwn
, &port_map
->map_nwwn
,
12626 sizeof (gan_resp
->gan_nwwn
));
12627 bcopy(gan_resp
->gan_fc4types
, port_map
->map_fc4_types
,
12628 sizeof (gan_resp
->gan_fc4types
));
12630 port_map
->map_did
.port_id
= d_id
;
12631 port_map
->map_did
.priv_lilp_posit
= 0;
12632 port_map
->map_hard_addr
.hard_addr
= 0;
12633 port_map
->map_hard_addr
.rsvd
= 0;
12634 port_map
->map_state
= PORT_DEVICE_INVALID
;
12635 port_map
->map_type
= PORT_DEVICE_NEW
;
12636 port_map
->map_flags
= 0;
12637 port_map
->map_pd
= NULL
;
12639 (void) fctl_remove_if_orphan(port
, &port_map
->map_pwwn
);
12641 ASSERT(port
!= NULL
);
12646 * Perform LINIT ELS
12649 fp_remote_lip(fc_local_port_t
*port
, la_wwn_t
*pwwn
, int sleep
,
12650 job_request_t
*job
)
12659 fc_porttype_t ptype
;
12661 fc_linit_req_t payload
;
12662 fc_remote_port_t
*pd
;
12666 ASSERT(job
!= NULL
);
12667 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
12669 pd
= fctl_get_remote_port_by_pwwn(port
, pwwn
);
12671 fctl_ns_req_t
*ns_cmd
;
12673 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gid_pn_t
),
12674 sizeof (ns_resp_gid_pn_t
), sizeof (ns_resp_gid_pn_t
),
12677 if (ns_cmd
== NULL
) {
12680 job
->job_result
= FC_SUCCESS
;
12681 ns_cmd
->ns_cmd_code
= NS_GID_PN
;
12682 ((ns_req_gid_pn_t
*)(ns_cmd
->ns_cmd_buf
))->pwwn
= *pwwn
;
12684 ret
= fp_ns_query(port
, ns_cmd
, job
, 1, sleep
);
12685 if (ret
!= FC_SUCCESS
|| job
->job_result
!= FC_SUCCESS
) {
12686 fctl_free_ns_cmd(ns_cmd
);
12687 return (FC_FAILURE
);
12689 bcopy(ns_cmd
->ns_data_buf
, (caddr_t
)&d_id
, sizeof (d_id
));
12690 d_id
= BE_32(*((uint32_t *)ns_cmd
->ns_data_buf
));
12692 fctl_free_ns_cmd(ns_cmd
);
12693 lfa
= d_id
& 0xFFFF00;
12696 * Given this D_ID, get the port type to see if
12697 * we can do LINIT on the LFA
12699 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gpt_id_t
),
12700 sizeof (ns_resp_gpt_id_t
), sizeof (ns_resp_gpt_id_t
),
12703 if (ns_cmd
== NULL
) {
12707 job
->job_result
= FC_SUCCESS
;
12708 ns_cmd
->ns_cmd_code
= NS_GPT_ID
;
12710 ((ns_req_gpt_id_t
*)(ns_cmd
->ns_cmd_buf
))->pid
.port_id
= d_id
;
12711 ((ns_req_gpt_id_t
*)
12712 (ns_cmd
->ns_cmd_buf
))->pid
.priv_lilp_posit
= 0;
12714 ret
= fp_ns_query(port
, ns_cmd
, job
, 1, sleep
);
12715 if (ret
!= FC_SUCCESS
|| job
->job_result
!= FC_SUCCESS
) {
12716 fctl_free_ns_cmd(ns_cmd
);
12717 return (FC_FAILURE
);
12719 bcopy(ns_cmd
->ns_data_buf
, (caddr_t
)&ptype
, sizeof (ptype
));
12721 fctl_free_ns_cmd(ns_cmd
);
12723 switch (ptype
.port_type
) {
12724 case FC_NS_PORT_NL
:
12725 case FC_NS_PORT_F_NL
:
12726 case FC_NS_PORT_FL
:
12730 return (FC_FAILURE
);
12733 mutex_enter(&pd
->pd_mutex
);
12734 ptype
= pd
->pd_porttype
;
12736 switch (pd
->pd_porttype
.port_type
) {
12737 case FC_NS_PORT_NL
:
12738 case FC_NS_PORT_F_NL
:
12739 case FC_NS_PORT_FL
:
12740 lfa
= pd
->pd_port_id
.port_id
& 0xFFFF00;
12744 mutex_exit(&pd
->pd_mutex
);
12745 return (FC_FAILURE
);
12747 mutex_exit(&pd
->pd_mutex
);
12750 mutex_enter(&port
->fp_mutex
);
12751 s_id
= port
->fp_port_id
.port_id
;
12752 class = port
->fp_ns_login_class
;
12753 mutex_exit(&port
->fp_mutex
);
12755 cmd
= fp_alloc_pkt(port
, sizeof (fc_linit_req_t
),
12756 sizeof (fc_linit_resp_t
), sleep
, pd
);
12761 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| class;
12762 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
12763 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
12764 cmd
->cmd_retry_count
= fp_retry_count
;
12765 cmd
->cmd_ulp_pkt
= NULL
;
12767 pkt
= &cmd
->cmd_pkt
;
12768 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
12770 fp_els_init(cmd
, s_id
, lfa
, fp_linit_intr
, job
);
12773 * How does LIP work by the way ?
12774 * If the L_Port receives three consecutive identical ordered
12775 * sets whose first two characters (fully decoded) are equal to
12776 * the values shown in Table 3 of FC-AL-2 then the L_Port shall
12777 * recognize a Loop Initialization Primitive sequence. The
12778 * character 3 determines the type of lip:
12779 * LIP(F7) Normal LIP
12780 * LIP(F8) Loop Failure LIP
12782 * The possible combination for the 3rd and 4th bytes are:
12783 * F7, F7 Normal Lip - No valid AL_PA
12784 * F8, F8 Loop Failure - No valid AL_PA
12785 * F7, AL_PS Normal Lip - Valid source AL_PA
12786 * F8, AL_PS Loop Failure - Valid source AL_PA
12787 * AL_PD AL_PS Loop reset of AL_PD originated by AL_PS
12788 * And Normal Lip for all other loop members
12789 * 0xFF AL_PS Vendor specific reset of all loop members
12791 * Now, it may not always be that we, at the source, may have an
12792 * AL_PS (AL_PA of source) for 4th character slot, so we decide
12793 * to do (Normal Lip, No Valid AL_PA), that means, in the LINIT
12794 * payload we are going to set:
12795 * lip_b3 = 0xF7; Normal LIP
12796 * lip_b4 = 0xF7; No valid source AL_PA
12798 payload
.ls_code
.ls_code
= LA_ELS_LINIT
;
12799 payload
.ls_code
.mbz
= 0;
12801 payload
.func
= 0; /* Let Fabric determine the best way */
12802 payload
.lip_b3
= 0xF7; /* Normal LIP */
12803 payload
.lip_b4
= 0xF7; /* No valid source AL_PA */
12805 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
12806 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
12808 job
->job_counter
= 1;
12810 ret
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
12811 if (ret
== FC_SUCCESS
) {
12813 rval
= job
->job_result
;
12824 * Fill out the device handles with GAN response
12827 fp_stuff_device_with_gan(ddi_acc_handle_t
*handle
, fc_remote_port_t
*pd
,
12828 ns_resp_gan_t
*gan_resp
)
12830 fc_remote_node_t
*node
;
12831 fc_porttype_t type
;
12832 fc_local_port_t
*port
;
12834 ASSERT(pd
!= NULL
);
12835 ASSERT(handle
!= NULL
);
12837 port
= pd
->pd_port
;
12839 FP_TRACE(FP_NHEAD1(1, 0), "GAN PD stuffing; pd=%p,"
12840 " port_id=%x, sym_len=%d fc4-type=%x",
12841 pd
, gan_resp
->gan_type_id
.rsvd
,
12842 gan_resp
->gan_spnlen
, gan_resp
->gan_fc4types
[0]);
12844 mutex_enter(&pd
->pd_mutex
);
12846 FC_GET_RSP(port
, *handle
, (uint8_t *)&type
,
12847 (uint8_t *)&gan_resp
->gan_type_id
, sizeof (type
), DDI_DEV_AUTOINCR
);
12849 pd
->pd_porttype
.port_type
= type
.port_type
;
12850 pd
->pd_porttype
.rsvd
= 0;
12852 pd
->pd_spn_len
= gan_resp
->gan_spnlen
;
12853 if (pd
->pd_spn_len
) {
12854 FC_GET_RSP(port
, *handle
, (uint8_t *)pd
->pd_spn
,
12855 (uint8_t *)gan_resp
->gan_spname
, pd
->pd_spn_len
,
12859 FC_GET_RSP(port
, *handle
, (uint8_t *)pd
->pd_ip_addr
,
12860 (uint8_t *)gan_resp
->gan_ip
, sizeof (pd
->pd_ip_addr
),
12862 FC_GET_RSP(port
, *handle
, (uint8_t *)&pd
->pd_cos
,
12863 (uint8_t *)&gan_resp
->gan_cos
, sizeof (pd
->pd_cos
),
12865 FC_GET_RSP(port
, *handle
, (uint8_t *)pd
->pd_fc4types
,
12866 (uint8_t *)gan_resp
->gan_fc4types
, sizeof (pd
->pd_fc4types
),
12869 node
= pd
->pd_remote_nodep
;
12870 mutex_exit(&pd
->pd_mutex
);
12872 mutex_enter(&node
->fd_mutex
);
12874 FC_GET_RSP(port
, *handle
, (uint8_t *)node
->fd_ipa
,
12875 (uint8_t *)gan_resp
->gan_ipa
, sizeof (node
->fd_ipa
),
12878 node
->fd_snn_len
= gan_resp
->gan_snnlen
;
12879 if (node
->fd_snn_len
) {
12880 FC_GET_RSP(port
, *handle
, (uint8_t *)node
->fd_snn
,
12881 (uint8_t *)gan_resp
->gan_snname
, node
->fd_snn_len
,
12885 mutex_exit(&node
->fd_mutex
);
12890 * Handles all NS Queries (also means that this function
12891 * doesn't handle NS object registration)
12894 fp_ns_query(fc_local_port_t
*port
, fctl_ns_req_t
*ns_cmd
, job_request_t
*job
,
12895 int polled
, int sleep
)
12900 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
12902 if (ns_cmd
->ns_cmd_code
== NS_GA_NXT
) {
12903 FP_TRACE(FP_NHEAD1(1, 0), "fp_ns_query GA_NXT fp %x pd %x",
12904 port
->fp_port_id
.port_id
, ns_cmd
->ns_gan_sid
);
12907 if (ns_cmd
->ns_cmd_size
== 0) {
12908 return (FC_FAILURE
);
12911 cmd
= fp_alloc_pkt(port
, sizeof (fc_ct_header_t
) +
12912 ns_cmd
->ns_cmd_size
, sizeof (fc_ct_header_t
) +
12913 ns_cmd
->ns_resp_size
, sleep
, NULL
);
12918 fp_ct_init(port
, cmd
, ns_cmd
, ns_cmd
->ns_cmd_code
, ns_cmd
->ns_cmd_buf
,
12919 ns_cmd
->ns_cmd_size
, ns_cmd
->ns_resp_size
, job
);
12922 job
->job_counter
= 1;
12923 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
12925 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
12926 if (rval
!= FC_SUCCESS
) {
12927 job
->job_result
= rval
;
12931 * Return FC_SUCCESS to indicate that
12932 * fp_iodone is performed already.
12940 rval
= job
->job_result
;
12948 * Initialize Common Transport request
12951 fp_ct_init(fc_local_port_t
*port
, fp_cmd_t
*cmd
, fctl_ns_req_t
*ns_cmd
,
12952 uint16_t cmd_code
, caddr_t cmd_buf
, uint16_t cmd_len
,
12953 uint16_t resp_len
, job_request_t
*job
)
12960 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
12962 mutex_enter(&port
->fp_mutex
);
12963 s_id
= port
->fp_port_id
.port_id
;
12964 class = port
->fp_ns_login_class
;
12965 mutex_exit(&port
->fp_mutex
);
12967 cmd
->cmd_job
= job
;
12968 cmd
->cmd_private
= ns_cmd
;
12969 pkt
= &cmd
->cmd_pkt
;
12971 ct
.ct_rev
= CT_REV
;
12973 ct
.ct_fcstype
= FCSTYPE_DIRECTORY
;
12974 ct
.ct_fcssubtype
= FCSSUB_DS_NAME_SERVER
;
12976 ct
.ct_reserved1
= 0;
12977 ct
.ct_cmdrsp
= cmd_code
;
12978 ct
.ct_aiusize
= resp_len
>> 2;
12979 ct
.ct_reserved2
= 0;
12984 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&ct
,
12985 (uint8_t *)pkt
->pkt_cmd
, sizeof (ct
), DDI_DEV_AUTOINCR
);
12987 pkt
->pkt_cmd_fhdr
.r_ctl
= R_CTL_UNSOL_CONTROL
;
12988 pkt
->pkt_cmd_fhdr
.d_id
= 0xFFFFFC;
12989 pkt
->pkt_cmd_fhdr
.s_id
= s_id
;
12990 pkt
->pkt_cmd_fhdr
.type
= FC_TYPE_FC_SERVICES
;
12991 pkt
->pkt_cmd_fhdr
.f_ctl
= F_CTL_SEQ_INITIATIVE
|
12992 F_CTL_FIRST_SEQ
| F_CTL_END_SEQ
;
12993 pkt
->pkt_cmd_fhdr
.seq_id
= 0;
12994 pkt
->pkt_cmd_fhdr
.df_ctl
= 0;
12995 pkt
->pkt_cmd_fhdr
.seq_cnt
= 0;
12996 pkt
->pkt_cmd_fhdr
.ox_id
= 0xffff;
12997 pkt
->pkt_cmd_fhdr
.rx_id
= 0xffff;
12998 pkt
->pkt_cmd_fhdr
.ro
= 0;
12999 pkt
->pkt_cmd_fhdr
.rsvd
= 0;
13001 pkt
->pkt_comp
= fp_ns_intr
;
13002 pkt
->pkt_ulp_private
= (opaque_t
)cmd
;
13003 pkt
->pkt_timeout
= FP_NS_TIMEOUT
;
13006 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)cmd_buf
,
13007 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
13008 cmd_len
, DDI_DEV_AUTOINCR
);
13011 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_transport
;
13013 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| class;
13014 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
13015 cmd
->cmd_flags
= FP_CMD_PLOGI_DONT_CARE
;
13016 cmd
->cmd_retry_count
= fp_retry_count
;
13017 cmd
->cmd_ulp_pkt
= NULL
;
13022 * Name Server request interrupt routine
13025 fp_ns_intr(fc_packet_t
*pkt
)
13028 fc_local_port_t
*port
;
13029 fc_ct_header_t resp_hdr
;
13030 fc_ct_header_t cmd_hdr
;
13031 fctl_ns_req_t
*ns_cmd
;
13033 cmd
= pkt
->pkt_ulp_private
;
13034 port
= cmd
->cmd_port
;
13036 mutex_enter(&port
->fp_mutex
);
13037 port
->fp_out_fpcmds
--;
13038 mutex_exit(&port
->fp_mutex
);
13040 FC_GET_RSP(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&cmd_hdr
,
13041 (uint8_t *)pkt
->pkt_cmd
, sizeof (cmd_hdr
), DDI_DEV_AUTOINCR
);
13042 ns_cmd
= (fctl_ns_req_t
*)
13043 (((fp_cmd_t
*)(pkt
->pkt_ulp_private
))->cmd_private
);
13044 if (!FP_IS_PKT_ERROR(pkt
)) {
13045 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&resp_hdr
,
13046 (uint8_t *)pkt
->pkt_resp
, sizeof (resp_hdr
),
13050 * On x86 architectures, make sure the resp_hdr is big endian.
13051 * This macro is a NOP on sparc architectures mainly because
13052 * we don't want to end up wasting time since the end result
13053 * is going to be the same.
13055 MAKE_BE_32(&resp_hdr
);
13059 * Always copy out the response CT_HDR
13061 bcopy(&resp_hdr
, &ns_cmd
->ns_resp_hdr
,
13062 sizeof (resp_hdr
));
13065 if (resp_hdr
.ct_cmdrsp
== FS_RJT_IU
) {
13066 pkt
->pkt_state
= FC_PKT_FS_RJT
;
13067 pkt
->pkt_reason
= resp_hdr
.ct_reason
;
13068 pkt
->pkt_expln
= resp_hdr
.ct_expln
;
13072 if (FP_IS_PKT_ERROR(pkt
)) {
13074 if (ns_cmd
->ns_flags
& FCTL_NS_VALIDATE_PD
) {
13075 ASSERT(ns_cmd
->ns_pd
!= NULL
);
13077 /* Mark it OLD if not already done */
13078 mutex_enter(&ns_cmd
->ns_pd
->pd_mutex
);
13079 ns_cmd
->ns_pd
->pd_type
= PORT_DEVICE_OLD
;
13080 mutex_exit(&ns_cmd
->ns_pd
->pd_mutex
);
13083 if (ns_cmd
->ns_flags
& FCTL_NS_ASYNC_REQUEST
) {
13084 fctl_free_ns_cmd(ns_cmd
);
13086 (pkt
->pkt_ulp_private
))->cmd_private
= NULL
;
13091 FP_TRACE(FP_NHEAD2(1, 0), "%x NS failure pkt state=%x "
13092 "reason=%x, expln=%x, NSCMD=%04X, NSRSP=%04X",
13093 port
->fp_port_id
.port_id
, pkt
->pkt_state
,
13094 pkt
->pkt_reason
, pkt
->pkt_expln
,
13095 cmd_hdr
.ct_cmdrsp
, resp_hdr
.ct_cmdrsp
);
13097 (void) fp_common_intr(pkt
, 1);
13102 if (resp_hdr
.ct_cmdrsp
!= FS_ACC_IU
) {
13104 fc_local_port_t
*port
;
13107 d_id
= pkt
->pkt_cmd_fhdr
.d_id
;
13108 cmd
= pkt
->pkt_ulp_private
;
13109 port
= cmd
->cmd_port
;
13110 FP_TRACE(FP_NHEAD2(9, 0),
13111 "Bogus NS response received for D_ID=%x", d_id
);
13114 if (cmd_hdr
.ct_cmdrsp
== NS_GA_NXT
) {
13115 fp_gan_handler(pkt
, ns_cmd
);
13119 if (cmd_hdr
.ct_cmdrsp
>= NS_GPN_ID
&&
13120 cmd_hdr
.ct_cmdrsp
<= NS_GID_PT
) {
13122 if ((ns_cmd
->ns_flags
& FCTL_NS_NO_DATA_BUF
) == 0) {
13123 fp_ns_query_handler(pkt
, ns_cmd
);
13129 fp_iodone(pkt
->pkt_ulp_private
);
13134 * Process NS_GAN response
13137 fp_gan_handler(fc_packet_t
*pkt
, fctl_ns_req_t
*ns_cmd
)
13142 fc_local_port_t
*port
;
13143 fc_remote_port_t
*pd
;
13144 ns_req_gan_t gan_req
;
13145 ns_resp_gan_t
*gan_resp
;
13147 ASSERT(ns_cmd
!= NULL
);
13149 cmd
= pkt
->pkt_ulp_private
;
13150 port
= cmd
->cmd_port
;
13152 gan_resp
= (ns_resp_gan_t
*)(pkt
->pkt_resp
+ sizeof (fc_ct_header_t
));
13154 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&d_id
,
13155 (uint8_t *)&gan_resp
->gan_type_id
, sizeof (d_id
), DDI_DEV_AUTOINCR
);
13157 *(uint32_t *)&d_id
= BE_32(*(uint32_t *)&d_id
);
13160 * In this case the priv_lilp_posit field in reality
13161 * is actually represents the relative position on a private loop.
13162 * So zero it while dealing with Port Identifiers.
13164 d_id
.priv_lilp_posit
= 0;
13165 pd
= fctl_get_remote_port_by_did(port
, d_id
.port_id
);
13166 if (ns_cmd
->ns_gan_sid
== d_id
.port_id
) {
13168 * We've come a full circle; time to get out.
13174 if (ns_cmd
->ns_gan_sid
== FCTL_GAN_START_ID
) {
13175 ns_cmd
->ns_gan_sid
= d_id
.port_id
;
13178 mutex_enter(&port
->fp_mutex
);
13179 my_did
= (d_id
.port_id
== port
->fp_port_id
.port_id
) ? 1 : 0;
13180 mutex_exit(&port
->fp_mutex
);
13182 FP_TRACE(FP_NHEAD1(1, 0), "GAN response; port=%p, fp %x pd %x", port
,
13183 port
->fp_port_id
.port_id
, d_id
.port_id
);
13188 FP_TRACE(FP_NHEAD1(1, 0), "GAN response details; "
13189 "port=%p, d_id=%x, type_id=%x, "
13190 "pwwn=%x %x %x %x %x %x %x %x, "
13191 "nwwn=%x %x %x %x %x %x %x %x",
13192 port
, d_id
.port_id
, gan_resp
->gan_type_id
,
13194 gan_resp
->gan_pwwn
.raw_wwn
[0],
13195 gan_resp
->gan_pwwn
.raw_wwn
[1],
13196 gan_resp
->gan_pwwn
.raw_wwn
[2],
13197 gan_resp
->gan_pwwn
.raw_wwn
[3],
13198 gan_resp
->gan_pwwn
.raw_wwn
[4],
13199 gan_resp
->gan_pwwn
.raw_wwn
[5],
13200 gan_resp
->gan_pwwn
.raw_wwn
[6],
13201 gan_resp
->gan_pwwn
.raw_wwn
[7],
13203 gan_resp
->gan_nwwn
.raw_wwn
[0],
13204 gan_resp
->gan_nwwn
.raw_wwn
[1],
13205 gan_resp
->gan_nwwn
.raw_wwn
[2],
13206 gan_resp
->gan_nwwn
.raw_wwn
[3],
13207 gan_resp
->gan_nwwn
.raw_wwn
[4],
13208 gan_resp
->gan_nwwn
.raw_wwn
[5],
13209 gan_resp
->gan_nwwn
.raw_wwn
[6],
13210 gan_resp
->gan_nwwn
.raw_wwn
[7]);
13212 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&nwwn
,
13213 (uint8_t *)&gan_resp
->gan_nwwn
, sizeof (nwwn
),
13216 FC_GET_RSP(port
, pkt
->pkt_resp_acc
, (uint8_t *)&pwwn
,
13217 (uint8_t *)&gan_resp
->gan_pwwn
, sizeof (pwwn
),
13220 if (ns_cmd
->ns_flags
& FCTL_NS_CREATE_DEVICE
&& pd
== NULL
) {
13221 FP_TRACE(FP_NHEAD1(1, 0), "fp %x gan_hander create"
13222 "pd %x", port
->fp_port_id
.port_id
, d_id
.port_id
);
13223 pd
= fctl_create_remote_port(port
, &nwwn
, &pwwn
,
13224 d_id
.port_id
, PD_PLOGI_INITIATOR
, KM_NOSLEEP
);
13227 fp_stuff_device_with_gan(&pkt
->pkt_resp_acc
,
13231 if (ns_cmd
->ns_flags
& FCTL_NS_GET_DEV_COUNT
) {
13232 *((int *)ns_cmd
->ns_data_buf
) += 1;
13235 if (ns_cmd
->ns_flags
& FCTL_NS_FILL_NS_MAP
) {
13236 ASSERT((ns_cmd
->ns_flags
& FCTL_NS_NO_DATA_BUF
) == 0);
13238 if (ns_cmd
->ns_flags
& FCTL_NS_BUF_IS_USERLAND
) {
13239 fc_port_dev_t
*userbuf
;
13241 userbuf
= ((fc_port_dev_t
*)
13242 ns_cmd
->ns_data_buf
) +
13243 ns_cmd
->ns_gan_index
++;
13245 userbuf
->dev_did
= d_id
;
13247 FC_GET_RSP(port
, pkt
->pkt_resp_acc
,
13248 (uint8_t *)userbuf
->dev_type
,
13249 (uint8_t *)gan_resp
->gan_fc4types
,
13250 sizeof (userbuf
->dev_type
),
13253 userbuf
->dev_nwwn
= nwwn
;
13254 userbuf
->dev_pwwn
= pwwn
;
13257 mutex_enter(&pd
->pd_mutex
);
13258 userbuf
->dev_state
= pd
->pd_state
;
13259 userbuf
->dev_hard_addr
=
13261 mutex_exit(&pd
->pd_mutex
);
13263 userbuf
->dev_state
=
13264 PORT_DEVICE_INVALID
;
13266 } else if (ns_cmd
->ns_flags
&
13267 FCTL_NS_BUF_IS_FC_PORTMAP
) {
13270 map
= ((fc_portmap_t
*)
13271 ns_cmd
->ns_data_buf
) +
13272 ns_cmd
->ns_gan_index
++;
13275 * First fill it like any new map
13276 * and update the port device info
13279 fp_fillout_new_nsmap(port
, &pkt
->pkt_resp_acc
,
13280 map
, gan_resp
, d_id
.port_id
);
13282 fctl_copy_portmap(map
, pd
);
13284 map
->map_state
= PORT_DEVICE_INVALID
;
13285 map
->map_type
= PORT_DEVICE_NOCHANGE
;
13290 dst_ptr
= ns_cmd
->ns_data_buf
+
13291 (NS_GAN_RESP_LEN
) * ns_cmd
->ns_gan_index
++;
13293 FC_GET_RSP(port
, pkt
->pkt_resp_acc
,
13294 (uint8_t *)dst_ptr
, (uint8_t *)gan_resp
,
13295 NS_GAN_RESP_LEN
, DDI_DEV_AUTOINCR
);
13298 ns_cmd
->ns_gan_index
++;
13300 if (ns_cmd
->ns_gan_index
>= ns_cmd
->ns_gan_max
) {
13306 gan_req
.pid
= d_id
;
13308 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&gan_req
,
13309 (uint8_t *)(pkt
->pkt_cmd
+ sizeof (fc_ct_header_t
)),
13310 sizeof (gan_req
), DDI_DEV_AUTOINCR
);
13312 if (cmd
->cmd_transport(port
->fp_fca_handle
, pkt
) != FC_SUCCESS
) {
13313 pkt
->pkt_state
= FC_PKT_TRAN_ERROR
;
13316 mutex_enter(&port
->fp_mutex
);
13317 port
->fp_out_fpcmds
++;
13318 mutex_exit(&port
->fp_mutex
);
13324 * Handle NS Query interrupt
13327 fp_ns_query_handler(fc_packet_t
*pkt
, fctl_ns_req_t
*ns_cmd
)
13330 fc_local_port_t
*port
;
13334 cmd
= pkt
->pkt_ulp_private
;
13335 port
= cmd
->cmd_port
;
13337 xfer_len
= ns_cmd
->ns_resp_size
;
13339 FP_TRACE(FP_NHEAD1(1, 0), "NS Query response, cmd_code=%x, xfer_len=%x",
13340 ns_cmd
->ns_cmd_code
, xfer_len
);
13342 if (ns_cmd
->ns_cmd_code
== NS_GPN_ID
) {
13343 src_ptr
= (caddr_t
)pkt
->pkt_resp
+ sizeof (fc_ct_header_t
);
13345 FP_TRACE(FP_NHEAD1(6, 0), "GPN_ID results; %x %x %x %x %x",
13346 src_ptr
[0], src_ptr
[1], src_ptr
[2], src_ptr
[3], src_ptr
[4]);
13349 if (xfer_len
<= ns_cmd
->ns_data_len
) {
13350 src_ptr
= (caddr_t
)pkt
->pkt_resp
+ sizeof (fc_ct_header_t
);
13351 FC_GET_RSP(port
, pkt
->pkt_resp_acc
,
13352 (uint8_t *)ns_cmd
->ns_data_buf
,
13353 (uint8_t *)src_ptr
, xfer_len
, DDI_DEV_AUTOINCR
);
13356 if (ns_cmd
->ns_flags
& FCTL_NS_VALIDATE_PD
) {
13357 ASSERT(ns_cmd
->ns_pd
!= NULL
);
13359 mutex_enter(&ns_cmd
->ns_pd
->pd_mutex
);
13360 if (ns_cmd
->ns_pd
->pd_type
== PORT_DEVICE_OLD
) {
13361 ns_cmd
->ns_pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
13363 mutex_exit(&ns_cmd
->ns_pd
->pd_mutex
);
13366 if (ns_cmd
->ns_flags
& FCTL_NS_ASYNC_REQUEST
) {
13367 fctl_free_ns_cmd(ns_cmd
);
13368 ((fp_cmd_t
*)(pkt
->pkt_ulp_private
))->cmd_private
= NULL
;
13375 * Handle unsolicited ADISC ELS request
13378 fp_handle_unsol_adisc(fc_local_port_t
*port
, fc_unsol_buf_t
*buf
,
13379 fc_remote_port_t
*pd
, job_request_t
*job
)
13384 FP_TRACE(FP_NHEAD1(5, 0), "ADISC; port=%p, D_ID=%x state=%x, pd=%p",
13385 port
, pd
->pd_port_id
.port_id
, pd
->pd_state
, pd
);
13386 mutex_enter(&pd
->pd_mutex
);
13387 if (pd
->pd_state
!= PORT_DEVICE_LOGGED_IN
) {
13388 mutex_exit(&pd
->pd_mutex
);
13389 if (FP_IS_CLASS_1_OR_2(buf
->ub_class
)) {
13390 cmd
= fp_alloc_pkt(port
, sizeof (la_els_rjt_t
),
13393 fp_els_rjt_init(port
, cmd
, buf
,
13394 FC_ACTION_NON_RETRYABLE
,
13395 FC_REASON_INVALID_LINK_CTRL
, job
);
13397 if (fp_sendcmd(port
, cmd
,
13398 port
->fp_fca_handle
) != FC_SUCCESS
) {
13404 mutex_exit(&pd
->pd_mutex
);
13406 * Yes, yes, we don't have a hard address. But we
13407 * we should still respond. Huh ? Visit 21.19.2
13408 * of FC-PH-2 which essentially says that if an
13409 * NL_Port doesn't have a hard address, or if a port
13410 * does not have FC-AL capability, it shall report
13411 * zeroes in this field.
13413 cmd
= fp_alloc_pkt(port
, sizeof (la_els_adisc_t
),
13418 fp_adisc_acc_init(port
, cmd
, buf
, job
);
13419 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
13420 if (rval
!= FC_SUCCESS
) {
13428 * Initialize ADISC response.
13431 fp_adisc_acc_init(fc_local_port_t
*port
, fp_cmd_t
*cmd
, fc_unsol_buf_t
*buf
,
13432 job_request_t
*job
)
13435 la_els_adisc_t payload
;
13437 cmd
->cmd_pkt
.pkt_tran_flags
= buf
->ub_class
;
13438 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_OUTBOUND
;
13439 cmd
->cmd_flags
= FP_CMD_CFLAG_UNDEFINED
;
13440 cmd
->cmd_retry_count
= 1;
13441 cmd
->cmd_ulp_pkt
= NULL
;
13443 cmd
->cmd_transport
= port
->fp_fca_tran
->fca_els_send
;
13444 cmd
->cmd_job
= job
;
13446 pkt
= &cmd
->cmd_pkt
;
13448 fp_unsol_resp_init(pkt
, buf
, R_CTL_ELS_RSP
, FC_TYPE_EXTENDED_LS
);
13450 payload
.ls_code
.ls_code
= LA_ELS_ACC
;
13451 payload
.ls_code
.mbz
= 0;
13453 mutex_enter(&port
->fp_mutex
);
13454 payload
.nport_id
= port
->fp_port_id
;
13455 payload
.hard_addr
= port
->fp_hard_addr
;
13456 mutex_exit(&port
->fp_mutex
);
13458 payload
.port_wwn
= port
->fp_service_params
.nport_ww_name
;
13459 payload
.node_wwn
= port
->fp_service_params
.node_ww_name
;
13461 FC_SET_CMD(port
, pkt
->pkt_cmd_acc
, (uint8_t *)&payload
,
13462 (uint8_t *)pkt
->pkt_cmd
, sizeof (payload
), DDI_DEV_AUTOINCR
);
13467 * Hold and Install the requested ULP drivers
13470 fp_load_ulp_modules(dev_info_t
*dip
, fc_local_port_t
*port
)
13480 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
13483 if (ddi_getlongprop(DDI_DEV_T_ANY
, dip
,
13484 DDI_PROP_DONTPASS
, "load-ulp-list",
13485 (caddr_t
)&data_buf
, &data_len
) != DDI_PROP_SUCCESS
) {
13489 len
= strlen(data_buf
);
13490 port
->fp_ulp_nload
= fctl_atoi(data_buf
, 10);
13492 data_ptr
= data_buf
+ len
+ 1;
13493 for (count
= 0; count
< port
->fp_ulp_nload
; count
++) {
13494 len
= strlen(data_ptr
) + 1;
13495 ulp_name
= kmem_zalloc(len
, KM_SLEEP
);
13496 bcopy(data_ptr
, ulp_name
, len
);
13498 ulp_major
= ddi_name_to_major(ulp_name
);
13500 if (ulp_major
!= (major_t
)-1) {
13501 if (modload("drv", ulp_name
) < 0) {
13502 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
,
13503 0, NULL
, "failed to load %s",
13507 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
13508 "%s isn't a valid driver", ulp_name
);
13511 kmem_free(ulp_name
, len
);
13512 data_ptr
+= len
; /* Skip to next field */
13516 * Free the memory allocated by DDI
13518 if (data_buf
!= NULL
) {
13519 kmem_free(data_buf
, data_len
);
13525 * Perform LOGO operation
13528 fp_logout(fc_local_port_t
*port
, fc_remote_port_t
*pd
, job_request_t
*job
)
13533 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
13534 ASSERT(!MUTEX_HELD(&pd
->pd_mutex
));
13536 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logo_t
),
13537 FP_PORT_IDENTIFIER_LEN
, KM_SLEEP
, pd
);
13539 mutex_enter(&port
->fp_mutex
);
13540 mutex_enter(&pd
->pd_mutex
);
13542 ASSERT(pd
->pd_state
== PORT_DEVICE_LOGGED_IN
);
13543 ASSERT(pd
->pd_login_count
== 1);
13545 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
13546 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
13547 cmd
->cmd_flags
= 0;
13548 cmd
->cmd_retry_count
= 1;
13549 cmd
->cmd_ulp_pkt
= NULL
;
13551 fp_logo_init(pd
, cmd
, job
);
13553 mutex_exit(&pd
->pd_mutex
);
13554 mutex_exit(&port
->fp_mutex
);
13556 rval
= fp_sendcmd(port
, cmd
, port
->fp_fca_handle
);
13557 if (rval
!= FC_SUCCESS
) {
13566 * Perform Port attach callbacks to registered ULPs
13569 fp_attach_ulps(fc_local_port_t
*port
, fc_attach_cmd_t cmd
)
13571 fp_soft_attach_t
*att
;
13573 att
= kmem_zalloc(sizeof (*att
), KM_SLEEP
);
13574 att
->att_cmd
= cmd
;
13575 att
->att_port
= port
;
13578 * We need to remember whether or not fctl_busy_port
13579 * succeeded so we know whether or not to call
13580 * fctl_idle_port when the task is complete.
13583 if (fctl_busy_port(port
) == 0) {
13584 att
->att_need_pm_idle
= B_TRUE
;
13586 att
->att_need_pm_idle
= B_FALSE
;
13589 (void) taskq_dispatch(port
->fp_taskq
, fp_ulp_port_attach
,
13595 * Forward state change notifications on to interested ULPs.
13596 * Spawns a call to fctl_ulp_statec_cb() in a taskq thread to do all the
13600 fp_ulp_notify(fc_local_port_t
*port
, uint32_t statec
, int sleep
)
13602 fc_port_clist_t
*clist
;
13604 clist
= kmem_zalloc(sizeof (*clist
), sleep
);
13605 if (clist
== NULL
) {
13609 clist
->clist_state
= statec
;
13611 mutex_enter(&port
->fp_mutex
);
13612 clist
->clist_flags
= port
->fp_topology
;
13613 mutex_exit(&port
->fp_mutex
);
13615 clist
->clist_port
= (opaque_t
)port
;
13616 clist
->clist_len
= 0;
13617 clist
->clist_size
= 0;
13618 clist
->clist_map
= NULL
;
13620 (void) taskq_dispatch(port
->fp_taskq
, fctl_ulp_statec_cb
,
13623 return (FC_SUCCESS
);
13628 * Get name server map
13631 fp_ns_getmap(fc_local_port_t
*port
, job_request_t
*job
, fc_portmap_t
**map
,
13632 uint32_t *len
, uint32_t sid
)
13635 fctl_ns_req_t
*ns_cmd
;
13638 * Don't let the allocator do anything for response;
13639 * we have have buffer ready to fillout.
13641 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gan_t
),
13642 sizeof (ns_resp_gan_t
), 0, (FCTL_NS_FILL_NS_MAP
|
13643 FCTL_NS_BUF_IS_FC_PORTMAP
), KM_SLEEP
);
13645 ns_cmd
->ns_data_len
= sizeof (**map
) * (*len
);
13646 ns_cmd
->ns_data_buf
= (caddr_t
)*map
;
13648 ASSERT(ns_cmd
!= NULL
);
13650 ns_cmd
->ns_gan_index
= 0;
13651 ns_cmd
->ns_gan_sid
= sid
;
13652 ns_cmd
->ns_cmd_code
= NS_GA_NXT
;
13653 ns_cmd
->ns_gan_max
= *len
;
13655 ret
= fp_ns_query(port
, ns_cmd
, job
, 1, KM_SLEEP
);
13657 if (ns_cmd
->ns_gan_index
!= *len
) {
13658 *len
= ns_cmd
->ns_gan_index
;
13660 ns_cmd
->ns_data_len
= 0;
13661 ns_cmd
->ns_data_buf
= NULL
;
13662 fctl_free_ns_cmd(ns_cmd
);
13669 * Create a remote port in Fabric topology by using NS services
13671 static fc_remote_port_t
*
13672 fp_create_remote_port_by_ns(fc_local_port_t
*port
, uint32_t d_id
, int sleep
)
13675 job_request_t
*job
;
13676 fctl_ns_req_t
*ns_cmd
;
13677 fc_remote_port_t
*pd
;
13679 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
13681 FP_TRACE(FP_NHEAD1(1, 0), "PD creation begin; port=%p, d_id=%x",
13685 mutex_enter(&port
->fp_mutex
);
13686 ASSERT(FC_IS_TOP_SWITCH(port
->fp_topology
));
13687 mutex_exit(&port
->fp_mutex
);
13690 job
= fctl_alloc_job(JOB_NS_CMD
, 0, NULL
, (opaque_t
)port
, sleep
);
13695 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gan_t
),
13696 sizeof (ns_resp_gan_t
), 0, (FCTL_NS_CREATE_DEVICE
|
13697 FCTL_NS_NO_DATA_BUF
), sleep
);
13698 if (ns_cmd
== NULL
) {
13702 job
->job_result
= FC_SUCCESS
;
13703 ns_cmd
->ns_gan_max
= 1;
13704 ns_cmd
->ns_cmd_code
= NS_GA_NXT
;
13705 ns_cmd
->ns_gan_sid
= FCTL_GAN_START_ID
;
13706 ((ns_req_gan_t
*)(ns_cmd
->ns_cmd_buf
))->pid
.port_id
= d_id
- 1;
13707 ((ns_req_gan_t
*)(ns_cmd
->ns_cmd_buf
))->pid
.priv_lilp_posit
= 0;
13709 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
13710 rval
= fp_ns_query(port
, ns_cmd
, job
, 1, KM_SLEEP
);
13711 fctl_free_ns_cmd(ns_cmd
);
13713 if (rval
!= FC_SUCCESS
|| job
->job_result
!= FC_SUCCESS
) {
13714 fctl_dealloc_job(job
);
13717 fctl_dealloc_job(job
);
13719 pd
= fctl_get_remote_port_by_did(port
, d_id
);
13721 FP_TRACE(FP_NHEAD1(1, 0), "PD creation end; port=%p, d_id=%x, pd=%p",
13729 * Check for the permissions on an ioctl command. If it is required to have an
13730 * EXCLUSIVE open performed, return a FAILURE to just shut the door on it. If
13731 * the ioctl command isn't in one of the list built, shut the door on that too.
13733 * Certain ioctls perform hardware accesses in FCA drivers, and it needs
13734 * to be made sure that users open the port for an exclusive access while
13735 * performing those operations.
13737 * This can prevent a casual user from inflicting damage on the port by
13738 * sending these ioctls from multiple processes/threads (there is no good
13739 * reason why one would need to do that) without actually realizing how
13740 * expensive such commands could turn out to be.
13742 * It is also important to note that, even with an exclusive access,
13743 * multiple threads can share the same file descriptor and fire down
13744 * commands in parallel. To prevent that the driver needs to make sure
13745 * that such commands aren't in progress already. This is taken care of
13746 * in the FP_EXCL_BUSY bit of fp_flag.
13749 fp_check_perms(uchar_t open_flag
, uint16_t ioctl_cmd
)
13751 int ret
= FC_FAILURE
;
13755 count
< sizeof (fp_perm_list
) / sizeof (fp_perm_list
[0]);
13757 if (fp_perm_list
[count
].fp_ioctl_cmd
== ioctl_cmd
) {
13758 if (fp_perm_list
[count
].fp_open_flag
& open_flag
) {
13770 * Bind Port driver's unsolicited, state change callbacks
13773 fp_bind_callbacks(fc_local_port_t
*port
)
13775 fc_fca_bind_info_t bind_info
= {0};
13776 fc_fca_port_info_t
*port_info
;
13777 int rval
= DDI_SUCCESS
;
13779 int node_namelen
, port_namelen
;
13780 char *nname
= NULL
, *pname
= NULL
;
13782 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
13784 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, port
->fp_port_dip
,
13785 DDI_PROP_NOTPROM
| DDI_PROP_DONTPASS
,
13786 "node-name", &nname
) != DDI_PROP_SUCCESS
) {
13787 FP_TRACE(FP_NHEAD1(1, 0),
13788 "fp_bind_callback fail to get node-name");
13791 fc_str_to_wwn(nname
, &(bind_info
.port_nwwn
));
13794 if (ddi_prop_lookup_string(DDI_DEV_T_ANY
, port
->fp_port_dip
,
13795 DDI_PROP_NOTPROM
| DDI_PROP_DONTPASS
,
13796 "port-name", &pname
) != DDI_PROP_SUCCESS
) {
13797 FP_TRACE(FP_NHEAD1(1, 0),
13798 "fp_bind_callback fail to get port-name");
13801 fc_str_to_wwn(pname
, &(bind_info
.port_pwwn
));
13804 if (port
->fp_npiv_type
== FC_NPIV_PORT
) {
13805 bind_info
.port_npiv
= 1;
13809 * fca_bind_port returns the FCA driver's handle for the local
13810 * port instance. If the port number isn't supported it returns NULL.
13811 * It also sets up callback in the FCA for various
13812 * things like state change, ELS etc..
13814 bind_info
.port_statec_cb
= fp_statec_cb
;
13815 bind_info
.port_unsol_cb
= fp_unsol_cb
;
13816 bind_info
.port_num
= port
->fp_port_num
;
13817 bind_info
.port_handle
= (opaque_t
)port
;
13819 port_info
= kmem_zalloc(sizeof (*port_info
), KM_SLEEP
);
13822 * Hold the port driver mutex as the callbacks are bound until the
13823 * service parameters are properly filled in (in order to be able to
13824 * properly respond to unsolicited ELS requests)
13826 mutex_enter(&port
->fp_mutex
);
13828 port
->fp_fca_handle
= port
->fp_fca_tran
->fca_bind_port(
13829 port
->fp_fca_dip
, port_info
, &bind_info
);
13831 if (port
->fp_fca_handle
== NULL
) {
13832 rval
= DDI_FAILURE
;
13837 * Only fcoei will set this bit
13839 if (port_info
->pi_port_state
& FC_STATE_FCA_IS_NODMA
) {
13840 port
->fp_soft_state
|= FP_SOFT_FCA_IS_NODMA
;
13841 port_info
->pi_port_state
&= ~(FC_STATE_FCA_IS_NODMA
);
13844 port
->fp_bind_state
= port
->fp_state
= port_info
->pi_port_state
;
13845 port
->fp_service_params
= port_info
->pi_login_params
;
13846 port
->fp_hard_addr
= port_info
->pi_hard_addr
;
13848 /* Copy from the FCA structure to the FP structure */
13849 port
->fp_hba_port_attrs
= port_info
->pi_attrs
;
13851 if (port_info
->pi_rnid_params
.status
== FC_SUCCESS
) {
13852 port
->fp_rnid_init
= 1;
13853 bcopy(&port_info
->pi_rnid_params
.params
,
13854 &port
->fp_rnid_params
,
13855 sizeof (port
->fp_rnid_params
));
13857 port
->fp_rnid_init
= 0;
13860 node_namelen
= strlen((char *)&port_info
->pi_attrs
.sym_node_name
);
13861 if (node_namelen
) {
13862 bcopy(&port_info
->pi_attrs
.sym_node_name
,
13863 &port
->fp_sym_node_name
,
13865 port
->fp_sym_node_namelen
= node_namelen
;
13867 port_namelen
= strlen((char *)&port_info
->pi_attrs
.sym_port_name
);
13868 if (port_namelen
) {
13869 bcopy(&port_info
->pi_attrs
.sym_port_name
,
13870 &port
->fp_sym_port_name
,
13872 port
->fp_sym_port_namelen
= port_namelen
;
13875 /* zero out the normally unused fields right away */
13876 port
->fp_service_params
.ls_code
.mbz
= 0;
13877 port
->fp_service_params
.ls_code
.ls_code
= 0;
13878 bzero(&port
->fp_service_params
.reserved
,
13879 sizeof (port
->fp_service_params
.reserved
));
13881 class = port_info
->pi_login_params
.class_1
.class_opt
;
13882 port
->fp_cos
|= (class & 0x8000) ? FC_NS_CLASS1
: 0;
13884 class = port_info
->pi_login_params
.class_2
.class_opt
;
13885 port
->fp_cos
|= (class & 0x8000) ? FC_NS_CLASS2
: 0;
13887 class = port_info
->pi_login_params
.class_3
.class_opt
;
13888 port
->fp_cos
|= (class & 0x8000) ? FC_NS_CLASS3
: 0;
13892 ddi_prop_free(nname
);
13895 ddi_prop_free(pname
);
13897 mutex_exit(&port
->fp_mutex
);
13898 kmem_free(port_info
, sizeof (*port_info
));
13905 * Retrieve FCA capabilities
13908 fp_retrieve_caps(fc_local_port_t
*port
)
13912 fc_fcp_dma_t fcp_dma
;
13913 fc_reset_action_t action
;
13914 fc_dma_behavior_t dma_behavior
;
13916 ASSERT(!MUTEX_HELD(&port
->fp_mutex
));
13918 rval
= port
->fp_fca_tran
->fca_get_cap(port
->fp_fca_handle
,
13919 FC_CAP_UNSOL_BUF
, &ub_count
);
13923 case FC_CAP_SETTABLE
:
13924 switch (ub_count
) {
13929 ub_count
= fp_unsol_buf_count
;
13933 /* 1/4th of total buffers is my share */
13935 (ub_count
/ port
->fp_fca_tran
->fca_numports
) >> 2;
13945 mutex_enter(&port
->fp_mutex
);
13946 port
->fp_ub_count
= ub_count
;
13947 mutex_exit(&port
->fp_mutex
);
13949 rval
= port
->fp_fca_tran
->fca_get_cap(port
->fp_fca_handle
,
13950 FC_CAP_POST_RESET_BEHAVIOR
, &action
);
13954 case FC_CAP_SETTABLE
:
13956 case FC_RESET_RETURN_NONE
:
13957 case FC_RESET_RETURN_ALL
:
13958 case FC_RESET_RETURN_OUTSTANDING
:
13962 action
= FC_RESET_RETURN_NONE
;
13968 action
= FC_RESET_RETURN_NONE
;
13971 mutex_enter(&port
->fp_mutex
);
13972 port
->fp_reset_action
= action
;
13973 mutex_exit(&port
->fp_mutex
);
13975 rval
= port
->fp_fca_tran
->fca_get_cap(port
->fp_fca_handle
,
13976 FC_CAP_NOSTREAM_ON_UNALIGN_BUF
, &dma_behavior
);
13980 switch (dma_behavior
) {
13981 case FC_ALLOW_STREAMING
:
13983 case FC_NO_STREAMING
:
13988 * If capability was found and the value
13989 * was incorrect assume the worst
13991 dma_behavior
= FC_NO_STREAMING
;
13998 * If capability was not defined - allow streaming; existing
13999 * FCAs should not be affected.
14001 dma_behavior
= FC_ALLOW_STREAMING
;
14004 mutex_enter(&port
->fp_mutex
);
14005 port
->fp_dma_behavior
= dma_behavior
;
14006 mutex_exit(&port
->fp_mutex
);
14008 rval
= port
->fp_fca_tran
->fca_get_cap(port
->fp_fca_handle
,
14009 FC_CAP_FCP_DMA
, &fcp_dma
);
14011 if (rval
!= FC_CAP_FOUND
|| (fcp_dma
!= FC_NO_DVMA_SPACE
&&
14012 fcp_dma
!= FC_DVMA_SPACE
)) {
14013 fcp_dma
= FC_DVMA_SPACE
;
14016 mutex_enter(&port
->fp_mutex
);
14017 port
->fp_fcp_dma
= fcp_dma
;
14018 mutex_exit(&port
->fp_mutex
);
14023 * Handle Domain, Area changes in the Fabric.
14026 fp_validate_area_domain(fc_local_port_t
*port
, uint32_t id
, uint32_t mask
,
14027 job_request_t
*job
, int sleep
)
14041 fctl_ns_req_t
*ns_cmd
;
14042 fc_portmap_t
*list
;
14046 fc_remote_port_t
*pd
;
14047 fc_remote_port_t
*npd
;
14048 struct pwwn_hash
*head
;
14050 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gid_pn_t
),
14051 sizeof (ns_resp_gid_pn_t
), sizeof (ns_resp_gid_pn_t
),
14053 if (ns_cmd
== NULL
) {
14054 mutex_enter(&port
->fp_mutex
);
14055 if (--port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
14056 --port
->fp_rscn_count
;
14058 mutex_exit(&port
->fp_mutex
);
14062 ns_cmd
->ns_cmd_code
= NS_GID_PN
;
14065 * We need to get a new count of devices from the
14066 * name server, which will also create any new devices
14070 (void) fp_ns_get_devcount(port
, job
, 1, sleep
);
14072 FP_TRACE(FP_NHEAD1(3, 0),
14073 "fp_validate_area_domain: get_devcount found %d devices",
14074 port
->fp_total_devices
);
14076 mutex_enter(&port
->fp_mutex
);
14078 for (count
= index
= 0; index
< pwwn_table_size
; index
++) {
14079 head
= &port
->fp_pwwn_table
[index
];
14080 pd
= head
->pwwn_head
;
14081 while (pd
!= NULL
) {
14082 mutex_enter(&pd
->pd_mutex
);
14083 if (pd
->pd_flags
!= PD_ELS_IN_PROGRESS
) {
14084 if ((pd
->pd_port_id
.port_id
& mask
) == id
&&
14085 pd
->pd_recepient
== PD_PLOGI_INITIATOR
) {
14087 pd
->pd_type
= PORT_DEVICE_OLD
;
14088 pd
->pd_flags
= PD_ELS_MARK
;
14091 mutex_exit(&pd
->pd_mutex
);
14092 pd
= pd
->pd_wwn_hnext
;
14101 * Since port->fp_orphan_count is declared an 'int' it is
14102 * theoretically possible that the count could go negative.
14104 * This would be bad and if that happens we really do want
14108 ASSERT(port
->fp_orphan_count
>= 0);
14110 count
+= port
->fp_orphan_count
;
14113 * We add the port->fp_total_devices value to the count
14114 * in the case where our port is newly attached. This is
14115 * because we haven't done any discovery and we don't have
14116 * any orphans in the port's orphan list. If we do not do
14117 * this addition to count then we won't alloc enough kmem
14118 * to do discovery with.
14122 count
+= port
->fp_total_devices
;
14123 FP_TRACE(FP_NHEAD1(3, 0), "fp_validate_area_domain: "
14124 "0x%x orphans found, using 0x%x",
14125 port
->fp_orphan_count
, count
);
14128 mutex_exit(&port
->fp_mutex
);
14131 * Allocate the change list
14134 list
= kmem_zalloc(sizeof (fc_portmap_t
) * count
, sleep
);
14135 if (list
== NULL
) {
14136 fp_printf(port
, CE_NOTE
, FP_LOG_ONLY
, 0, NULL
,
14137 " Not enough memory to service RSCNs"
14138 " for %d ports, continuing...", count
);
14140 fctl_free_ns_cmd(ns_cmd
);
14142 mutex_enter(&port
->fp_mutex
);
14143 if (--port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
14144 --port
->fp_rscn_count
;
14146 mutex_exit(&port
->fp_mutex
);
14152 * Attempt to validate or invalidate the devices that were
14153 * already in the pwwn hash table.
14156 mutex_enter(&port
->fp_mutex
);
14157 for (listindex
= 0, index
= 0; index
< pwwn_table_size
; index
++) {
14158 head
= &port
->fp_pwwn_table
[index
];
14159 npd
= head
->pwwn_head
;
14161 while ((pd
= npd
) != NULL
) {
14162 npd
= pd
->pd_wwn_hnext
;
14164 mutex_enter(&pd
->pd_mutex
);
14165 if ((pd
->pd_port_id
.port_id
& mask
) == id
&&
14166 pd
->pd_flags
== PD_ELS_MARK
) {
14169 job
->job_result
= FC_SUCCESS
;
14171 ((ns_req_gid_pn_t
*)
14172 (ns_cmd
->ns_cmd_buf
))->pwwn
=
14175 pwwn
= &pd
->pd_port_name
;
14176 d_id
= pd
->pd_port_id
.port_id
;
14178 mutex_exit(&pd
->pd_mutex
);
14179 mutex_exit(&port
->fp_mutex
);
14181 rval
= fp_ns_query(port
, ns_cmd
, job
, 1,
14183 if (rval
!= FC_SUCCESS
) {
14184 fc_wwn_to_str(pwwn
, ww_name
);
14186 FP_TRACE(FP_NHEAD1(3, 0),
14187 "AREA RSCN: PD disappeared; "
14188 "d_id=%x, PWWN=%s", d_id
, ww_name
);
14190 FP_TRACE(FP_NHEAD2(9, 0),
14191 "N_x Port with D_ID=%x,"
14192 " PWWN=%s disappeared from fabric",
14195 fp_fillout_old_map(list
+ listindex
++,
14198 fctl_copy_portmap(list
+ listindex
++,
14201 mutex_enter(&pd
->pd_mutex
);
14202 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
14203 mutex_exit(&pd
->pd_mutex
);
14206 mutex_enter(&port
->fp_mutex
);
14208 mutex_exit(&pd
->pd_mutex
);
14213 mutex_exit(&port
->fp_mutex
);
14215 ASSERT(listindex
== dcnt
);
14217 job
->job_counter
= listindex
;
14218 job_flags
= job
->job_flags
;
14219 job
->job_flags
|= JOB_TYPE_FP_ASYNC
;
14222 * Login (if we were the initiator) or validate devices in the
14226 for (index
= 0; index
< listindex
; index
++) {
14227 pd
= list
[index
].map_pd
;
14229 mutex_enter(&pd
->pd_mutex
);
14230 ASSERT((pd
->pd_port_id
.port_id
& mask
) == id
);
14232 if (pd
->pd_flags
!= PD_ELS_IN_PROGRESS
) {
14233 ASSERT(pd
->pd_type
== PORT_DEVICE_OLD
);
14234 mutex_exit(&pd
->pd_mutex
);
14239 login
= (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) ? 1 : 0;
14240 send
= (pd
->pd_recepient
== PD_PLOGI_INITIATOR
) ? 1 : 0;
14241 d_id
= pd
->pd_port_id
.port_id
;
14242 mutex_exit(&pd
->pd_mutex
);
14244 if ((d_id
& mask
) == id
&& send
) {
14246 FP_TRACE(FP_NHEAD1(6, 0),
14247 "RSCN and PLOGI request;"
14248 " pd=%p, job=%p d_id=%x, index=%d", pd
,
14251 rval
= fp_port_login(port
, d_id
, job
,
14252 FP_CMD_PLOGI_RETAIN
, sleep
, pd
, NULL
);
14253 if (rval
!= FC_SUCCESS
) {
14254 mutex_enter(&pd
->pd_mutex
);
14255 pd
->pd_flags
= PD_IDLE
;
14256 mutex_exit(&pd
->pd_mutex
);
14258 job
->job_result
= rval
;
14261 FP_TRACE(FP_NHEAD1(1, 0),
14262 "PLOGI succeeded:no skip(1) for "
14264 list
[index
].map_flags
|=
14265 PORT_DEVICE_NO_SKIP_DEVICE_DISCOVERY
;
14267 FP_TRACE(FP_NHEAD1(6, 0), "RSCN and NS request;"
14268 " pd=%p, job=%p d_id=%x, index=%d", pd
,
14271 rval
= fp_ns_validate_device(port
, pd
, job
,
14273 if (rval
!= FC_SUCCESS
) {
14276 mutex_enter(&pd
->pd_mutex
);
14277 pd
->pd_flags
= PD_IDLE
;
14278 mutex_exit(&pd
->pd_mutex
);
14281 FP_TRACE(FP_NHEAD1(6, 0),
14282 "RSCN and NO request sent; pd=%p,"
14283 " d_id=%x, index=%d", pd
, d_id
, index
);
14285 mutex_enter(&pd
->pd_mutex
);
14286 pd
->pd_flags
= PD_IDLE
;
14287 mutex_exit(&pd
->pd_mutex
);
14296 job
->job_flags
= job_flags
;
14299 * Orphan list validation.
14301 mutex_enter(&port
->fp_mutex
);
14302 for (prev
= NULL
, orp
= port
->fp_orphan_list
; port
->fp_orphan_count
&&
14303 orp
!= NULL
; orp
= norp
) {
14304 norp
= orp
->orp_next
;
14305 mutex_exit(&port
->fp_mutex
);
14307 job
->job_counter
= 1;
14308 job
->job_result
= FC_SUCCESS
;
14309 ASSERT((job
->job_flags
& JOB_TYPE_FP_ASYNC
) == 0);
14311 ((ns_req_gid_pn_t
*)ns_cmd
->ns_cmd_buf
)->pwwn
= orp
->orp_pwwn
;
14313 ((ns_resp_gid_pn_t
*)ns_cmd
->ns_data_buf
)->pid
.port_id
= 0;
14314 ((ns_resp_gid_pn_t
*)
14315 ns_cmd
->ns_data_buf
)->pid
.priv_lilp_posit
= 0;
14317 rval
= fp_ns_query(port
, ns_cmd
, job
, 1, KM_SLEEP
);
14318 if (rval
== FC_SUCCESS
) {
14319 d_id
= BE_32(*((uint32_t *)ns_cmd
->ns_data_buf
));
14320 pd
= fp_create_remote_port_by_ns(port
, d_id
, KM_SLEEP
);
14322 fc_wwn_to_str(&orp
->orp_pwwn
, ww_name
);
14324 FP_TRACE(FP_NHEAD1(6, 0),
14325 "RSCN and ORPHAN list "
14326 "success; d_id=%x, PWWN=%s", d_id
, ww_name
);
14328 FP_TRACE(FP_NHEAD2(6, 0),
14329 "N_x Port with D_ID=%x, PWWN=%s reappeared"
14330 " in fabric", d_id
, ww_name
);
14332 mutex_enter(&port
->fp_mutex
);
14334 prev
->orp_next
= orp
->orp_next
;
14336 ASSERT(orp
== port
->fp_orphan_list
);
14337 port
->fp_orphan_list
= orp
->orp_next
;
14339 port
->fp_orphan_count
--;
14340 mutex_exit(&port
->fp_mutex
);
14342 kmem_free(orp
, sizeof (*orp
));
14343 fctl_copy_portmap(list
+ listindex
++, pd
);
14350 mutex_enter(&port
->fp_mutex
);
14352 mutex_exit(&port
->fp_mutex
);
14355 * One more pass through the list to delist old devices from
14356 * the d_id and pwwn tables and possibly add to the orphan list.
14359 for (index
= 0; index
< listindex
; index
++) {
14360 pd
= list
[index
].map_pd
;
14361 ASSERT(pd
!= NULL
);
14364 * Update PLOGI results; For NS validation
14365 * of orphan list, it is redundant
14367 * Take care to preserve PORT_DEVICE_NO_SKIP_DEVICE_DISCOVERY if
14368 * appropriate as fctl_copy_portmap() will clear map_flags.
14370 if (list
[index
].map_flags
&
14371 PORT_DEVICE_NO_SKIP_DEVICE_DISCOVERY
) {
14372 fctl_copy_portmap(list
+ index
, pd
);
14373 list
[index
].map_flags
|=
14374 PORT_DEVICE_NO_SKIP_DEVICE_DISCOVERY
;
14376 fctl_copy_portmap(list
+ index
, pd
);
14379 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with Area DOMAIN "
14380 "results; pd=%p, d_id=%x pwwn=%x %x %x %x %x %x %x %x",
14381 pd
, pd
->pd_port_id
.port_id
,
14382 pd
->pd_port_name
.raw_wwn
[0],
14383 pd
->pd_port_name
.raw_wwn
[1],
14384 pd
->pd_port_name
.raw_wwn
[2],
14385 pd
->pd_port_name
.raw_wwn
[3],
14386 pd
->pd_port_name
.raw_wwn
[4],
14387 pd
->pd_port_name
.raw_wwn
[5],
14388 pd
->pd_port_name
.raw_wwn
[6],
14389 pd
->pd_port_name
.raw_wwn
[7]);
14391 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with Area DOMAIN "
14392 "results continued, pd=%p type=%x, flags=%x, state=%x",
14393 pd
, pd
->pd_type
, pd
->pd_flags
, pd
->pd_state
);
14395 mutex_enter(&pd
->pd_mutex
);
14396 if (pd
->pd_type
== PORT_DEVICE_OLD
) {
14399 pd
->pd_flags
= PD_IDLE
;
14400 initiator
= (pd
->pd_recepient
==
14401 PD_PLOGI_INITIATOR
) ? 1 : 0;
14403 mutex_exit(&pd
->pd_mutex
);
14405 mutex_enter(&port
->fp_mutex
);
14406 mutex_enter(&pd
->pd_mutex
);
14408 pd
->pd_state
= PORT_DEVICE_INVALID
;
14409 fctl_delist_did_table(port
, pd
);
14410 fctl_delist_pwwn_table(port
, pd
);
14412 mutex_exit(&pd
->pd_mutex
);
14413 mutex_exit(&port
->fp_mutex
);
14416 (void) fctl_add_orphan(port
, pd
, sleep
);
14418 list
[index
].map_pd
= pd
;
14420 ASSERT(pd
->pd_flags
== PD_IDLE
);
14421 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
14423 * Reset LOGO tolerance to zero
14425 fctl_tc_reset(&pd
->pd_logo_tc
);
14427 mutex_exit(&pd
->pd_mutex
);
14432 fctl_free_ns_cmd(ns_cmd
);
14435 (void) fp_ulp_devc_cb(port
, list
, listindex
, count
,
14438 kmem_free(list
, sizeof (*list
) * count
);
14440 mutex_enter(&port
->fp_mutex
);
14441 if (--port
->fp_rscn_count
== FC_INVALID_RSCN_COUNT
) {
14442 --port
->fp_rscn_count
;
14444 mutex_exit(&port
->fp_mutex
);
14450 * Work hard to make sense out of an RSCN page.
14453 fp_validate_rscn_page(fc_local_port_t
*port
, fc_affected_id_t
*page
,
14454 job_request_t
*job
, fctl_ns_req_t
*ns_cmd
, fc_portmap_t
*listptr
,
14455 int *listindex
, int sleep
)
14460 fc_remote_port_t
*pwwn_pd
;
14461 fc_remote_port_t
*did_pd
;
14463 did_pd
= fctl_get_remote_port_by_did(port
, page
->aff_d_id
);
14465 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID page; "
14466 "port=%p, d_id=%x, pd=%p, rscn_count:0x%x", port
, page
->aff_d_id
,
14467 did_pd
, (uint32_t)(uintptr_t)job
->job_cb_arg
);
14469 if (did_pd
!= NULL
) {
14470 mutex_enter(&did_pd
->pd_mutex
);
14471 if (did_pd
->pd_flags
!= PD_IDLE
) {
14472 mutex_exit(&did_pd
->pd_mutex
);
14473 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID page: "
14474 "PD is BUSY; port=%p, d_id=%x, pd=%p",
14475 port
, page
->aff_d_id
, did_pd
);
14478 did_pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
14479 mutex_exit(&did_pd
->pd_mutex
);
14482 job
->job_counter
= 1;
14484 pwwn
= &((ns_resp_gpn_id_t
*)ns_cmd
->ns_data_buf
)->pwwn
;
14486 ((ns_req_gpn_id_t
*)ns_cmd
->ns_cmd_buf
)->pid
.port_id
= page
->aff_d_id
;
14487 ((ns_req_gpn_id_t
*)ns_cmd
->ns_cmd_buf
)->pid
.priv_lilp_posit
= 0;
14489 bzero(ns_cmd
->ns_data_buf
, sizeof (la_wwn_t
));
14490 rval
= fp_ns_query(port
, ns_cmd
, job
, 1, sleep
);
14492 FP_TRACE(FP_NHEAD1(1, 0), "NS Query Response for D_ID page; rev=%x,"
14493 " in_id=%x, cmdrsp=%x, reason=%x, expln=%x",
14494 ns_cmd
->ns_resp_hdr
.ct_rev
, ns_cmd
->ns_resp_hdr
.ct_inid
,
14495 ns_cmd
->ns_resp_hdr
.ct_cmdrsp
, ns_cmd
->ns_resp_hdr
.ct_reason
,
14496 ns_cmd
->ns_resp_hdr
.ct_expln
);
14498 job
->job_counter
= 1;
14500 if (rval
!= FC_SUCCESS
|| fctl_is_wwn_zero(pwwn
) == FC_SUCCESS
) {
14502 * What this means is that the D_ID
14503 * disappeared from the Fabric.
14505 if (did_pd
== NULL
) {
14506 FP_TRACE(FP_NHEAD1(1, 0), "RSCN with D_ID page;"
14507 " NULL PD disappeared, rval=%x", rval
);
14511 fc_wwn_to_str(&did_pd
->pd_port_name
, ww_name
);
14513 (listptr
+ *listindex
)->map_rscn_info
.ulp_rscn_count
=
14514 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14516 fp_fillout_old_map(listptr
+ (*listindex
)++, did_pd
, 0);
14518 FP_TRACE(FP_NHEAD1(3, 0), "RSCN: PD disappeared; "
14519 "d_id=%x, PWWN=%s", page
->aff_d_id
, ww_name
);
14521 FP_TRACE(FP_NHEAD2(9, 0),
14522 "GPN_ID for D_ID=%x failed", page
->aff_d_id
);
14524 FP_TRACE(FP_NHEAD2(9, 0),
14525 "N_x Port with D_ID=%x, PWWN=%s disappeared from"
14526 " fabric", page
->aff_d_id
, ww_name
);
14528 mutex_enter(&did_pd
->pd_mutex
);
14529 did_pd
->pd_flags
= PD_IDLE
;
14530 mutex_exit(&did_pd
->pd_mutex
);
14532 FP_TRACE(FP_NHEAD1(3, 0), "RSCN with D_ID (%x) page; "
14533 "PD disappeared, pd=%p", page
->aff_d_id
, did_pd
);
14538 pwwn_pd
= fctl_get_remote_port_by_pwwn(port
, pwwn
);
14540 if (did_pd
!= NULL
&& pwwn_pd
!= NULL
&& did_pd
== pwwn_pd
) {
14542 * There is no change. Do PLOGI again and add it to
14543 * ULP portmap baggage and return. Note: When RSCNs
14544 * arrive with per page states, the need for PLOGI
14545 * can be determined correctly.
14547 mutex_enter(&pwwn_pd
->pd_mutex
);
14548 pwwn_pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
14549 mutex_exit(&pwwn_pd
->pd_mutex
);
14551 (listptr
+ *listindex
)->map_rscn_info
.ulp_rscn_count
=
14552 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14554 fctl_copy_portmap(listptr
+ (*listindex
)++, pwwn_pd
);
14556 mutex_enter(&pwwn_pd
->pd_mutex
);
14557 if ((pwwn_pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) ||
14558 (pwwn_pd
->pd_aux_flags
& PD_LOGGED_OUT
)) {
14559 fc_wwn_to_str(&pwwn_pd
->pd_port_name
, ww_name
);
14560 mutex_exit(&pwwn_pd
->pd_mutex
);
14562 rval
= fp_port_login(port
, page
->aff_d_id
, job
,
14563 FP_CMD_PLOGI_RETAIN
, sleep
, pwwn_pd
, NULL
);
14564 if (rval
== FC_SUCCESS
) {
14566 rval
= job
->job_result
;
14569 * Reset LOGO tolerance to zero
14570 * Also we are the PLOGI initiator now.
14572 mutex_enter(&pwwn_pd
->pd_mutex
);
14573 fctl_tc_reset(&pwwn_pd
->pd_logo_tc
);
14574 pwwn_pd
->pd_recepient
= PD_PLOGI_INITIATOR
;
14575 mutex_exit(&pwwn_pd
->pd_mutex
);
14578 if (rval
== FC_SUCCESS
) {
14579 struct fc_portmap
*map
=
14580 listptr
+ *listindex
- 1;
14582 FP_TRACE(FP_NHEAD1(1, 0),
14583 "PLOGI succeeded: no skip(2)"
14584 " for D_ID %x", page
->aff_d_id
);
14586 PORT_DEVICE_NO_SKIP_DEVICE_DISCOVERY
;
14588 FP_TRACE(FP_NHEAD2(9, rval
),
14589 "PLOGI to D_ID=%x failed", page
->aff_d_id
);
14591 FP_TRACE(FP_NHEAD2(9, 0),
14592 "N_x Port with D_ID=%x, PWWN=%s"
14593 " disappeared from fabric",
14594 page
->aff_d_id
, ww_name
);
14596 fp_fillout_old_map(listptr
+
14597 *listindex
- 1, pwwn_pd
, 0);
14600 mutex_exit(&pwwn_pd
->pd_mutex
);
14603 mutex_enter(&did_pd
->pd_mutex
);
14604 did_pd
->pd_flags
= PD_IDLE
;
14605 mutex_exit(&did_pd
->pd_mutex
);
14607 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID (0x%x) page; "
14608 "Case ONE, rval=%x, result=%x pd=%p", page
->aff_d_id
, rval
,
14609 job
->job_result
, pwwn_pd
);
14614 if (did_pd
== NULL
&& pwwn_pd
== NULL
) {
14616 fc_orphan_t
*orp
= NULL
;
14617 fc_orphan_t
*norp
= NULL
;
14618 fc_orphan_t
*prev
= NULL
;
14621 * Hunt down the orphan list before giving up.
14624 mutex_enter(&port
->fp_mutex
);
14625 if (port
->fp_orphan_count
) {
14627 for (orp
= port
->fp_orphan_list
; orp
; orp
= norp
) {
14628 norp
= orp
->orp_next
;
14630 if (fctl_wwn_cmp(&orp
->orp_pwwn
, pwwn
) != 0) {
14636 prev
->orp_next
= orp
->orp_next
;
14639 port
->fp_orphan_list
);
14640 port
->fp_orphan_list
=
14643 port
->fp_orphan_count
--;
14648 mutex_exit(&port
->fp_mutex
);
14649 pwwn_pd
= fp_create_remote_port_by_ns(port
,
14650 page
->aff_d_id
, sleep
);
14652 if (pwwn_pd
!= NULL
) {
14655 fc_wwn_to_str(&orp
->orp_pwwn
,
14658 FP_TRACE(FP_NHEAD2(9, 0),
14659 "N_x Port with D_ID=%x,"
14660 " PWWN=%s reappeared in fabric",
14661 page
->aff_d_id
, ww_name
);
14663 kmem_free(orp
, sizeof (*orp
));
14666 (listptr
+ *listindex
)->
14667 map_rscn_info
.ulp_rscn_count
=
14668 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14670 fctl_copy_portmap(listptr
+
14671 (*listindex
)++, pwwn_pd
);
14674 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID (0x%x) page; "
14675 "Case TWO", page
->aff_d_id
);
14680 if (pwwn_pd
!= NULL
&& did_pd
== NULL
) {
14682 uint32_t d_id
= page
->aff_d_id
;
14685 * What this means is there is a new D_ID for this
14686 * Port WWN. Take out the port device off D_ID
14687 * list and put it back with a new D_ID. Perform
14688 * PLOGI if already logged in.
14690 mutex_enter(&port
->fp_mutex
);
14691 mutex_enter(&pwwn_pd
->pd_mutex
);
14693 old_d_id
= pwwn_pd
->pd_port_id
.port_id
;
14695 fctl_delist_did_table(port
, pwwn_pd
);
14697 (listptr
+ *listindex
)->map_rscn_info
.ulp_rscn_count
=
14698 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14700 fp_fillout_changed_map(listptr
+ (*listindex
)++, pwwn_pd
,
14702 fctl_enlist_did_table(port
, pwwn_pd
);
14704 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID page;"
14705 " Case THREE, pd=%p,"
14706 " state=%x", pwwn_pd
, pwwn_pd
->pd_state
);
14708 if ((pwwn_pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) ||
14709 (pwwn_pd
->pd_aux_flags
& PD_LOGGED_OUT
)) {
14710 fc_wwn_to_str(&pwwn_pd
->pd_port_name
, ww_name
);
14712 mutex_exit(&pwwn_pd
->pd_mutex
);
14713 mutex_exit(&port
->fp_mutex
);
14715 FP_TRACE(FP_NHEAD2(9, 0),
14716 "N_x Port with D_ID=%x, PWWN=%s has a new"
14717 " D_ID=%x now", old_d_id
, ww_name
, d_id
);
14719 rval
= fp_port_login(port
, page
->aff_d_id
, job
,
14720 FP_CMD_PLOGI_RETAIN
, sleep
, pwwn_pd
, NULL
);
14721 if (rval
== FC_SUCCESS
) {
14723 rval
= job
->job_result
;
14726 if (rval
!= FC_SUCCESS
) {
14727 fp_fillout_old_map(listptr
+
14728 *listindex
- 1, pwwn_pd
, 0);
14731 mutex_exit(&pwwn_pd
->pd_mutex
);
14732 mutex_exit(&port
->fp_mutex
);
14738 if (pwwn_pd
== NULL
&& did_pd
!= NULL
) {
14741 char old_ww_name
[17];
14743 mutex_enter(&did_pd
->pd_mutex
);
14744 fc_wwn_to_str(&did_pd
->pd_port_name
, old_ww_name
);
14745 mutex_exit(&did_pd
->pd_mutex
);
14747 fc_wwn_to_str(pwwn
, ww_name
);
14749 (listptr
+ *listindex
)->map_rscn_info
.ulp_rscn_count
=
14750 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14753 * What this means is that there is a new Port WWN for
14754 * this D_ID; Mark the Port device as old and provide
14755 * the new PWWN and D_ID combination as new.
14757 fp_fillout_old_map(listptr
+ (*listindex
)++, did_pd
, 0);
14759 FP_TRACE(FP_NHEAD2(9, 0),
14760 "N_x Port with D_ID=%x, PWWN=%s has a new PWWN=%s now",
14761 page
->aff_d_id
, old_ww_name
, ww_name
);
14763 (listptr
+ *listindex
)->map_rscn_info
.ulp_rscn_count
=
14764 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14766 ptr
= listptr
+ (*listindex
)++;
14768 job
->job_counter
= 1;
14770 if (fp_ns_getmap(port
, job
, &ptr
, &len
,
14771 page
->aff_d_id
- 1) != FC_SUCCESS
) {
14775 mutex_enter(&did_pd
->pd_mutex
);
14776 did_pd
->pd_flags
= PD_IDLE
;
14777 mutex_exit(&did_pd
->pd_mutex
);
14783 * A weird case of Port WWN and D_ID existence but not matching up
14784 * between them. Trust your instincts - Take the port device handle
14785 * off Port WWN list, fix it with new Port WWN and put it back, In
14786 * the mean time mark the port device corresponding to the old port
14789 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID page; Case WEIRD, pwwn_pd=%p,"
14790 " did_pd=%p", pwwn_pd
, did_pd
);
14792 mutex_enter(&port
->fp_mutex
);
14793 mutex_enter(&pwwn_pd
->pd_mutex
);
14795 pwwn_pd
->pd_type
= PORT_DEVICE_OLD
;
14796 pwwn_pd
->pd_state
= PORT_DEVICE_INVALID
;
14797 fctl_delist_did_table(port
, pwwn_pd
);
14798 fctl_delist_pwwn_table(port
, pwwn_pd
);
14800 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID page; case WEIRD continued,"
14801 " pwwn-d_id=%x pwwn-wwn=%x %x %x %x %x %x %x %x",
14802 pwwn_pd
->pd_port_id
.port_id
,
14804 pwwn_pd
->pd_port_name
.raw_wwn
[0],
14805 pwwn_pd
->pd_port_name
.raw_wwn
[1],
14806 pwwn_pd
->pd_port_name
.raw_wwn
[2],
14807 pwwn_pd
->pd_port_name
.raw_wwn
[3],
14808 pwwn_pd
->pd_port_name
.raw_wwn
[4],
14809 pwwn_pd
->pd_port_name
.raw_wwn
[5],
14810 pwwn_pd
->pd_port_name
.raw_wwn
[6],
14811 pwwn_pd
->pd_port_name
.raw_wwn
[7]);
14813 mutex_exit(&pwwn_pd
->pd_mutex
);
14814 mutex_exit(&port
->fp_mutex
);
14816 (listptr
+ *listindex
)->map_rscn_info
.ulp_rscn_count
=
14817 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14819 fctl_copy_portmap(listptr
+ (*listindex
)++, pwwn_pd
);
14821 mutex_enter(&port
->fp_mutex
);
14822 mutex_enter(&did_pd
->pd_mutex
);
14824 fctl_delist_pwwn_table(port
, did_pd
);
14826 (listptr
+ *listindex
)->map_rscn_info
.ulp_rscn_count
=
14827 (uint32_t)(uintptr_t)job
->job_cb_arg
;
14829 fp_fillout_changed_map(listptr
+ (*listindex
)++, did_pd
, NULL
, pwwn
);
14830 fctl_enlist_pwwn_table(port
, did_pd
);
14832 FP_TRACE(FP_NHEAD1(6, 0), "RSCN with D_ID page; case WEIRD continued,"
14833 " d_id=%x, state=%x, did-wwn=%x %x %x %x %x %x %x %x",
14834 did_pd
->pd_port_id
.port_id
, did_pd
->pd_state
,
14836 did_pd
->pd_port_name
.raw_wwn
[0],
14837 did_pd
->pd_port_name
.raw_wwn
[1],
14838 did_pd
->pd_port_name
.raw_wwn
[2],
14839 did_pd
->pd_port_name
.raw_wwn
[3],
14840 did_pd
->pd_port_name
.raw_wwn
[4],
14841 did_pd
->pd_port_name
.raw_wwn
[5],
14842 did_pd
->pd_port_name
.raw_wwn
[6],
14843 did_pd
->pd_port_name
.raw_wwn
[7]);
14845 if ((did_pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) ||
14846 (did_pd
->pd_aux_flags
& PD_LOGGED_OUT
)) {
14847 mutex_exit(&did_pd
->pd_mutex
);
14848 mutex_exit(&port
->fp_mutex
);
14850 rval
= fp_port_login(port
, page
->aff_d_id
, job
,
14851 FP_CMD_PLOGI_RETAIN
, sleep
, did_pd
, NULL
);
14852 if (rval
== FC_SUCCESS
) {
14854 if (job
->job_result
!= FC_SUCCESS
) {
14855 fp_fillout_old_map(listptr
+
14856 *listindex
- 1, did_pd
, 0);
14859 fp_fillout_old_map(listptr
+ *listindex
- 1, did_pd
, 0);
14862 mutex_exit(&did_pd
->pd_mutex
);
14863 mutex_exit(&port
->fp_mutex
);
14866 mutex_enter(&did_pd
->pd_mutex
);
14867 did_pd
->pd_flags
= PD_IDLE
;
14868 mutex_exit(&did_pd
->pd_mutex
);
14873 * Check with NS for the presence of this port WWN
14876 fp_ns_validate_device(fc_local_port_t
*port
, fc_remote_port_t
*pd
,
14877 job_request_t
*job
, int polled
, int sleep
)
14881 fctl_ns_req_t
*ns_cmd
;
14883 flags
= FCTL_NS_VALIDATE_PD
| ((polled
) ? 0: FCTL_NS_ASYNC_REQUEST
);
14884 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gid_pn_t
),
14885 sizeof (ns_resp_gid_pn_t
), sizeof (ns_resp_gid_pn_t
),
14887 if (ns_cmd
== NULL
) {
14891 mutex_enter(&pd
->pd_mutex
);
14892 pwwn
= pd
->pd_port_name
;
14893 mutex_exit(&pd
->pd_mutex
);
14895 ns_cmd
->ns_cmd_code
= NS_GID_PN
;
14896 ns_cmd
->ns_pd
= pd
;
14897 ((ns_req_gid_pn_t
*)ns_cmd
->ns_cmd_buf
)->pwwn
= pwwn
;
14898 ((ns_resp_gid_pn_t
*)ns_cmd
->ns_data_buf
)->pid
.port_id
= 0;
14899 ((ns_resp_gid_pn_t
*)ns_cmd
->ns_data_buf
)->pid
.priv_lilp_posit
= 0;
14901 return (fp_ns_query(port
, ns_cmd
, job
, polled
, sleep
));
14906 * Sanity check the LILP map returned by FCA
14909 fp_validate_lilp_map(fc_lilpmap_t
*lilp_map
)
14913 if (lilp_map
->lilp_length
== 0) {
14914 return (FC_FAILURE
);
14917 for (count
= 0; count
< lilp_map
->lilp_length
; count
++) {
14918 if (fp_is_valid_alpa(lilp_map
->lilp_alpalist
[count
]) !=
14920 return (FC_FAILURE
);
14924 return (FC_SUCCESS
);
14929 * Sanity check if the AL_PA is a valid address
14932 fp_is_valid_alpa(uchar_t al_pa
)
14936 for (count
= 0; count
< sizeof (fp_valid_alpas
); count
++) {
14937 if (al_pa
== fp_valid_alpas
[count
] || al_pa
== 0) {
14938 return (FC_SUCCESS
);
14942 return (FC_FAILURE
);
14947 * Post unsolicited callbacks to ULPs
14950 fp_ulp_unsol_cb(void *arg
)
14952 fp_unsol_spec_t
*ub_spec
= (fp_unsol_spec_t
*)arg
;
14954 fctl_ulp_unsol_cb(ub_spec
->port
, ub_spec
->buf
,
14955 ub_spec
->buf
->ub_frame
.type
);
14956 kmem_free(ub_spec
, sizeof (*ub_spec
));
14961 * Perform message reporting in a consistent manner. Unless there is
14962 * a strong reason NOT to use this function (which is very very rare)
14963 * all message reporting should go through this.
14966 fp_printf(fc_local_port_t
*port
, int level
, fp_mesg_dest_t dest
, int fc_errno
,
14967 fc_packet_t
*pkt
, const char *fmt
, ...)
14974 if ((port
->fp_verbose
& FP_WARNING_MESSAGES
) == 0) {
14980 if ((port
->fp_verbose
& FP_FATAL_MESSAGES
) == 0) {
14986 buf
= kmem_zalloc(256, KM_NOSLEEP
);
14991 (void) sprintf(buf
, "fp(%d): ", port
->fp_instance
);
14994 (void) vsprintf(buf
+ strlen(buf
), fmt
, ap
);
15000 (void) fc_ulp_error(fc_errno
, &errmsg
);
15001 (void) sprintf(buf
+ strlen(buf
), " FC Error=%s", errmsg
);
15004 caddr_t state
, reason
, action
, expln
;
15006 (void) fc_ulp_pkt_error(pkt
, &state
, &reason
,
15009 (void) sprintf(buf
+ strlen(buf
),
15010 " state=%s, reason=%s", state
, reason
);
15012 if (pkt
->pkt_resp_resid
) {
15013 (void) sprintf(buf
+ strlen(buf
),
15014 " resp resid=%x\n", pkt
->pkt_resp_resid
);
15020 case FP_CONSOLE_ONLY
:
15021 cmn_err(level
, "^%s", buf
);
15025 cmn_err(level
, "!%s", buf
);
15029 cmn_err(level
, "%s", buf
);
15033 kmem_free(buf
, 256);
15037 fp_fcio_login(fc_local_port_t
*port
, fcio_t
*fcio
, job_request_t
*job
)
15042 fc_remote_port_t
*pd
= NULL
;
15043 fc_remote_port_t
*held_pd
= NULL
;
15044 fctl_ns_req_t
*ns_cmd
;
15045 fc_portmap_t
*changelist
;
15047 bcopy(fcio
->fcio_ibuf
, &pwwn
, sizeof (pwwn
));
15049 mutex_enter(&port
->fp_mutex
);
15050 if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
15051 mutex_exit(&port
->fp_mutex
);
15052 job
->job_counter
= 1;
15054 job
->job_result
= FC_SUCCESS
;
15056 ns_cmd
= fctl_alloc_ns_cmd(sizeof (ns_req_gid_pn_t
),
15057 sizeof (ns_resp_gid_pn_t
), sizeof (ns_resp_gid_pn_t
),
15058 FCTL_NS_BUF_IS_USERLAND
, KM_SLEEP
);
15060 ASSERT(ns_cmd
!= NULL
);
15062 ns_cmd
->ns_cmd_code
= NS_GID_PN
;
15063 ((ns_req_gid_pn_t
*)(ns_cmd
->ns_cmd_buf
))->pwwn
= pwwn
;
15065 ret
= fp_ns_query(port
, ns_cmd
, job
, 1, KM_SLEEP
);
15067 if (ret
!= FC_SUCCESS
|| job
->job_result
!= FC_SUCCESS
) {
15068 if (ret
!= FC_SUCCESS
) {
15069 fcio
->fcio_errno
= ret
;
15071 fcio
->fcio_errno
= job
->job_result
;
15073 fctl_free_ns_cmd(ns_cmd
);
15076 d_id
= BE_32(*((uint32_t *)ns_cmd
->ns_data_buf
));
15077 fctl_free_ns_cmd(ns_cmd
);
15079 mutex_exit(&port
->fp_mutex
);
15081 held_pd
= fctl_hold_remote_port_by_pwwn(port
, &pwwn
);
15082 if (held_pd
== NULL
) {
15083 fcio
->fcio_errno
= FC_BADWWN
;
15088 mutex_enter(&pd
->pd_mutex
);
15089 d_id
= pd
->pd_port_id
.port_id
;
15090 mutex_exit(&pd
->pd_mutex
);
15093 job
->job_counter
= 1;
15095 pd
= fctl_get_remote_port_by_did(port
, d_id
);
15098 mutex_enter(&pd
->pd_mutex
);
15099 if (pd
->pd_state
== PORT_DEVICE_LOGGED_IN
) {
15100 pd
->pd_login_count
++;
15101 mutex_exit(&pd
->pd_mutex
);
15103 fcio
->fcio_errno
= FC_SUCCESS
;
15105 fctl_release_remote_port(held_pd
);
15110 mutex_exit(&pd
->pd_mutex
);
15112 mutex_enter(&port
->fp_mutex
);
15113 if (FC_IS_TOP_SWITCH(port
->fp_topology
)) {
15114 mutex_exit(&port
->fp_mutex
);
15115 pd
= fp_create_remote_port_by_ns(port
, d_id
, KM_SLEEP
);
15117 fcio
->fcio_errno
= FC_FAILURE
;
15119 fctl_release_remote_port(held_pd
);
15124 mutex_exit(&port
->fp_mutex
);
15128 job
->job_flags
&= ~JOB_TYPE_FP_ASYNC
;
15129 job
->job_counter
= 1;
15131 ret
= fp_port_login(port
, d_id
, job
, FP_CMD_PLOGI_RETAIN
,
15132 KM_SLEEP
, pd
, NULL
);
15134 if (ret
!= FC_SUCCESS
) {
15135 fcio
->fcio_errno
= ret
;
15137 fctl_release_remote_port(held_pd
);
15143 fcio
->fcio_errno
= job
->job_result
;
15146 fctl_release_remote_port(held_pd
);
15149 if (job
->job_result
!= FC_SUCCESS
) {
15153 pd
= fctl_hold_remote_port_by_pwwn(port
, &pwwn
);
15155 fcio
->fcio_errno
= FC_BADDEV
;
15159 changelist
= kmem_zalloc(sizeof (*changelist
), KM_SLEEP
);
15161 fctl_copy_portmap(changelist
, pd
);
15162 changelist
->map_type
= PORT_DEVICE_USER_LOGIN
;
15164 (void) fp_ulp_devc_cb(port
, changelist
, 1, 1, KM_SLEEP
, 1);
15166 mutex_enter(&pd
->pd_mutex
);
15167 pd
->pd_type
= PORT_DEVICE_NOCHANGE
;
15168 mutex_exit(&pd
->pd_mutex
);
15170 fctl_release_remote_port(pd
);
15177 fp_fcio_logout(fc_local_port_t
*port
, fcio_t
*fcio
, job_request_t
*job
)
15181 fc_portmap_t
*changelist
;
15182 fc_remote_port_t
*pd
;
15184 bcopy(fcio
->fcio_ibuf
, &pwwn
, sizeof (pwwn
));
15186 pd
= fctl_hold_remote_port_by_pwwn(port
, &pwwn
);
15188 fcio
->fcio_errno
= FC_BADWWN
;
15192 mutex_enter(&pd
->pd_mutex
);
15193 if (pd
->pd_state
!= PORT_DEVICE_LOGGED_IN
) {
15194 fcio
->fcio_errno
= FC_LOGINREQ
;
15195 mutex_exit(&pd
->pd_mutex
);
15197 fctl_release_remote_port(pd
);
15202 ASSERT(pd
->pd_login_count
>= 1);
15204 if (pd
->pd_flags
== PD_ELS_IN_PROGRESS
) {
15205 fcio
->fcio_errno
= FC_FAILURE
;
15206 mutex_exit(&pd
->pd_mutex
);
15208 fctl_release_remote_port(pd
);
15213 if (pd
->pd_login_count
> 1) {
15214 pd
->pd_login_count
--;
15215 fcio
->fcio_errno
= FC_SUCCESS
;
15216 mutex_exit(&pd
->pd_mutex
);
15218 changelist
= kmem_zalloc(sizeof (*changelist
), KM_SLEEP
);
15220 fctl_copy_portmap(changelist
, pd
);
15221 changelist
->map_type
= PORT_DEVICE_USER_LOGOUT
;
15223 fctl_release_remote_port(pd
);
15225 (void) fp_ulp_devc_cb(port
, changelist
, 1, 1, KM_SLEEP
, 1);
15230 pd
->pd_flags
= PD_ELS_IN_PROGRESS
;
15231 mutex_exit(&pd
->pd_mutex
);
15233 job
->job_counter
= 1;
15235 cmd
= fp_alloc_pkt(port
, sizeof (la_els_logo_t
),
15236 FP_PORT_IDENTIFIER_LEN
, KM_SLEEP
, pd
);
15238 fcio
->fcio_errno
= FC_NOMEM
;
15239 fctl_release_remote_port(pd
);
15241 mutex_enter(&pd
->pd_mutex
);
15242 pd
->pd_flags
= PD_IDLE
;
15243 mutex_exit(&pd
->pd_mutex
);
15248 mutex_enter(&port
->fp_mutex
);
15249 mutex_enter(&pd
->pd_mutex
);
15251 cmd
->cmd_pkt
.pkt_tran_flags
= FC_TRAN_INTR
| pd
->pd_login_class
;
15252 cmd
->cmd_pkt
.pkt_tran_type
= FC_PKT_EXCHANGE
;
15253 cmd
->cmd_flags
= FP_CMD_PLOGI_DONT_CARE
;
15254 cmd
->cmd_retry_count
= 1;
15255 cmd
->cmd_ulp_pkt
= NULL
;
15257 fp_logo_init(pd
, cmd
, job
);
15259 mutex_exit(&pd
->pd_mutex
);
15260 mutex_exit(&port
->fp_mutex
);
15262 if (fp_sendcmd(port
, cmd
, port
->fp_fca_handle
) != FC_SUCCESS
) {
15263 mutex_enter(&pd
->pd_mutex
);
15264 pd
->pd_flags
= PD_IDLE
;
15265 mutex_exit(&pd
->pd_mutex
);
15268 fctl_release_remote_port(pd
);
15275 fcio
->fcio_errno
= job
->job_result
;
15276 if (job
->job_result
!= FC_SUCCESS
) {
15277 mutex_enter(&pd
->pd_mutex
);
15278 pd
->pd_flags
= PD_IDLE
;
15279 mutex_exit(&pd
->pd_mutex
);
15281 fctl_release_remote_port(pd
);
15286 ASSERT(pd
!= NULL
);
15288 changelist
= kmem_zalloc(sizeof (*changelist
), KM_SLEEP
);
15290 fctl_copy_portmap(changelist
, pd
);
15291 changelist
->map_type
= PORT_DEVICE_USER_LOGOUT
;
15292 changelist
->map_state
= PORT_DEVICE_INVALID
;
15294 mutex_enter(&port
->fp_mutex
);
15295 mutex_enter(&pd
->pd_mutex
);
15297 fctl_delist_did_table(port
, pd
);
15298 fctl_delist_pwwn_table(port
, pd
);
15299 pd
->pd_flags
= PD_IDLE
;
15301 mutex_exit(&pd
->pd_mutex
);
15302 mutex_exit(&port
->fp_mutex
);
15304 (void) fp_ulp_devc_cb(port
, changelist
, 1, 1, KM_SLEEP
, 1);
15306 fctl_release_remote_port(pd
);
15314 * Send a syslog event for adapter port level events.
15317 fp_log_port_event(fc_local_port_t
*port
, char *subclass
)
15319 nvlist_t
*attr_list
;
15321 if (nvlist_alloc(&attr_list
, NV_UNIQUE_NAME_TYPE
,
15322 KM_SLEEP
) != DDI_SUCCESS
) {
15326 if (nvlist_add_uint32(attr_list
, "instance",
15327 port
->fp_instance
) != DDI_SUCCESS
) {
15331 if (nvlist_add_byte_array(attr_list
, "port-wwn",
15332 port
->fp_service_params
.nport_ww_name
.raw_wwn
,
15333 sizeof (la_wwn_t
)) != DDI_SUCCESS
) {
15337 (void) ddi_log_sysevent(port
->fp_port_dip
, DDI_VENDOR_SUNW
, EC_SUNFC
,
15338 subclass
, attr_list
, NULL
, DDI_SLEEP
);
15340 nvlist_free(attr_list
);
15344 nvlist_free(attr_list
);
15346 FP_TRACE(FP_NHEAD1(9, 0), "Unable to send %s event", subclass
);
15351 fp_log_target_event(fc_local_port_t
*port
, char *subclass
, la_wwn_t tgt_pwwn
,
15354 nvlist_t
*attr_list
;
15356 if (nvlist_alloc(&attr_list
, NV_UNIQUE_NAME_TYPE
,
15357 KM_SLEEP
) != DDI_SUCCESS
) {
15361 if (nvlist_add_uint32(attr_list
, "instance",
15362 port
->fp_instance
) != DDI_SUCCESS
) {
15366 if (nvlist_add_byte_array(attr_list
, "port-wwn",
15367 port
->fp_service_params
.nport_ww_name
.raw_wwn
,
15368 sizeof (la_wwn_t
)) != DDI_SUCCESS
) {
15372 if (nvlist_add_byte_array(attr_list
, "target-port-wwn",
15373 tgt_pwwn
.raw_wwn
, sizeof (la_wwn_t
)) != DDI_SUCCESS
) {
15377 if (nvlist_add_uint32(attr_list
, "target-port-id",
15378 port_id
) != DDI_SUCCESS
) {
15382 (void) ddi_log_sysevent(port
->fp_port_dip
, DDI_VENDOR_SUNW
, EC_SUNFC
,
15383 subclass
, attr_list
, NULL
, DDI_SLEEP
);
15385 nvlist_free(attr_list
);
15389 nvlist_free(attr_list
);
15391 FP_TRACE(FP_NHEAD1(9, 0), "Unable to send %s event", subclass
);
15395 fp_map_remote_port_state(uint32_t rm_state
)
15397 switch (rm_state
) {
15398 case PORT_DEVICE_LOGGED_IN
:
15399 return (FC_HBA_PORTSTATE_ONLINE
);
15400 case PORT_DEVICE_VALID
:
15401 case PORT_DEVICE_INVALID
:
15403 return (FC_HBA_PORTSTATE_UNKNOWN
);