4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 * 1394 Services Layer Fixed Address Support Routines
32 * Currently used for FCP support.
37 #include <sys/sunddi.h>
38 #include <sys/cmn_err.h>
39 #include <sys/types.h>
41 #include <sys/tnf_probe.h>
43 #include <sys/1394/t1394.h>
44 #include <sys/1394/s1394.h>
45 #include <sys/1394/h1394.h>
47 static void s1394_fa_completion_cb(cmd1394_cmd_t
*cmd
);
50 * s1394_fa_claim_addr_blk()
51 * Claim fixed address block.
54 s1394_fa_claim_addr(s1394_hal_t
*hal
, s1394_fa_type_t type
,
55 s1394_fa_descr_t
*descr
)
57 t1394_alloc_addr_t addr
;
58 s1394_fa_hal_t
*falp
= &hal
->hal_fa
[type
];
61 /* Might have been claimed already */
62 if (falp
->fal_addr_blk
!= NULL
) {
66 falp
->fal_descr
= descr
;
68 bzero(&addr
, sizeof (addr
));
69 addr
.aa_type
= T1394_ADDR_FIXED
;
70 addr
.aa_address
= descr
->fd_addr
;
71 addr
.aa_length
= descr
->fd_size
;
72 addr
.aa_enable
= descr
->fd_enable
;
73 addr
.aa_evts
= descr
->fd_evts
;
76 ret
= s1394_claim_addr_blk(hal
, &addr
);
77 if (ret
!= DDI_SUCCESS
) {
79 falp
->fal_addr_blk
= (s1394_addr_space_blk_t
*)addr
.aa_hdl
;
86 * s1394_fa_free_addr_blk()
87 * Free fixed address block.
90 s1394_fa_free_addr(s1394_hal_t
*hal
, s1394_fa_type_t type
)
92 s1394_fa_hal_t
*falp
= &hal
->hal_fa
[type
];
95 /* Might have been freed already */
96 if (falp
->fal_addr_blk
!= NULL
) {
97 ret
= s1394_free_addr_blk(hal
, falp
->fal_addr_blk
);
98 if (ret
!= DDI_SUCCESS
) {
100 falp
->fal_addr_blk
= NULL
;
105 * s1394_fa_list_add()
106 * Add target to the list of FA clients.
107 * target_list_rwlock should be writer-held.
110 s1394_fa_list_add(s1394_hal_t
*hal
, s1394_target_t
*target
,
111 s1394_fa_type_t type
)
113 s1394_fa_hal_t
*fal
= &hal
->hal_fa
[type
];
115 if (fal
->fal_head
== NULL
) {
116 ASSERT(fal
->fal_tail
== NULL
);
117 fal
->fal_head
= fal
->fal_tail
= target
;
119 fal
->fal_tail
->target_fa
[type
].fat_next
= target
;
120 fal
->fal_tail
= target
;
126 * s1394_fa_list_remove()
127 * Remove target from the list of FA clients.
128 * target_list_rwlock should be writer-held.
131 s1394_fa_list_remove(s1394_hal_t
*hal
, s1394_target_t
*target
,
132 s1394_fa_type_t type
)
134 s1394_fa_hal_t
*fal
= &hal
->hal_fa
[type
];
135 s1394_target_t
*curp
, **nextp
, *prevp
= NULL
;
137 for (nextp
= &fal
->fal_head
; (curp
= *nextp
) != NULL
; ) {
138 if (curp
== target
) {
139 *nextp
= target
->target_fa
[type
].fat_next
;
140 if (target
== fal
->fal_tail
) {
141 fal
->fal_tail
= prevp
;
144 return (DDI_SUCCESS
);
146 nextp
= &curp
->target_fa
[type
].fat_next
;
149 return (DDI_FAILURE
);
153 * s1394_fa_list_is_empty()
154 * Returns B_TRUE if the target list is empty
155 * target_list_rwlock should be at least reader-held.
158 s1394_fa_list_is_empty(s1394_hal_t
*hal
, s1394_fa_type_t type
)
160 s1394_fa_hal_t
*fal
= &hal
->hal_fa
[type
];
162 return (fal
->fal_head
== NULL
);
166 * s1394_fa_list_gen()
167 * Returns list generation number.
168 * target_list_rwlock should be at least reader-held.
171 s1394_fa_list_gen(s1394_hal_t
*hal
, s1394_fa_type_t type
)
173 s1394_fa_hal_t
*fal
= &hal
->hal_fa
[type
];
175 return (fal
->fal_gen
);
179 * s1394_fa_init_cmd()
180 * initialize the FA specific part of the command
183 s1394_fa_init_cmd(s1394_cmd_priv_t
*s_priv
, s1394_fa_type_t type
)
185 s_priv
->cmd_ext_type
= S1394_CMD_EXT_FA
;
186 s_priv
->cmd_ext
.fa
.type
= type
;
190 * s1394_fa_convert_cmd()
191 * convert an FA command (with a relative address) to a regular 1394 command
194 s1394_fa_convert_cmd(s1394_hal_t
*hal
, cmd1394_cmd_t
*cmd
)
196 s1394_fa_cmd_priv_t
*fa_priv
= S1394_GET_FA_CMD_PRIV(cmd
);
198 cmd
->cmd_addr
+= hal
->hal_fa
[fa_priv
->type
].fal_descr
->fd_conv_base
;
199 fa_priv
->completion_callback
= cmd
->completion_callback
;
200 fa_priv
->callback_arg
= cmd
->cmd_callback_arg
;
201 cmd
->completion_callback
= s1394_fa_completion_cb
;
202 cmd
->cmd_callback_arg
= hal
;
206 * s1394_fa_restore_cmd()
207 * opposite of s1394_fa_convert_cmd(): regular 1394 command to FA command
210 s1394_fa_restore_cmd(s1394_hal_t
*hal
, cmd1394_cmd_t
*cmd
)
212 s1394_fa_cmd_priv_t
*fa_priv
= S1394_GET_FA_CMD_PRIV(cmd
);
214 ASSERT(fa_priv
->type
< S1394_FA_NTYPES
);
216 cmd
->cmd_addr
-= hal
->hal_fa
[fa_priv
->type
].fal_descr
->fd_conv_base
;
217 cmd
->completion_callback
= fa_priv
->completion_callback
;
218 cmd
->cmd_callback_arg
= fa_priv
->callback_arg
;
222 * s1394_fa_check_restore_cmd()
223 * if a command has FA extension, do s1394_fa_restore_cmd()
226 s1394_fa_check_restore_cmd(s1394_hal_t
*hal
, cmd1394_cmd_t
*cmd
)
228 s1394_cmd_priv_t
*s_priv
= S1394_GET_CMD_PRIV(cmd
);
230 if (s_priv
->cmd_ext_type
== S1394_CMD_EXT_FA
) {
231 s1394_fa_restore_cmd(hal
, cmd
);
236 * s1394_fa_completion_cb()
237 * FA completion callback: restore command and call original callback
240 s1394_fa_completion_cb(cmd1394_cmd_t
*cmd
)
242 s1394_hal_t
*hal
= cmd
->cmd_callback_arg
;
244 s1394_fa_restore_cmd(hal
, cmd
);
246 if (cmd
->completion_callback
) {
247 cmd
->completion_callback(cmd
);