xref: /titanic_51/usr/src/uts/common/io/1394/s1394_fa.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * s1394_fa.c
31*7c478bd9Sstevel@tonic-gate  *    1394 Services Layer Fixed Address Support Routines
32*7c478bd9Sstevel@tonic-gate  *    Currently used for FCP support.
33*7c478bd9Sstevel@tonic-gate  */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #include <sys/conf.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/tnf_probe.h>
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #include <sys/1394/t1394.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/1394/s1394.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/1394/h1394.h>
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate static void s1394_fa_completion_cb(cmd1394_cmd_t *cmd);
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate /*
50*7c478bd9Sstevel@tonic-gate  * s1394_fa_claim_addr_blk()
51*7c478bd9Sstevel@tonic-gate  *    Claim fixed address block.
52*7c478bd9Sstevel@tonic-gate  */
53*7c478bd9Sstevel@tonic-gate int
54*7c478bd9Sstevel@tonic-gate s1394_fa_claim_addr(s1394_hal_t *hal, s1394_fa_type_t type,
55*7c478bd9Sstevel@tonic-gate     s1394_fa_descr_t *descr)
56*7c478bd9Sstevel@tonic-gate {
57*7c478bd9Sstevel@tonic-gate 	t1394_alloc_addr_t	addr;
58*7c478bd9Sstevel@tonic-gate 	s1394_fa_hal_t		*falp = &hal->hal_fa[type];
59*7c478bd9Sstevel@tonic-gate 	int			ret;
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fa_claim_addr_enter, S1394_TNF_SL_FA_STACK, "");
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	/* Might have been claimed already */
64*7c478bd9Sstevel@tonic-gate 	if (falp->fal_addr_blk != NULL) {
65*7c478bd9Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(s1394_fa_claim_addr_exit,
66*7c478bd9Sstevel@tonic-gate 		    S1394_TNF_SL_FA_STACK, "");
67*7c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
68*7c478bd9Sstevel@tonic-gate 	}
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	falp->fal_descr = descr;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	bzero(&addr, sizeof (addr));
73*7c478bd9Sstevel@tonic-gate 	addr.aa_type = T1394_ADDR_FIXED;
74*7c478bd9Sstevel@tonic-gate 	addr.aa_address = descr->fd_addr;
75*7c478bd9Sstevel@tonic-gate 	addr.aa_length = descr->fd_size;
76*7c478bd9Sstevel@tonic-gate 	addr.aa_enable = descr->fd_enable;
77*7c478bd9Sstevel@tonic-gate 	addr.aa_evts = descr->fd_evts;
78*7c478bd9Sstevel@tonic-gate 	addr.aa_arg = hal;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 	ret = s1394_claim_addr_blk(hal, &addr);
81*7c478bd9Sstevel@tonic-gate 	if (ret != DDI_SUCCESS) {
82*7c478bd9Sstevel@tonic-gate 		TNF_PROBE_2(s1394_fa_claim_addr_error, S1394_TNF_SL_FA_ERROR,
83*7c478bd9Sstevel@tonic-gate 		    "", tnf_int, type, type, tnf_int, ret, ret);
84*7c478bd9Sstevel@tonic-gate 	} else {
85*7c478bd9Sstevel@tonic-gate 		falp->fal_addr_blk = (s1394_addr_space_blk_t *)addr.aa_hdl;
86*7c478bd9Sstevel@tonic-gate 	}
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fa_claim_addr_exit, S1394_TNF_SL_FA_STACK, "");
89*7c478bd9Sstevel@tonic-gate 	return (ret);
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate  * s1394_fa_free_addr_blk()
94*7c478bd9Sstevel@tonic-gate  *    Free fixed address block.
95*7c478bd9Sstevel@tonic-gate  */
96*7c478bd9Sstevel@tonic-gate void
97*7c478bd9Sstevel@tonic-gate s1394_fa_free_addr(s1394_hal_t *hal, s1394_fa_type_t type)
98*7c478bd9Sstevel@tonic-gate {
99*7c478bd9Sstevel@tonic-gate 	s1394_fa_hal_t		*falp = &hal->hal_fa[type];
100*7c478bd9Sstevel@tonic-gate 	int			ret;
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fa_free_addr_enter, S1394_TNF_SL_FA_STACK, "");
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	/* Might have been freed already */
105*7c478bd9Sstevel@tonic-gate 	if (falp->fal_addr_blk != NULL) {
106*7c478bd9Sstevel@tonic-gate 		ret = s1394_free_addr_blk(hal, falp->fal_addr_blk);
107*7c478bd9Sstevel@tonic-gate 		if (ret != DDI_SUCCESS) {
108*7c478bd9Sstevel@tonic-gate 			TNF_PROBE_1(s1394_fa_free_addr_error,
109*7c478bd9Sstevel@tonic-gate 			    S1394_TNF_SL_FA_STACK, "", tnf_int, ret, ret);
110*7c478bd9Sstevel@tonic-gate 		}
111*7c478bd9Sstevel@tonic-gate 		falp->fal_addr_blk = NULL;
112*7c478bd9Sstevel@tonic-gate 	}
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fa_free_addr_exit, S1394_TNF_SL_FA_STACK, "");
115*7c478bd9Sstevel@tonic-gate }
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /*
118*7c478bd9Sstevel@tonic-gate  * s1394_fa_list_add()
119*7c478bd9Sstevel@tonic-gate  *    Add target to the list of FA clients.
120*7c478bd9Sstevel@tonic-gate  *    target_list_rwlock should be writer-held.
121*7c478bd9Sstevel@tonic-gate  */
122*7c478bd9Sstevel@tonic-gate void
123*7c478bd9Sstevel@tonic-gate s1394_fa_list_add(s1394_hal_t *hal, s1394_target_t *target,
124*7c478bd9Sstevel@tonic-gate     s1394_fa_type_t type)
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate 	s1394_fa_hal_t	*fal = &hal->hal_fa[type];
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	if (fal->fal_head == NULL) {
129*7c478bd9Sstevel@tonic-gate 		ASSERT(fal->fal_tail == NULL);
130*7c478bd9Sstevel@tonic-gate 		fal->fal_head = fal->fal_tail = target;
131*7c478bd9Sstevel@tonic-gate 	} else {
132*7c478bd9Sstevel@tonic-gate 		fal->fal_tail->target_fa[type].fat_next = target;
133*7c478bd9Sstevel@tonic-gate 		fal->fal_tail = target;
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 	fal->fal_gen++;
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * s1394_fa_list_remove()
140*7c478bd9Sstevel@tonic-gate  *    Remove target from the list of FA clients.
141*7c478bd9Sstevel@tonic-gate  *    target_list_rwlock should be writer-held.
142*7c478bd9Sstevel@tonic-gate  */
143*7c478bd9Sstevel@tonic-gate int
144*7c478bd9Sstevel@tonic-gate s1394_fa_list_remove(s1394_hal_t *hal, s1394_target_t *target,
145*7c478bd9Sstevel@tonic-gate     s1394_fa_type_t type)
146*7c478bd9Sstevel@tonic-gate {
147*7c478bd9Sstevel@tonic-gate 	s1394_fa_hal_t	*fal = &hal->hal_fa[type];
148*7c478bd9Sstevel@tonic-gate 	s1394_target_t	*curp, **nextp, *prevp = NULL;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 	for (nextp = &fal->fal_head; (curp = *nextp) != NULL; ) {
151*7c478bd9Sstevel@tonic-gate 		if (curp == target) {
152*7c478bd9Sstevel@tonic-gate 			*nextp = target->target_fa[type].fat_next;
153*7c478bd9Sstevel@tonic-gate 			if (target == fal->fal_tail) {
154*7c478bd9Sstevel@tonic-gate 				fal->fal_tail = prevp;
155*7c478bd9Sstevel@tonic-gate 			}
156*7c478bd9Sstevel@tonic-gate 			fal->fal_gen++;
157*7c478bd9Sstevel@tonic-gate 			return (DDI_SUCCESS);
158*7c478bd9Sstevel@tonic-gate 		}
159*7c478bd9Sstevel@tonic-gate 		nextp = &curp->target_fa[type].fat_next;
160*7c478bd9Sstevel@tonic-gate 		prevp = curp;
161*7c478bd9Sstevel@tonic-gate 	}
162*7c478bd9Sstevel@tonic-gate 	return (DDI_FAILURE);
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate  * s1394_fa_list_is_empty()
167*7c478bd9Sstevel@tonic-gate  *    Returns B_TRUE if the target list is empty
168*7c478bd9Sstevel@tonic-gate  *    target_list_rwlock should be at least reader-held.
169*7c478bd9Sstevel@tonic-gate  */
170*7c478bd9Sstevel@tonic-gate boolean_t
171*7c478bd9Sstevel@tonic-gate s1394_fa_list_is_empty(s1394_hal_t *hal, s1394_fa_type_t type)
172*7c478bd9Sstevel@tonic-gate {
173*7c478bd9Sstevel@tonic-gate 	s1394_fa_hal_t	*fal = &hal->hal_fa[type];
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	return (fal->fal_head == NULL);
176*7c478bd9Sstevel@tonic-gate }
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate /*
179*7c478bd9Sstevel@tonic-gate  * s1394_fa_list_gen()
180*7c478bd9Sstevel@tonic-gate  *    Returns list generation number.
181*7c478bd9Sstevel@tonic-gate  *    target_list_rwlock should be at least reader-held.
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate uint_t
184*7c478bd9Sstevel@tonic-gate s1394_fa_list_gen(s1394_hal_t *hal, s1394_fa_type_t type)
185*7c478bd9Sstevel@tonic-gate {
186*7c478bd9Sstevel@tonic-gate 	s1394_fa_hal_t	*fal = &hal->hal_fa[type];
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 	return (fal->fal_gen);
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate /*
192*7c478bd9Sstevel@tonic-gate  * s1394_fa_init_cmd()
193*7c478bd9Sstevel@tonic-gate  *    initialize the FA specific part of the command
194*7c478bd9Sstevel@tonic-gate  */
195*7c478bd9Sstevel@tonic-gate void
196*7c478bd9Sstevel@tonic-gate s1394_fa_init_cmd(s1394_cmd_priv_t *s_priv, s1394_fa_type_t type)
197*7c478bd9Sstevel@tonic-gate {
198*7c478bd9Sstevel@tonic-gate 	s_priv->cmd_ext_type = S1394_CMD_EXT_FA;
199*7c478bd9Sstevel@tonic-gate 	s_priv->cmd_ext.fa.type = type;
200*7c478bd9Sstevel@tonic-gate }
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate /*
203*7c478bd9Sstevel@tonic-gate  * s1394_fa_convert_cmd()
204*7c478bd9Sstevel@tonic-gate  *    convert an FA command (with a relative address) to a regular 1394 command
205*7c478bd9Sstevel@tonic-gate  */
206*7c478bd9Sstevel@tonic-gate void
207*7c478bd9Sstevel@tonic-gate s1394_fa_convert_cmd(s1394_hal_t *hal, cmd1394_cmd_t *cmd)
208*7c478bd9Sstevel@tonic-gate {
209*7c478bd9Sstevel@tonic-gate 	s1394_fa_cmd_priv_t *fa_priv = S1394_GET_FA_CMD_PRIV(cmd);
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 	cmd->cmd_addr += hal->hal_fa[fa_priv->type].fal_descr->fd_conv_base;
212*7c478bd9Sstevel@tonic-gate 	fa_priv->completion_callback = cmd->completion_callback;
213*7c478bd9Sstevel@tonic-gate 	fa_priv->callback_arg = cmd->cmd_callback_arg;
214*7c478bd9Sstevel@tonic-gate 	cmd->completion_callback = s1394_fa_completion_cb;
215*7c478bd9Sstevel@tonic-gate 	cmd->cmd_callback_arg = hal;
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate /*
219*7c478bd9Sstevel@tonic-gate  * s1394_fa_restore_cmd()
220*7c478bd9Sstevel@tonic-gate  *    opposite of s1394_fa_convert_cmd(): regular 1394 command to FA command
221*7c478bd9Sstevel@tonic-gate  */
222*7c478bd9Sstevel@tonic-gate void
223*7c478bd9Sstevel@tonic-gate s1394_fa_restore_cmd(s1394_hal_t *hal, cmd1394_cmd_t *cmd)
224*7c478bd9Sstevel@tonic-gate {
225*7c478bd9Sstevel@tonic-gate 	s1394_fa_cmd_priv_t *fa_priv = S1394_GET_FA_CMD_PRIV(cmd);
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 	ASSERT(fa_priv->type < S1394_FA_NTYPES);
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 	cmd->cmd_addr -= hal->hal_fa[fa_priv->type].fal_descr->fd_conv_base;
230*7c478bd9Sstevel@tonic-gate 	cmd->completion_callback = fa_priv->completion_callback;
231*7c478bd9Sstevel@tonic-gate 	cmd->cmd_callback_arg = fa_priv->callback_arg;
232*7c478bd9Sstevel@tonic-gate }
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate /*
235*7c478bd9Sstevel@tonic-gate  * s1394_fa_check_restore_cmd()
236*7c478bd9Sstevel@tonic-gate  *    if a command has FA extension, do s1394_fa_restore_cmd()
237*7c478bd9Sstevel@tonic-gate  */
238*7c478bd9Sstevel@tonic-gate void
239*7c478bd9Sstevel@tonic-gate s1394_fa_check_restore_cmd(s1394_hal_t *hal, cmd1394_cmd_t *cmd)
240*7c478bd9Sstevel@tonic-gate {
241*7c478bd9Sstevel@tonic-gate 	s1394_cmd_priv_t *s_priv = S1394_GET_CMD_PRIV(cmd);
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate 	if (s_priv->cmd_ext_type == S1394_CMD_EXT_FA) {
244*7c478bd9Sstevel@tonic-gate 		s1394_fa_restore_cmd(hal, cmd);
245*7c478bd9Sstevel@tonic-gate 	}
246*7c478bd9Sstevel@tonic-gate }
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate /*
249*7c478bd9Sstevel@tonic-gate  * s1394_fa_completion_cb()
250*7c478bd9Sstevel@tonic-gate  *    FA completion callback: restore command and call original callback
251*7c478bd9Sstevel@tonic-gate  */
252*7c478bd9Sstevel@tonic-gate static void
253*7c478bd9Sstevel@tonic-gate s1394_fa_completion_cb(cmd1394_cmd_t *cmd)
254*7c478bd9Sstevel@tonic-gate {
255*7c478bd9Sstevel@tonic-gate 	s1394_hal_t	*hal = cmd->cmd_callback_arg;
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fa_completion_cb_enter,
258*7c478bd9Sstevel@tonic-gate 	    S1394_TNF_SL_FA_STACK, "");
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 	s1394_fa_restore_cmd(hal, cmd);
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate 	if (cmd->completion_callback) {
263*7c478bd9Sstevel@tonic-gate 		cmd->completion_callback(cmd);
264*7c478bd9Sstevel@tonic-gate 	}
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(s1394_fa_completion_cb_exit,
267*7c478bd9Sstevel@tonic-gate 	    S1394_TNF_SL_FA_STACK, "");
268*7c478bd9Sstevel@tonic-gate }
269