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