xref: /onnv-gate/usr/src/uts/common/io/1394/adapters/hci1394_async.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 (c) 1999-2000 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
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  * hci1394_async.c
31*0Sstevel@tonic-gate  *    These routines manipulate the 1394 asynchronous dma engines.  This
32*0Sstevel@tonic-gate  *    includes incoming and outgoing reads, writes, and locks and their
33*0Sstevel@tonic-gate  *    associated responses.
34*0Sstevel@tonic-gate  */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <sys/conf.h>
37*0Sstevel@tonic-gate #include <sys/ddi.h>
38*0Sstevel@tonic-gate #include <sys/modctl.h>
39*0Sstevel@tonic-gate #include <sys/stat.h>
40*0Sstevel@tonic-gate #include <sys/sunddi.h>
41*0Sstevel@tonic-gate #include <sys/cmn_err.h>
42*0Sstevel@tonic-gate #include <sys/kmem.h>
43*0Sstevel@tonic-gate #include <sys/types.h>
44*0Sstevel@tonic-gate #include <sys/note.h>
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate #include <sys/1394/h1394.h>
47*0Sstevel@tonic-gate #include <sys/1394/adapters/hci1394.h>
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate /*
51*0Sstevel@tonic-gate  * ASYNC_ARRESP_ACK_ERROR is or'd into the error status when we get an ACK error
52*0Sstevel@tonic-gate  * on an ARRESP.  Since the 1394 response code overlaps with the OpenHCI ACK/EVT
53*0Sstevel@tonic-gate  * errors, we use this to distinguish between the errors in process_arresp().
54*0Sstevel@tonic-gate  */
55*0Sstevel@tonic-gate #define	ASYNC_ARRESP_ACK_ERROR		0x8000
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate /* Macro's to help extract 48-bit 1394 address into a uint64_t */
58*0Sstevel@tonic-gate #define	HCI1394_TO_ADDR_HI(data) (((uint64_t)((data) & 0xFFFF)) << 32)
59*0Sstevel@tonic-gate #define	HCI1394_TO_ADDR_LO(data) ((uint64_t)((data) & 0xFFFFFFFF))
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate /*
62*0Sstevel@tonic-gate  * Macro to convert a byte stream into a big endian quadlet or octlet or back
63*0Sstevel@tonic-gate  * the other way. 1394 arithmetic lock operations are done on big endian
64*0Sstevel@tonic-gate  * quadlets or octlets. compare swaps and bit masks are done on a byte streams.
65*0Sstevel@tonic-gate  * All data is treated as byte streams over the bus. These macros will convert
66*0Sstevel@tonic-gate  * the data to a big endian "integer" on x86 plaforms if the operation is an
67*0Sstevel@tonic-gate  * arithmetic lock operation.  It will do nothing if it is not on x86 or is not
68*0Sstevel@tonic-gate  * an arithmetic lock operation.
69*0Sstevel@tonic-gate  */
70*0Sstevel@tonic-gate #ifdef _LITTLE_ENDIAN
71*0Sstevel@tonic-gate #define	HCI1394_ARITH_LOCK_SWAP32(tcode, data) \
72*0Sstevel@tonic-gate 	(((tcode) == CMD1394_LOCK_FETCH_ADD) || \
73*0Sstevel@tonic-gate 	((tcode) == CMD1394_LOCK_BOUNDED_ADD) || \
74*0Sstevel@tonic-gate 	((tcode) == CMD1394_LOCK_WRAP_ADD)) ? \
75*0Sstevel@tonic-gate 	(ddi_swap32(data)) : (data)
76*0Sstevel@tonic-gate #define	HCI1394_ARITH_LOCK_SWAP64(tcode, data) \
77*0Sstevel@tonic-gate 	(((tcode) == CMD1394_LOCK_FETCH_ADD) || \
78*0Sstevel@tonic-gate 	((tcode) == CMD1394_LOCK_BOUNDED_ADD) || \
79*0Sstevel@tonic-gate 	((tcode) == CMD1394_LOCK_WRAP_ADD)) ? \
80*0Sstevel@tonic-gate 	(ddi_swap64(data)) : (data)
81*0Sstevel@tonic-gate #else
82*0Sstevel@tonic-gate #define	HCI1394_ARITH_LOCK_SWAP32(tcode, data) (data)
83*0Sstevel@tonic-gate #define	HCI1394_ARITH_LOCK_SWAP64(tcode, data) (data)
84*0Sstevel@tonic-gate #endif
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate static int hci1394_async_arresp_read(hci1394_async_handle_t async_handle,
89*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, uint_t *tcode, hci1394_async_cmd_t **hcicmd,
90*0Sstevel@tonic-gate     uint_t *size);
91*0Sstevel@tonic-gate static int hci1394_async_arresp_size_get(uint_t tcode, hci1394_q_handle_t q,
92*0Sstevel@tonic-gate     uint32_t *addr, uint_t *size);
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate static int hci1394_async_arreq_read(hci1394_async_handle_t async_handle,
95*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, uint_t *tcode, hci1394_async_cmd_t **hcicmd,
96*0Sstevel@tonic-gate     uint_t *size);
97*0Sstevel@tonic-gate static int hci1394_async_arreq_read_qrd(hci1394_async_handle_t async_handle,
98*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size);
99*0Sstevel@tonic-gate static int hci1394_async_arreq_read_qwr(hci1394_async_handle_t async_handle,
100*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size);
101*0Sstevel@tonic-gate static int hci1394_async_arreq_read_brd(hci1394_async_handle_t async_handle,
102*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size);
103*0Sstevel@tonic-gate static int hci1394_async_arreq_read_bwr(hci1394_async_handle_t async_handle,
104*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size);
105*0Sstevel@tonic-gate static int hci1394_async_arreq_read_lck(hci1394_async_handle_t async_handle,
106*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size);
107*0Sstevel@tonic-gate static int hci1394_async_arreq_read_phy(hci1394_async_handle_t async_handle,
108*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size,
109*0Sstevel@tonic-gate     boolean_t *bus_reset_token);
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate static void hci1394_async_hcicmd_init(hci1394_async_handle_t async_handle,
112*0Sstevel@tonic-gate     cmd1394_cmd_t *cmd, h1394_cmd_priv_t *cmd_priv,
113*0Sstevel@tonic-gate     hci1394_async_cmd_t **hcicmd);
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate static void hci1394_async_atreq_start(void *async, uint32_t command_ptr);
116*0Sstevel@tonic-gate static void hci1394_async_arresp_start(void *async, uint32_t command_ptr);
117*0Sstevel@tonic-gate static void hci1394_async_arreq_start(void *async, uint32_t command_ptr);
118*0Sstevel@tonic-gate static void hci1394_async_atresp_start(void *async, uint32_t command_ptr);
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate static void hci1394_async_atreq_wake(void *async);
121*0Sstevel@tonic-gate static void hci1394_async_arresp_wake(void *async);
122*0Sstevel@tonic-gate static void hci1394_async_arreq_wake(void *async);
123*0Sstevel@tonic-gate static void hci1394_async_atresp_wake(void *async);
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate static void hci1394_async_atreq_flush(hci1394_async_handle_t async_handle);
126*0Sstevel@tonic-gate static void hci1394_async_arresp_flush(hci1394_async_handle_t async_handle);
127*0Sstevel@tonic-gate static void hci1394_async_arreq_flush(hci1394_async_handle_t async_handle);
128*0Sstevel@tonic-gate static void hci1394_async_atresp_flush(hci1394_async_handle_t async_handle);
129*0Sstevel@tonic-gate static void hci1394_async_pending_list_flush(hci1394_async_handle_t
130*0Sstevel@tonic-gate     async_handle);
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate static void hci1394_async_pending_timeout(hci1394_tlist_node_t *node,
133*0Sstevel@tonic-gate     void *arg);
134*0Sstevel@tonic-gate static uint_t hci1394_async_timeout_calc(hci1394_async_handle_t async_handle,
135*0Sstevel@tonic-gate     uint_t current_time);
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique", msgb))
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate /*
140*0Sstevel@tonic-gate  * hci1394_async_init()
141*0Sstevel@tonic-gate  *    Initialize the async DMA engines and state. We init the tlabels; ATREQ
142*0Sstevel@tonic-gate  *    pending Q; and ATREQ, ARRESP, ARREQ, and ATRESP Q's. init() returns a
143*0Sstevel@tonic-gate  *    handle to be used in rest of the functions.
144*0Sstevel@tonic-gate  */
145*0Sstevel@tonic-gate int
hci1394_async_init(hci1394_drvinfo_t * drvinfo,hci1394_ohci_handle_t ohci_handle,hci1394_csr_handle_t csr_handle,hci1394_async_handle_t * async_handle)146*0Sstevel@tonic-gate hci1394_async_init(hci1394_drvinfo_t *drvinfo,
147*0Sstevel@tonic-gate     hci1394_ohci_handle_t ohci_handle, hci1394_csr_handle_t csr_handle,
148*0Sstevel@tonic-gate     hci1394_async_handle_t *async_handle)
149*0Sstevel@tonic-gate {
150*0Sstevel@tonic-gate 	hci1394_tlist_timer_t timer_info;
151*0Sstevel@tonic-gate 	hci1394_q_info_t qinfo;
152*0Sstevel@tonic-gate 	hci1394_async_t *async;
153*0Sstevel@tonic-gate 	int status;
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate 	ASSERT(drvinfo != NULL);
157*0Sstevel@tonic-gate 	ASSERT(ohci_handle != NULL);
158*0Sstevel@tonic-gate 	ASSERT(csr_handle != NULL);
159*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
160*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_init_enter, HCI1394_TNF_HAL_STACK, "");
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate 	/* alloc the space to keep track of the list */
163*0Sstevel@tonic-gate 	async = kmem_alloc(sizeof (hci1394_async_t), KM_SLEEP);
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate 	/* copy in parms to our local state */
166*0Sstevel@tonic-gate 	async->as_drvinfo = drvinfo;
167*0Sstevel@tonic-gate 	async->as_ohci = ohci_handle;
168*0Sstevel@tonic-gate 	async->as_csr = csr_handle;
169*0Sstevel@tonic-gate 	async->as_flushing_arreq = B_FALSE;
170*0Sstevel@tonic-gate 	async->as_phy_reset = 0xFFFFFFFF;
171*0Sstevel@tonic-gate 	mutex_init(&async->as_atomic_lookup, NULL, MUTEX_DRIVER,
172*0Sstevel@tonic-gate 	    drvinfo->di_iblock_cookie);
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate 	/*
175*0Sstevel@tonic-gate 	 * Initialize the tlabels. Reclaim a bad tlabel after the split timeout
176*0Sstevel@tonic-gate 	 * has gone by. This time is in reference to the point the transaction
177*0Sstevel@tonic-gate 	 * has been marked as bad. Therefore the tlabel will be reclaimed at
178*0Sstevel@tonic-gate 	 * twice the split_timeout. (i.e. if the split timeout was set to 100mS
179*0Sstevel@tonic-gate 	 * and the transaction has timed out, 100mS has already gone by. We need
180*0Sstevel@tonic-gate 	 * to wait for 100mS more before we can reuse the tlabel. Therefore, the
181*0Sstevel@tonic-gate 	 * reclaim time is split_timeout and not split_timeout * 2. The split
182*0Sstevel@tonic-gate 	 * timeout is stored as the number of bus cycles.  We need to convert
183*0Sstevel@tonic-gate 	 * this to nS since the reclaim time is passed as nS.
184*0Sstevel@tonic-gate 	 */
185*0Sstevel@tonic-gate 	hci1394_tlabel_init(drvinfo, OHCI_BUS_CYCLE_TO_nS(
186*0Sstevel@tonic-gate 	    hci1394_csr_split_timeout_get(csr_handle)), &async->as_tlabel);
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 	/*
189*0Sstevel@tonic-gate 	 * Initialize ATREQ pending list. A pended ATREQ will be timed out after
190*0Sstevel@tonic-gate 	 * "split_timeout" has gone by. split timeout is in bus cycles so we
191*0Sstevel@tonic-gate 	 * need to convert that to nS for the tlist timer info. We will set the
192*0Sstevel@tonic-gate 	 * timer resolution to 1/2 of the timeout so that we will have a worst
193*0Sstevel@tonic-gate 	 * case timeout of split timeout + (1/2 * split timeout).  See
194*0Sstevel@tonic-gate 	 * hci1394_tlist.h for more information about this.
195*0Sstevel@tonic-gate 	 */
196*0Sstevel@tonic-gate 	timer_info.tlt_timeout =
197*0Sstevel@tonic-gate 	    OHCI_BUS_CYCLE_TO_nS(hci1394_csr_split_timeout_get(csr_handle));
198*0Sstevel@tonic-gate 	timer_info.tlt_timer_resolution = timer_info.tlt_timeout / 2;
199*0Sstevel@tonic-gate 	timer_info.tlt_callback = hci1394_async_pending_timeout;
200*0Sstevel@tonic-gate 	timer_info.tlt_callback_arg = async;
201*0Sstevel@tonic-gate 	hci1394_tlist_init(drvinfo, &timer_info, &async->as_pending_list);
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 	/* Initialize ATREQ Q */
204*0Sstevel@tonic-gate 	qinfo.qi_desc_size = ASYNC_ATREQ_DESC_SIZE;
205*0Sstevel@tonic-gate 	qinfo.qi_data_size = ASYNC_ATREQ_DATA_SIZE;
206*0Sstevel@tonic-gate 	qinfo.qi_mode = HCI1394_ATQ;
207*0Sstevel@tonic-gate 	qinfo.qi_start = hci1394_async_atreq_start;
208*0Sstevel@tonic-gate 	qinfo.qi_wake = hci1394_async_atreq_wake;
209*0Sstevel@tonic-gate 	qinfo.qi_callback_arg = async;
210*0Sstevel@tonic-gate 	status = hci1394_q_init(drvinfo, async->as_ohci, &qinfo,
211*0Sstevel@tonic-gate 	    &async->as_atreq_q);
212*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
213*0Sstevel@tonic-gate 		mutex_destroy(&async->as_atomic_lookup);
214*0Sstevel@tonic-gate 		hci1394_tlist_fini(&async->as_pending_list);
215*0Sstevel@tonic-gate 		hci1394_tlabel_fini(&async->as_tlabel);
216*0Sstevel@tonic-gate 		kmem_free(async, sizeof (hci1394_async_t));
217*0Sstevel@tonic-gate 		*async_handle = NULL;
218*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_q_init_fail, HCI1394_TNF_HAL_ERROR,
219*0Sstevel@tonic-gate 		    "");
220*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_init_exit,
221*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
222*0Sstevel@tonic-gate 		return (DDI_FAILURE);
223*0Sstevel@tonic-gate 	}
224*0Sstevel@tonic-gate 
225*0Sstevel@tonic-gate 	/* Initialize ARRESP Q */
226*0Sstevel@tonic-gate 	qinfo.qi_desc_size = ASYNC_ARRESP_DESC_SIZE;
227*0Sstevel@tonic-gate 	qinfo.qi_data_size = ASYNC_ARRESP_DATA_SIZE;
228*0Sstevel@tonic-gate 	qinfo.qi_mode = HCI1394_ARQ;
229*0Sstevel@tonic-gate 	qinfo.qi_start = hci1394_async_arresp_start;
230*0Sstevel@tonic-gate 	qinfo.qi_wake = hci1394_async_arresp_wake;
231*0Sstevel@tonic-gate 	qinfo.qi_callback_arg = async;
232*0Sstevel@tonic-gate 	status = hci1394_q_init(drvinfo, async->as_ohci, &qinfo,
233*0Sstevel@tonic-gate 	    &async->as_arresp_q);
234*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
235*0Sstevel@tonic-gate 		mutex_destroy(&async->as_atomic_lookup);
236*0Sstevel@tonic-gate 		hci1394_tlist_fini(&async->as_pending_list);
237*0Sstevel@tonic-gate 		hci1394_tlabel_fini(&async->as_tlabel);
238*0Sstevel@tonic-gate 		hci1394_q_fini(&async->as_atreq_q);
239*0Sstevel@tonic-gate 		kmem_free(async, sizeof (hci1394_async_t));
240*0Sstevel@tonic-gate 		*async_handle = NULL;
241*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_q_init_fail, HCI1394_TNF_HAL_ERROR,
242*0Sstevel@tonic-gate 		    "");
243*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_init_exit,
244*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
245*0Sstevel@tonic-gate 		return (DDI_FAILURE);
246*0Sstevel@tonic-gate 	}
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate 	/* Initialize ARREQ Q */
249*0Sstevel@tonic-gate 	qinfo.qi_desc_size = ASYNC_ARREQ_DESC_SIZE;
250*0Sstevel@tonic-gate 	qinfo.qi_data_size = ASYNC_ARREQ_DATA_SIZE;
251*0Sstevel@tonic-gate 	qinfo.qi_mode = HCI1394_ARQ;
252*0Sstevel@tonic-gate 	qinfo.qi_start = hci1394_async_arreq_start;
253*0Sstevel@tonic-gate 	qinfo.qi_wake = hci1394_async_arreq_wake;
254*0Sstevel@tonic-gate 	qinfo.qi_callback_arg = async;
255*0Sstevel@tonic-gate 	status = hci1394_q_init(drvinfo, async->as_ohci, &qinfo,
256*0Sstevel@tonic-gate 	    &async->as_arreq_q);
257*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
258*0Sstevel@tonic-gate 		mutex_destroy(&async->as_atomic_lookup);
259*0Sstevel@tonic-gate 		hci1394_tlist_fini(&async->as_pending_list);
260*0Sstevel@tonic-gate 		hci1394_tlabel_fini(&async->as_tlabel);
261*0Sstevel@tonic-gate 		hci1394_q_fini(&async->as_atreq_q);
262*0Sstevel@tonic-gate 		hci1394_q_fini(&async->as_arresp_q);
263*0Sstevel@tonic-gate 		kmem_free(async, sizeof (hci1394_async_t));
264*0Sstevel@tonic-gate 		*async_handle = NULL;
265*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_q_init_fail, HCI1394_TNF_HAL_ERROR,
266*0Sstevel@tonic-gate 		    "");
267*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_init_exit,
268*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
269*0Sstevel@tonic-gate 		return (DDI_FAILURE);
270*0Sstevel@tonic-gate 	}
271*0Sstevel@tonic-gate 
272*0Sstevel@tonic-gate 	/* Initialize ATRESP Q */
273*0Sstevel@tonic-gate 	qinfo.qi_desc_size = ASYNC_ATRESP_DESC_SIZE;
274*0Sstevel@tonic-gate 	qinfo.qi_data_size = ASYNC_ATRESP_DATA_SIZE;
275*0Sstevel@tonic-gate 	qinfo.qi_mode = HCI1394_ATQ;
276*0Sstevel@tonic-gate 	qinfo.qi_start = hci1394_async_atresp_start;
277*0Sstevel@tonic-gate 	qinfo.qi_wake = hci1394_async_atresp_wake;
278*0Sstevel@tonic-gate 	qinfo.qi_callback_arg = async;
279*0Sstevel@tonic-gate 	status = hci1394_q_init(drvinfo, async->as_ohci, &qinfo,
280*0Sstevel@tonic-gate 	    &async->as_atresp_q);
281*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
282*0Sstevel@tonic-gate 		mutex_destroy(&async->as_atomic_lookup);
283*0Sstevel@tonic-gate 		hci1394_tlist_fini(&async->as_pending_list);
284*0Sstevel@tonic-gate 		hci1394_tlabel_fini(&async->as_tlabel);
285*0Sstevel@tonic-gate 		hci1394_q_fini(&async->as_atreq_q);
286*0Sstevel@tonic-gate 		hci1394_q_fini(&async->as_arresp_q);
287*0Sstevel@tonic-gate 		hci1394_q_fini(&async->as_arreq_q);
288*0Sstevel@tonic-gate 		kmem_free(async, sizeof (hci1394_async_t));
289*0Sstevel@tonic-gate 		*async_handle = NULL;
290*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_q_init_fail, HCI1394_TNF_HAL_ERROR,
291*0Sstevel@tonic-gate 		    "");
292*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_init_exit,
293*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
294*0Sstevel@tonic-gate 		return (DDI_FAILURE);
295*0Sstevel@tonic-gate 	}
296*0Sstevel@tonic-gate 
297*0Sstevel@tonic-gate 	*async_handle = async;
298*0Sstevel@tonic-gate 
299*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_init_exit, HCI1394_TNF_HAL_STACK, "");
300*0Sstevel@tonic-gate 
301*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
302*0Sstevel@tonic-gate }
303*0Sstevel@tonic-gate 
304*0Sstevel@tonic-gate 
305*0Sstevel@tonic-gate /*
306*0Sstevel@tonic-gate  * hci1394_async_fini()
307*0Sstevel@tonic-gate  *    Free's up the space allocated in init().  Notice that a pointer to the
308*0Sstevel@tonic-gate  *    handle is used for the parameter.  fini() will set your handle to NULL
309*0Sstevel@tonic-gate  *    before returning.
310*0Sstevel@tonic-gate  */
311*0Sstevel@tonic-gate void
hci1394_async_fini(hci1394_async_handle_t * async_handle)312*0Sstevel@tonic-gate hci1394_async_fini(hci1394_async_handle_t *async_handle)
313*0Sstevel@tonic-gate {
314*0Sstevel@tonic-gate 	hci1394_async_t *async;
315*0Sstevel@tonic-gate 
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
318*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_fini_enter, HCI1394_TNF_HAL_STACK, "");
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate 	async = (hci1394_async_t *)*async_handle;
321*0Sstevel@tonic-gate 
322*0Sstevel@tonic-gate 	mutex_destroy(&async->as_atomic_lookup);
323*0Sstevel@tonic-gate 	hci1394_tlabel_fini(&async->as_tlabel);
324*0Sstevel@tonic-gate 	hci1394_tlist_fini(&async->as_pending_list);
325*0Sstevel@tonic-gate 	hci1394_q_fini(&async->as_atreq_q);
326*0Sstevel@tonic-gate 	hci1394_q_fini(&async->as_atresp_q);
327*0Sstevel@tonic-gate 	hci1394_q_fini(&async->as_arreq_q);
328*0Sstevel@tonic-gate 	hci1394_q_fini(&async->as_arresp_q);
329*0Sstevel@tonic-gate 
330*0Sstevel@tonic-gate 	kmem_free(async, sizeof (hci1394_async_t));
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate 	/* set handle to null.  This helps catch bugs. */
333*0Sstevel@tonic-gate 	*async_handle = NULL;
334*0Sstevel@tonic-gate 
335*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_fini_exit, HCI1394_TNF_HAL_STACK, "");
336*0Sstevel@tonic-gate }
337*0Sstevel@tonic-gate 
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate /*
340*0Sstevel@tonic-gate  * hci1394_async_suspend()
341*0Sstevel@tonic-gate  *    The system is getting ready to be suspended.  Make sure that all of
342*0Sstevel@tonic-gate  *    the Q's are clean and that the there are no scheduled timeouts in the
343*0Sstevel@tonic-gate  *    pending Q.
344*0Sstevel@tonic-gate  */
345*0Sstevel@tonic-gate void
hci1394_async_suspend(hci1394_async_handle_t async_handle)346*0Sstevel@tonic-gate hci1394_async_suspend(hci1394_async_handle_t async_handle)
347*0Sstevel@tonic-gate {
348*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
349*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_suspend_enter,
350*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate 	/* Flush out async DMA Q's */
353*0Sstevel@tonic-gate 	hci1394_async_flush(async_handle);
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 	/* Cancel any scheduled pending timeouts */
356*0Sstevel@tonic-gate 	hci1394_tlist_timeout_cancel(async_handle->as_pending_list);
357*0Sstevel@tonic-gate 
358*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_suspend_exit,
359*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
360*0Sstevel@tonic-gate }
361*0Sstevel@tonic-gate 
362*0Sstevel@tonic-gate 
363*0Sstevel@tonic-gate /*
364*0Sstevel@tonic-gate  * hci1394_async_resume()
365*0Sstevel@tonic-gate  *    Re-setup the DMA Q's during a resume after a successful suspend. The
366*0Sstevel@tonic-gate  *    tlabels will be re-initialized during the bus reset and the pending Q will
367*0Sstevel@tonic-gate  *    be flushed during the suspend.
368*0Sstevel@tonic-gate  */
369*0Sstevel@tonic-gate int
hci1394_async_resume(hci1394_async_handle_t async_handle)370*0Sstevel@tonic-gate hci1394_async_resume(hci1394_async_handle_t async_handle)
371*0Sstevel@tonic-gate {
372*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
373*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_resume_enter,
374*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 	hci1394_q_resume(async_handle->as_atreq_q);
377*0Sstevel@tonic-gate 	hci1394_q_resume(async_handle->as_atresp_q);
378*0Sstevel@tonic-gate 	hci1394_q_resume(async_handle->as_arreq_q);
379*0Sstevel@tonic-gate 	hci1394_q_resume(async_handle->as_arresp_q);
380*0Sstevel@tonic-gate 
381*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_resume_exit,
382*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
383*0Sstevel@tonic-gate 
384*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
385*0Sstevel@tonic-gate }
386*0Sstevel@tonic-gate 
387*0Sstevel@tonic-gate 
388*0Sstevel@tonic-gate /*
389*0Sstevel@tonic-gate  * hci1394_async_cmd_overhead()
390*0Sstevel@tonic-gate  *    Return the size of the HAL private area to attach to every alloced 1394
391*0Sstevel@tonic-gate  *    framework command.  This allows us to track command state without having
392*0Sstevel@tonic-gate  *    to alloc memory every time a command comes down the pipe.
393*0Sstevel@tonic-gate  */
394*0Sstevel@tonic-gate uint_t
hci1394_async_cmd_overhead()395*0Sstevel@tonic-gate hci1394_async_cmd_overhead()
396*0Sstevel@tonic-gate {
397*0Sstevel@tonic-gate 	return (sizeof (hci1394_async_cmd_t));
398*0Sstevel@tonic-gate }
399*0Sstevel@tonic-gate 
400*0Sstevel@tonic-gate 
401*0Sstevel@tonic-gate /*
402*0Sstevel@tonic-gate  * hci1394_async_flush()
403*0Sstevel@tonic-gate  *    Flush out the Async Q's and the ATREQ pending list.  This is called every
404*0Sstevel@tonic-gate  *    bus reset so that we're sync'd up with the HW and when shutting down or
405*0Sstevel@tonic-gate  *    suspending to make sure we cleanup after all commands.
406*0Sstevel@tonic-gate  */
407*0Sstevel@tonic-gate void
hci1394_async_flush(hci1394_async_handle_t async_handle)408*0Sstevel@tonic-gate hci1394_async_flush(hci1394_async_handle_t async_handle)
409*0Sstevel@tonic-gate {
410*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
411*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_flush_enter, HCI1394_TNF_HAL_STACK, "");
412*0Sstevel@tonic-gate 
413*0Sstevel@tonic-gate 	hci1394_async_atreq_flush(async_handle);
414*0Sstevel@tonic-gate 	hci1394_async_arresp_flush(async_handle);
415*0Sstevel@tonic-gate 	hci1394_async_pending_list_flush(async_handle);
416*0Sstevel@tonic-gate 	hci1394_async_arreq_flush(async_handle);
417*0Sstevel@tonic-gate 	hci1394_async_atresp_flush(async_handle);
418*0Sstevel@tonic-gate 	hci1394_tlabel_reset(async_handle->as_tlabel);
419*0Sstevel@tonic-gate 
420*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_flush_exit, HCI1394_TNF_HAL_STACK, "");
421*0Sstevel@tonic-gate }
422*0Sstevel@tonic-gate 
423*0Sstevel@tonic-gate 
424*0Sstevel@tonic-gate /*
425*0Sstevel@tonic-gate  * hci1394_async_pending_timeout_update()
426*0Sstevel@tonic-gate  *    Update the timeout for the pending list. This updates both the pending
427*0Sstevel@tonic-gate  *    list timeout and time we wait to reclaim  bad tlabels.  timeout is the
428*0Sstevel@tonic-gate  *    time in nS so we do not have to do any conversions. This routine will be
429*0Sstevel@tonic-gate  *    called when the CSR split timeout registers are updated.
430*0Sstevel@tonic-gate  */
431*0Sstevel@tonic-gate void
hci1394_async_pending_timeout_update(hci1394_async_handle_t async_handle,hrtime_t timeout)432*0Sstevel@tonic-gate hci1394_async_pending_timeout_update(hci1394_async_handle_t async_handle,
433*0Sstevel@tonic-gate     hrtime_t timeout)
434*0Sstevel@tonic-gate {
435*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
436*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_pending_timeout_update_enter,
437*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
438*0Sstevel@tonic-gate 	hci1394_tlist_timeout_update(async_handle->as_pending_list, timeout);
439*0Sstevel@tonic-gate 	hci1394_tlabel_set_reclaim_time(async_handle->as_tlabel, timeout);
440*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_pending_timeout_update_exit,
441*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
442*0Sstevel@tonic-gate }
443*0Sstevel@tonic-gate 
444*0Sstevel@tonic-gate 
445*0Sstevel@tonic-gate /*
446*0Sstevel@tonic-gate  * hci1394_async_atreq_process()
447*0Sstevel@tonic-gate  *    Process an atreq, if one has completed. This is called during interrupt
448*0Sstevel@tonic-gate  *    processing and will process a completed atreq. It returns status if an
449*0Sstevel@tonic-gate  *    atreq was processed so that the ISR knows that it needs to be called
450*0Sstevel@tonic-gate  *    again to see if another ATREQ has completed. flush_q set to B_TRUE tells
451*0Sstevel@tonic-gate  *    this routine to process all commands regardless of their completion
452*0Sstevel@tonic-gate  *    status.  This is used during bus reset processing to remove all commands
453*0Sstevel@tonic-gate  *    from the Q.
454*0Sstevel@tonic-gate  *
455*0Sstevel@tonic-gate  *    There are a few race conditions that we have to watch for in atreq/arresp.
456*0Sstevel@tonic-gate  *    They all have to do with pended responses so they are not applicable in
457*0Sstevel@tonic-gate  *    the ARREQ/ATRESP engine (since ATRESP's can't be pended).
458*0Sstevel@tonic-gate  *
459*0Sstevel@tonic-gate  *    Since the race conditions only exist for pended responses, we will only
460*0Sstevel@tonic-gate  *    talk about that sequence here. We're also going to simplify the discussion
461*0Sstevel@tonic-gate  *    so what the code does, so it won't exactly match what we say (e.g. we
462*0Sstevel@tonic-gate  *    don't always setup a timeout for every single command, etc.)
463*0Sstevel@tonic-gate  *
464*0Sstevel@tonic-gate  *    After Q'ing up an ATREQ, we will process the result of that command in
465*0Sstevel@tonic-gate  *    one of a couple different paths. A normal condition would be that we Q up
466*0Sstevel@tonic-gate  *    a command, we get an ATREQ complete interrupt and look at the ATREQ
467*0Sstevel@tonic-gate  *    result. In the case it has been pended, we setup a timeout to wait for the
468*0Sstevel@tonic-gate  *    response. If we receive the response before the timeout, the command is
469*0Sstevel@tonic-gate  *    done and we send the response up the chain, if we do not, the command is
470*0Sstevel@tonic-gate  *    done and we send a timeout notification up the chain.
471*0Sstevel@tonic-gate  *
472*0Sstevel@tonic-gate  *    The first race condition is when we get the timeout at the same time as
473*0Sstevel@tonic-gate  *    the response. At first glance a mutex around the command state would
474*0Sstevel@tonic-gate  *    solve this problem. But on a multi-processor machine, we may have the
475*0Sstevel@tonic-gate  *    ARRESP interrupt handler(ISR) running on one processor and the timeout on
476*0Sstevel@tonic-gate  *    another. This means that the command state could change between two
477*0Sstevel@tonic-gate  *    reads while in the ISR. This means we need to have a little more complex
478*0Sstevel@tonic-gate  *    logic around changing the command state and have to be careful how and
479*0Sstevel@tonic-gate  *    when we do this.
480*0Sstevel@tonic-gate  *
481*0Sstevel@tonic-gate  *    The second race condition is that we could see the ARRESP before we
482*0Sstevel@tonic-gate  *    process the ATREQ. We could be processing a few ARRESP from previous
483*0Sstevel@tonic-gate  *    ATREQ's when the ATREQ completes and then the ARRESP comes in.  Since we
484*0Sstevel@tonic-gate  *    already are in the interrupt handler, the ATREQ complete will not preempt
485*0Sstevel@tonic-gate  *    us.
486*0Sstevel@tonic-gate  *
487*0Sstevel@tonic-gate  *    We will never see a race condition between the ATREQ interrupt for a
488*0Sstevel@tonic-gate  *    command and the pending timeout since the command is not being timed until
489*0Sstevel@tonic-gate  *    this routine is run for that command.
490*0Sstevel@tonic-gate  */
491*0Sstevel@tonic-gate int
hci1394_async_atreq_process(hci1394_async_handle_t async_handle,boolean_t flush_q,boolean_t * request_available)492*0Sstevel@tonic-gate hci1394_async_atreq_process(hci1394_async_handle_t async_handle,
493*0Sstevel@tonic-gate     boolean_t flush_q, boolean_t *request_available)
494*0Sstevel@tonic-gate {
495*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
496*0Sstevel@tonic-gate 	hci1394_q_cmd_t *qcmd;
497*0Sstevel@tonic-gate 	int cmd_status;
498*0Sstevel@tonic-gate 
499*0Sstevel@tonic-gate 
500*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
501*0Sstevel@tonic-gate 	ASSERT(request_available != NULL);
502*0Sstevel@tonic-gate 
503*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_process_enter,
504*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate 	/*
507*0Sstevel@tonic-gate 	 * Get the next ATREQ that has completed (if one has). Space is free'd
508*0Sstevel@tonic-gate 	 * up in atreq_q and atreq_data_q as part of this function call.
509*0Sstevel@tonic-gate 	 */
510*0Sstevel@tonic-gate 	hci1394_q_at_next(async_handle->as_atreq_q, flush_q, &qcmd);
511*0Sstevel@tonic-gate 
512*0Sstevel@tonic-gate 	/*
513*0Sstevel@tonic-gate 	 * See if there were anymore requests on ATREQ Q. A NULL means there
514*0Sstevel@tonic-gate 	 * were no completed commands left on the Q
515*0Sstevel@tonic-gate 	 */
516*0Sstevel@tonic-gate 	if (qcmd == NULL) {
517*0Sstevel@tonic-gate 		*request_available = B_FALSE;
518*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_atreq_process_exit,
519*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
520*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
521*0Sstevel@tonic-gate 	}
522*0Sstevel@tonic-gate 
523*0Sstevel@tonic-gate 	/* There is a completed ATREQ, setup the HAL command pointer */
524*0Sstevel@tonic-gate 	*request_available = B_TRUE;
525*0Sstevel@tonic-gate 	hcicmd = (hci1394_async_cmd_t *)qcmd->qc_arg;
526*0Sstevel@tonic-gate 
527*0Sstevel@tonic-gate 	TNF_PROBE_1_DEBUG(hci1394_atreq_ack, HCI1394_TNF_HAL, "", tnf_uint,
528*0Sstevel@tonic-gate 	    atreq_ack, qcmd->qc_status);
529*0Sstevel@tonic-gate 
530*0Sstevel@tonic-gate 	/* save away the command completed timestamp for the services layer */
531*0Sstevel@tonic-gate 	hcicmd->ac_priv->ack_tstamp = qcmd->qc_timestamp;
532*0Sstevel@tonic-gate 
533*0Sstevel@tonic-gate 	/*
534*0Sstevel@tonic-gate 	 * Make sure this command has not already been processed. This command
535*0Sstevel@tonic-gate 	 * may have already received a response.  If the ACK was not an ACK
536*0Sstevel@tonic-gate 	 * pending, we have a HW error (i.e. The target HW sent a response to a
537*0Sstevel@tonic-gate 	 * non-pended request). There is a race condition where the software
538*0Sstevel@tonic-gate 	 * will see and complete a response before processing it's ACK Pending.
539*0Sstevel@tonic-gate 	 * This can only happen for ACK pendings. We have seen this race
540*0Sstevel@tonic-gate 	 * condition and response to a non-pended request during real-world
541*0Sstevel@tonic-gate 	 * testing :-)
542*0Sstevel@tonic-gate 	 */
543*0Sstevel@tonic-gate 	if (hcicmd->ac_state != HCI1394_CMD_STATE_IN_PROGRESS) {
544*0Sstevel@tonic-gate 		/*
545*0Sstevel@tonic-gate 		 * we already processed the ARRESP in arresp_process(), it
546*0Sstevel@tonic-gate 		 * better have been ACK pended. Otherwise the target device
547*0Sstevel@tonic-gate 		 * performed an illegal action.
548*0Sstevel@tonic-gate 		 */
549*0Sstevel@tonic-gate 		if (qcmd->qc_status == OHCI_ACK_PENDING) {
550*0Sstevel@tonic-gate 			/*
551*0Sstevel@tonic-gate 			 * Tell source that their command has completed. We're
552*0Sstevel@tonic-gate 			 * done with this command.
553*0Sstevel@tonic-gate 			 * NOTE: We use ac_status which was set in
554*0Sstevel@tonic-gate 			 * process_arresp()
555*0Sstevel@tonic-gate 			 */
556*0Sstevel@tonic-gate 			h1394_cmd_is_complete(
557*0Sstevel@tonic-gate 			    async_handle->as_drvinfo->di_sl_private,
558*0Sstevel@tonic-gate 			    hcicmd->ac_cmd, H1394_AT_REQ,
559*0Sstevel@tonic-gate 			    hcicmd->ac_status);
560*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_atreq_process_exit,
561*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
562*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
563*0Sstevel@tonic-gate 		/*
564*0Sstevel@tonic-gate 		 * This is a HW error.  Process the ACK like we never saw the
565*0Sstevel@tonic-gate 		 * response. We will do this below.
566*0Sstevel@tonic-gate 		 */
567*0Sstevel@tonic-gate 		} else {
568*0Sstevel@tonic-gate 			TNF_PROBE_1(hci1394_async_ack_fail,
569*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "", tnf_string, errmsg,
570*0Sstevel@tonic-gate 			    "response sent to non-pended ack");
571*0Sstevel@tonic-gate 		}
572*0Sstevel@tonic-gate 	}
573*0Sstevel@tonic-gate 
574*0Sstevel@tonic-gate 	/*
575*0Sstevel@tonic-gate 	 * if we got an ack pending, add it to the pending list and leave. We
576*0Sstevel@tonic-gate 	 * will either get an ARRESP or the pending list will timeout the
577*0Sstevel@tonic-gate 	 * response.
578*0Sstevel@tonic-gate 	 */
579*0Sstevel@tonic-gate 	if (qcmd->qc_status == OHCI_ACK_PENDING) {
580*0Sstevel@tonic-gate 		hcicmd->ac_state = HCI1394_CMD_STATE_PENDING;
581*0Sstevel@tonic-gate 		/* Add this command to the pending list */
582*0Sstevel@tonic-gate 		hcicmd->ac_plist_node.tln_addr = hcicmd;
583*0Sstevel@tonic-gate 		hci1394_tlist_add(async_handle->as_pending_list,
584*0Sstevel@tonic-gate 		    &hcicmd->ac_plist_node);
585*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_atreq_process_exit,
586*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
587*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
588*0Sstevel@tonic-gate 	}
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate 	/*
591*0Sstevel@tonic-gate 	 * setup our return command status based on the ACK from the HW. See the
592*0Sstevel@tonic-gate 	 * OpenHCI 1.0 spec (table 3.2 on pg. 18) for more information about
593*0Sstevel@tonic-gate 	 * these ACK/EVT's.
594*0Sstevel@tonic-gate 	 */
595*0Sstevel@tonic-gate 	switch (qcmd->qc_status) {
596*0Sstevel@tonic-gate 	case OHCI_ACK_COMPLETE:
597*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_SUCCESS;
598*0Sstevel@tonic-gate 		break;
599*0Sstevel@tonic-gate 
600*0Sstevel@tonic-gate 	/*
601*0Sstevel@tonic-gate 	 * we can get a nostatus during a bus reset (i.e. we shutdown the AT
602*0Sstevel@tonic-gate 	 * engine before it flushed all the commands)
603*0Sstevel@tonic-gate 	 */
604*0Sstevel@tonic-gate 	case OHCI_EVT_FLUSHED:
605*0Sstevel@tonic-gate 	case OHCI_EVT_NO_STATUS:
606*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EBUSRESET;
607*0Sstevel@tonic-gate 		break;
608*0Sstevel@tonic-gate 
609*0Sstevel@tonic-gate 	case OHCI_EVT_MISSING_ACK:
610*0Sstevel@tonic-gate 	case OHCI_EVT_TIMEOUT:
611*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
612*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
613*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
614*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
615*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
616*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ETIMEOUT;
617*0Sstevel@tonic-gate 		break;
618*0Sstevel@tonic-gate 
619*0Sstevel@tonic-gate 	case OHCI_ACK_BUSY_X:
620*0Sstevel@tonic-gate 	case OHCI_ACK_BUSY_A:
621*0Sstevel@tonic-gate 	case OHCI_ACK_BUSY_B:
622*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDEVICE_BUSY;
623*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
624*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
625*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
626*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
627*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
628*0Sstevel@tonic-gate 		break;
629*0Sstevel@tonic-gate 
630*0Sstevel@tonic-gate 	case OHCI_ACK_TARDY:
631*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDEVICE_POWERUP;
632*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
633*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
634*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
635*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
636*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
637*0Sstevel@tonic-gate 		break;
638*0Sstevel@tonic-gate 
639*0Sstevel@tonic-gate 	case OHCI_ACK_DATA_ERROR:
640*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDATA_ERROR;
641*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
642*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
643*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
644*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
645*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
646*0Sstevel@tonic-gate 		break;
647*0Sstevel@tonic-gate 
648*0Sstevel@tonic-gate 	case OHCI_ACK_TYPE_ERROR:
649*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ETYPE_ERROR;
650*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
651*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
652*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
653*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
654*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
655*0Sstevel@tonic-gate 		break;
656*0Sstevel@tonic-gate 
657*0Sstevel@tonic-gate 	case OHCI_ACK_CONFLICT_ERROR:
658*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ERSRC_CONFLICT;
659*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
660*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
661*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
662*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
663*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
664*0Sstevel@tonic-gate 		break;
665*0Sstevel@tonic-gate 
666*0Sstevel@tonic-gate 	case OHCI_ACK_ADDRESS_ERROR:
667*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EADDR_ERROR;
668*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
669*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
670*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
671*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
672*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
673*0Sstevel@tonic-gate 		break;
674*0Sstevel@tonic-gate 
675*0Sstevel@tonic-gate 	case OHCI_EVT_UNDERRUN:
676*0Sstevel@tonic-gate 	case OHCI_EVT_DATA_READ:
677*0Sstevel@tonic-gate 	case OHCI_EVT_TCODE_ERR:
678*0Sstevel@tonic-gate 	case OHCI_EVT_DESCRIPTOR_READ:
679*0Sstevel@tonic-gate 	case OHCI_EVT_UNKNOWN:
680*0Sstevel@tonic-gate 	default:
681*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EUNKNOWN_ERROR;
682*0Sstevel@tonic-gate 		TNF_PROBE_3(hci1394_atreq_ack_err, HCI1394_TNF_HAL_ERROR,
683*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
684*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(hcicmd->ac_tlabel.tbi_destination),
685*0Sstevel@tonic-gate 		    tnf_uint, tx_tlabel, hcicmd->ac_tlabel.tbi_tlabel,
686*0Sstevel@tonic-gate 		    tnf_uint, atreq_ack, qcmd->qc_status);
687*0Sstevel@tonic-gate 		break;
688*0Sstevel@tonic-gate 	}
689*0Sstevel@tonic-gate 
690*0Sstevel@tonic-gate 	/*
691*0Sstevel@tonic-gate 	 * Free the tlabel that was used for this transfer. We will not try and
692*0Sstevel@tonic-gate 	 * free the tlabel in the case that we already received a response or if
693*0Sstevel@tonic-gate 	 * we did not allocate one (PHY packet). If we already received a
694*0Sstevel@tonic-gate 	 * response, the tlabel would have been free'd in
695*0Sstevel@tonic-gate 	 * hci1394_async_arresp_process().
696*0Sstevel@tonic-gate 	 */
697*0Sstevel@tonic-gate 	if ((hcicmd->ac_state == HCI1394_CMD_STATE_IN_PROGRESS) &&
698*0Sstevel@tonic-gate 	    (hcicmd->ac_tlabel_alloc == B_TRUE)) {
699*0Sstevel@tonic-gate 		hci1394_tlabel_free(async_handle->as_tlabel,
700*0Sstevel@tonic-gate 		    &hcicmd->ac_tlabel);
701*0Sstevel@tonic-gate 	}
702*0Sstevel@tonic-gate 
703*0Sstevel@tonic-gate 	/*
704*0Sstevel@tonic-gate 	 * if we got anything other than and ACK pending, we are done w/ this
705*0Sstevel@tonic-gate 	 * transaction.
706*0Sstevel@tonic-gate 	 */
707*0Sstevel@tonic-gate 	hcicmd->ac_state = HCI1394_CMD_STATE_COMPLETED;
708*0Sstevel@tonic-gate 
709*0Sstevel@tonic-gate 	/* tell the services layer that the command has completed */
710*0Sstevel@tonic-gate 	h1394_cmd_is_complete(async_handle->as_drvinfo->di_sl_private,
711*0Sstevel@tonic-gate 	    hcicmd->ac_cmd, H1394_AT_REQ, cmd_status);
712*0Sstevel@tonic-gate 
713*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_process_exit,
714*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
715*0Sstevel@tonic-gate 
716*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
717*0Sstevel@tonic-gate }
718*0Sstevel@tonic-gate 
719*0Sstevel@tonic-gate 
720*0Sstevel@tonic-gate /*
721*0Sstevel@tonic-gate  * hci1394_async_arresp_process()
722*0Sstevel@tonic-gate  *    Process an arresp, if one has completed. This is called during interrupt
723*0Sstevel@tonic-gate  *    processing and will process a completed arresp. It returns status if an
724*0Sstevel@tonic-gate  *    arresp was processed so that the ISR knows that it needs to be called
725*0Sstevel@tonic-gate  *    again to see if another ARRESP has completed.
726*0Sstevel@tonic-gate  */
727*0Sstevel@tonic-gate int
hci1394_async_arresp_process(hci1394_async_handle_t async_handle,boolean_t * response_available)728*0Sstevel@tonic-gate hci1394_async_arresp_process(hci1394_async_handle_t async_handle,
729*0Sstevel@tonic-gate     boolean_t *response_available)
730*0Sstevel@tonic-gate {
731*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
732*0Sstevel@tonic-gate 	uint32_t *addr;
733*0Sstevel@tonic-gate 	int cmd_status;
734*0Sstevel@tonic-gate 	uint_t tcode;
735*0Sstevel@tonic-gate 	uint_t size;
736*0Sstevel@tonic-gate 	int status;
737*0Sstevel@tonic-gate 
738*0Sstevel@tonic-gate 
739*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
740*0Sstevel@tonic-gate 	ASSERT(response_available != NULL);
741*0Sstevel@tonic-gate 
742*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_process_enter,
743*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
744*0Sstevel@tonic-gate 
745*0Sstevel@tonic-gate 	/*
746*0Sstevel@tonic-gate 	 * See if there were any responses on ARRESP Q. A NULL means there
747*0Sstevel@tonic-gate 	 * were no responses on the Q. This call does NOT free up space. We
748*0Sstevel@tonic-gate 	 * need to do that later after we figure out how much space the
749*0Sstevel@tonic-gate 	 * response takes up.
750*0Sstevel@tonic-gate 	 */
751*0Sstevel@tonic-gate 	hci1394_q_ar_next(async_handle->as_arresp_q, &addr);
752*0Sstevel@tonic-gate 	if (addr == NULL) {
753*0Sstevel@tonic-gate 		*response_available = B_FALSE;
754*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_process_exit,
755*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
756*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
757*0Sstevel@tonic-gate 	}
758*0Sstevel@tonic-gate 
759*0Sstevel@tonic-gate 	/*
760*0Sstevel@tonic-gate 	 * We got a response. Lock out pending timeout callback from marking
761*0Sstevel@tonic-gate 	 * tlabel bad.
762*0Sstevel@tonic-gate 	 */
763*0Sstevel@tonic-gate 	*response_available = B_TRUE;
764*0Sstevel@tonic-gate 	mutex_enter(&async_handle->as_atomic_lookup);
765*0Sstevel@tonic-gate 
766*0Sstevel@tonic-gate 	/*
767*0Sstevel@tonic-gate 	 * Read in the response into the 1394 framework command. We could get a
768*0Sstevel@tonic-gate 	 * NULL for a command if we got a response with an error (i.e. tlabel
769*0Sstevel@tonic-gate 	 * that didn't match a request) This would be a successful read but with
770*0Sstevel@tonic-gate 	 * a NULL hcicmd returned. If we ever get a DDI_FAILURE, we will
771*0Sstevel@tonic-gate 	 * shutdown.
772*0Sstevel@tonic-gate 	 */
773*0Sstevel@tonic-gate 	status = hci1394_async_arresp_read(async_handle,
774*0Sstevel@tonic-gate 	    (hci1394_basic_pkt_t *)addr, &tcode, &hcicmd, &size);
775*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
776*0Sstevel@tonic-gate 		mutex_exit(&async_handle->as_atomic_lookup);
777*0Sstevel@tonic-gate 		h1394_error_detected(async_handle->as_drvinfo->di_sl_private,
778*0Sstevel@tonic-gate 		    H1394_SELF_INITIATED_SHUTDOWN, NULL);
779*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "hci1394(%d): driver shutdown: "
780*0Sstevel@tonic-gate 		    "unrecoverable error interrupt detected",
781*0Sstevel@tonic-gate 		    async_handle->as_drvinfo->di_instance);
782*0Sstevel@tonic-gate 		hci1394_shutdown(async_handle->as_drvinfo->di_dip);
783*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_arresp_read_fail,
784*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
785*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_process_exit,
786*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
787*0Sstevel@tonic-gate 		return (DDI_FAILURE);
788*0Sstevel@tonic-gate 	}
789*0Sstevel@tonic-gate 
790*0Sstevel@tonic-gate 	/* Free up the arresp Q space, we are done with the data */
791*0Sstevel@tonic-gate 	hci1394_q_ar_free(async_handle->as_arresp_q, size);
792*0Sstevel@tonic-gate 
793*0Sstevel@tonic-gate 	/*
794*0Sstevel@tonic-gate 	 * if we did not get a valid command response (i.e. we got a bad tlabel
795*0Sstevel@tonic-gate 	 * or something like that) we don't have anything else to do.  We will
796*0Sstevel@tonic-gate 	 * say that we processed a response and will return successfully. We
797*0Sstevel@tonic-gate 	 * still may have other responses on the Q.
798*0Sstevel@tonic-gate 	 */
799*0Sstevel@tonic-gate 	if (hcicmd == NULL) {
800*0Sstevel@tonic-gate 		mutex_exit(&async_handle->as_atomic_lookup);
801*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_process_exit,
802*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
803*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
804*0Sstevel@tonic-gate 	}
805*0Sstevel@tonic-gate 
806*0Sstevel@tonic-gate 	TNF_PROBE_1_DEBUG(hci1394_arresp_resp, HCI1394_TNF_HAL, "", tnf_uint,
807*0Sstevel@tonic-gate 	    atresp_resp, hcicmd->ac_status);
808*0Sstevel@tonic-gate 
809*0Sstevel@tonic-gate 	/*
810*0Sstevel@tonic-gate 	 * Make sure this is in the pending list. There is a small chance that
811*0Sstevel@tonic-gate 	 * we will see the response before we see the ACK PENDING. If it is the
812*0Sstevel@tonic-gate 	 * expected case, it is in the pending list.  We will remove it since
813*0Sstevel@tonic-gate 	 * we are done with the command.
814*0Sstevel@tonic-gate 	 *
815*0Sstevel@tonic-gate 	 * NOTE: there is a race condition here with the pending timeout.  Look
816*0Sstevel@tonic-gate 	 * at the comments before hci1394_async_atreq_process() for more info.
817*0Sstevel@tonic-gate 	 */
818*0Sstevel@tonic-gate 	if (hcicmd->ac_state == HCI1394_CMD_STATE_PENDING) {
819*0Sstevel@tonic-gate 		/* remove this transfer from our the pending list */
820*0Sstevel@tonic-gate 		status = hci1394_tlist_delete(async_handle->as_pending_list,
821*0Sstevel@tonic-gate 		    &hcicmd->ac_plist_node);
822*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
823*0Sstevel@tonic-gate 			mutex_exit(&async_handle->as_atomic_lookup);
824*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arresp_process_exit,
825*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
826*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
827*0Sstevel@tonic-gate 		}
828*0Sstevel@tonic-gate 	}
829*0Sstevel@tonic-gate 
830*0Sstevel@tonic-gate 	/* allow pending timeout callback to mark tlabel as bad */
831*0Sstevel@tonic-gate 	mutex_exit(&async_handle->as_atomic_lookup);
832*0Sstevel@tonic-gate 
833*0Sstevel@tonic-gate 	/*
834*0Sstevel@tonic-gate 	 * We got a valid response that we were able to read in. Free the tlabel
835*0Sstevel@tonic-gate 	 * that was used for this transfer.
836*0Sstevel@tonic-gate 	 */
837*0Sstevel@tonic-gate 	hci1394_tlabel_free(async_handle->as_tlabel, &hcicmd->ac_tlabel);
838*0Sstevel@tonic-gate 
839*0Sstevel@tonic-gate 	/*
840*0Sstevel@tonic-gate 	 * Setup our return command status based on the RESP or ACK or SW error.
841*0Sstevel@tonic-gate 	 * See the IEEE1394-1995 spec (6.2.4.10 on pg. 159) for more information
842*0Sstevel@tonic-gate 	 * on response codes. See the OpenHCI 1.0 spec (table 3.2 on pg. 18) for
843*0Sstevel@tonic-gate 	 * more information about ACK/EVT's. ac_status could have an IEEE1394
844*0Sstevel@tonic-gate 	 * response in it, a 1394 EVT/ACK, or a special cmd1394 error for a
845*0Sstevel@tonic-gate 	 * device error caught in SW (e.g. for a block read request that got a
846*0Sstevel@tonic-gate 	 * quadlet read response). We use a special mask to separate the
847*0Sstevel@tonic-gate 	 * ACK/EVT's from the responses (ASYNC_ARRESP_ACK_ERROR).
848*0Sstevel@tonic-gate 	 */
849*0Sstevel@tonic-gate 	switch (hcicmd->ac_status) {
850*0Sstevel@tonic-gate 	case IEEE1394_RESP_COMPLETE:
851*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_SUCCESS;
852*0Sstevel@tonic-gate 		break;
853*0Sstevel@tonic-gate 	case IEEE1394_RESP_DATA_ERROR:
854*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDATA_ERROR;
855*0Sstevel@tonic-gate 		break;
856*0Sstevel@tonic-gate 	case IEEE1394_RESP_TYPE_ERROR:
857*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ETYPE_ERROR;
858*0Sstevel@tonic-gate 		break;
859*0Sstevel@tonic-gate 	case IEEE1394_RESP_CONFLICT_ERROR:
860*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ERSRC_CONFLICT;
861*0Sstevel@tonic-gate 		break;
862*0Sstevel@tonic-gate 	case IEEE1394_RESP_ADDRESS_ERROR:
863*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EADDR_ERROR;
864*0Sstevel@tonic-gate 		break;
865*0Sstevel@tonic-gate 	case H1394_CMD_EDEVICE_ERROR:
866*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDEVICE_ERROR;
867*0Sstevel@tonic-gate 		break;
868*0Sstevel@tonic-gate 	case OHCI_ACK_DATA_ERROR | ASYNC_ARRESP_ACK_ERROR:
869*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDATA_ERROR;
870*0Sstevel@tonic-gate 		break;
871*0Sstevel@tonic-gate 	case OHCI_ACK_TYPE_ERROR | ASYNC_ARRESP_ACK_ERROR:
872*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ETYPE_ERROR;
873*0Sstevel@tonic-gate 		break;
874*0Sstevel@tonic-gate 	case OHCI_EVT_UNDERRUN | ASYNC_ARRESP_ACK_ERROR:
875*0Sstevel@tonic-gate 	case OHCI_EVT_DATA_READ | ASYNC_ARRESP_ACK_ERROR:
876*0Sstevel@tonic-gate 	case OHCI_EVT_TCODE_ERR | ASYNC_ARRESP_ACK_ERROR:
877*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EUNKNOWN_ERROR;
878*0Sstevel@tonic-gate 		break;
879*0Sstevel@tonic-gate 	default:
880*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EUNKNOWN_ERROR;
881*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_ack_err, HCI1394_TNF_HAL_ERROR,
882*0Sstevel@tonic-gate 		    "", tnf_uint, arresp_resp, hcicmd->ac_status);
883*0Sstevel@tonic-gate 		break;
884*0Sstevel@tonic-gate 	}
885*0Sstevel@tonic-gate 
886*0Sstevel@tonic-gate 	/*
887*0Sstevel@tonic-gate 	 * if we have already processed the atreq and put it on the pending Q
888*0Sstevel@tonic-gate 	 * (normal case), tell the services layer it completed.
889*0Sstevel@tonic-gate 	 */
890*0Sstevel@tonic-gate 	if (hcicmd->ac_state == HCI1394_CMD_STATE_PENDING) {
891*0Sstevel@tonic-gate 		/* Set state indicating that we are done with this cmd */
892*0Sstevel@tonic-gate 		hcicmd->ac_state = HCI1394_CMD_STATE_COMPLETED;
893*0Sstevel@tonic-gate 
894*0Sstevel@tonic-gate 		/* tell the services lyaer the command has completed */
895*0Sstevel@tonic-gate 		h1394_cmd_is_complete(async_handle->as_drvinfo->di_sl_private,
896*0Sstevel@tonic-gate 		    hcicmd->ac_cmd, H1394_AT_REQ, cmd_status);
897*0Sstevel@tonic-gate 
898*0Sstevel@tonic-gate 	/*
899*0Sstevel@tonic-gate 	 * We have not seen the atreq status yet.  We will call
900*0Sstevel@tonic-gate 	 * h1394_command_is_complete() in atreq_process() in case we did not get
901*0Sstevel@tonic-gate 	 * an ack pending (target HW error -> this is based on real world
902*0Sstevel@tonic-gate 	 * experience :-))
903*0Sstevel@tonic-gate 	 */
904*0Sstevel@tonic-gate 	} else {
905*0Sstevel@tonic-gate 		/* Set state indicating that we are done with this cmd */
906*0Sstevel@tonic-gate 		hcicmd->ac_state = HCI1394_CMD_STATE_COMPLETED;
907*0Sstevel@tonic-gate 
908*0Sstevel@tonic-gate 		/* save away the status for atreq_process() */
909*0Sstevel@tonic-gate 		hcicmd->ac_status = cmd_status;
910*0Sstevel@tonic-gate 	}
911*0Sstevel@tonic-gate 
912*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_process_exit,
913*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
914*0Sstevel@tonic-gate 
915*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
916*0Sstevel@tonic-gate }
917*0Sstevel@tonic-gate 
918*0Sstevel@tonic-gate 
919*0Sstevel@tonic-gate /*
920*0Sstevel@tonic-gate  * hci1394_async_arreq_process()
921*0Sstevel@tonic-gate  *    Process an arreq, if one has arrived. This is called during interrupt
922*0Sstevel@tonic-gate  *    processing and will process an arreq that has arrived. It returns status
923*0Sstevel@tonic-gate  *    if an arreq was processed so that the ISR knows that it needs to be
924*0Sstevel@tonic-gate  *    called again to see if another ARREQ has arrived.
925*0Sstevel@tonic-gate  */
926*0Sstevel@tonic-gate int
hci1394_async_arreq_process(hci1394_async_handle_t async_handle,boolean_t * request_available)927*0Sstevel@tonic-gate hci1394_async_arreq_process(hci1394_async_handle_t async_handle,
928*0Sstevel@tonic-gate     boolean_t *request_available)
929*0Sstevel@tonic-gate {
930*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
931*0Sstevel@tonic-gate 	uint32_t *addr;
932*0Sstevel@tonic-gate 	uint_t tcode;
933*0Sstevel@tonic-gate 	uint_t size;
934*0Sstevel@tonic-gate 	int status;
935*0Sstevel@tonic-gate 
936*0Sstevel@tonic-gate 
937*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
938*0Sstevel@tonic-gate 	ASSERT(request_available != NULL);
939*0Sstevel@tonic-gate 
940*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_process_enter,
941*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
942*0Sstevel@tonic-gate 
943*0Sstevel@tonic-gate 	/*
944*0Sstevel@tonic-gate 	 * See if there were any requests on ARREQ Q. A NULL means there
945*0Sstevel@tonic-gate 	 * were no requests on the Q. This call does NOT free up space. We
946*0Sstevel@tonic-gate 	 * need to do that later after we figure out how much space the
947*0Sstevel@tonic-gate 	 * request takes up.
948*0Sstevel@tonic-gate 	 */
949*0Sstevel@tonic-gate 	hci1394_q_ar_next(async_handle->as_arreq_q, &addr);
950*0Sstevel@tonic-gate 	if (addr == NULL) {
951*0Sstevel@tonic-gate 		*request_available = B_FALSE;
952*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_process_exit,
953*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
954*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
955*0Sstevel@tonic-gate 	}
956*0Sstevel@tonic-gate 
957*0Sstevel@tonic-gate 	/*
958*0Sstevel@tonic-gate 	 * We got a request. Read the request into a 1394 framework command.
959*0Sstevel@tonic-gate 	 * We could get a NULL for a command if we got a request with an error
960*0Sstevel@tonic-gate 	 * (i.e. ARREQ ACK was not ack pending or ack complete). This would be a
961*0Sstevel@tonic-gate 	 * successful read but with a NULL hcicmd returned. If we ever get a
962*0Sstevel@tonic-gate 	 * DDI_FAILURE, we will shutdown.
963*0Sstevel@tonic-gate 	 */
964*0Sstevel@tonic-gate 	*request_available = B_TRUE;
965*0Sstevel@tonic-gate 	status = hci1394_async_arreq_read(async_handle,
966*0Sstevel@tonic-gate 	    (hci1394_basic_pkt_t *)addr, &tcode, &hcicmd, &size);
967*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
968*0Sstevel@tonic-gate 		h1394_error_detected(async_handle->as_drvinfo->di_sl_private,
969*0Sstevel@tonic-gate 		    H1394_SELF_INITIATED_SHUTDOWN, NULL);
970*0Sstevel@tonic-gate 		cmn_err(CE_WARN, "hci1394(%d): driver shutdown: "
971*0Sstevel@tonic-gate 		    "unrecoverable error interrupt detected",
972*0Sstevel@tonic-gate 		    async_handle->as_drvinfo->di_instance);
973*0Sstevel@tonic-gate 		hci1394_shutdown(async_handle->as_drvinfo->di_dip);
974*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_arreq_read_fail,
975*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
976*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_process_exit,
977*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
978*0Sstevel@tonic-gate 		return (DDI_FAILURE);
979*0Sstevel@tonic-gate 	}
980*0Sstevel@tonic-gate 
981*0Sstevel@tonic-gate 	/* Free up the arreq Q space, we are done with the data */
982*0Sstevel@tonic-gate 	hci1394_q_ar_free(async_handle->as_arreq_q, size);
983*0Sstevel@tonic-gate 
984*0Sstevel@tonic-gate 	/*
985*0Sstevel@tonic-gate 	 * if we did not get a valid request (i.e. The ARREQ had a bad ACK
986*0Sstevel@tonic-gate 	 * or something like that) we don't have anything else to do.  We will
987*0Sstevel@tonic-gate 	 * say that we processed a request and will return successfully. We
988*0Sstevel@tonic-gate 	 * still may have other requests on the Q.
989*0Sstevel@tonic-gate 	 */
990*0Sstevel@tonic-gate 	if (hcicmd == NULL) {
991*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_process_exit,
992*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
993*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
994*0Sstevel@tonic-gate 	}
995*0Sstevel@tonic-gate 
996*0Sstevel@tonic-gate 	/*
997*0Sstevel@tonic-gate 	 * If as_flushing_arreq is set, we do not want to send any requests up
998*0Sstevel@tonic-gate 	 * to the Services Layer. We are flushing the ARREQ until we see a bus
999*0Sstevel@tonic-gate 	 * reset token that matches the current bus generation. Free up the
1000*0Sstevel@tonic-gate 	 * alloc'd command and return success.
1001*0Sstevel@tonic-gate 	 */
1002*0Sstevel@tonic-gate 	if (async_handle->as_flushing_arreq == B_TRUE) {
1003*0Sstevel@tonic-gate 		hci1394_async_response_complete(async_handle, hcicmd->ac_cmd,
1004*0Sstevel@tonic-gate 		    hcicmd->ac_priv);
1005*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_process_exit,
1006*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1007*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
1008*0Sstevel@tonic-gate 	}
1009*0Sstevel@tonic-gate 
1010*0Sstevel@tonic-gate 	TNF_PROBE_1_DEBUG(hci1394_arreq_ack, HCI1394_TNF_HAL, "", tnf_uint,
1011*0Sstevel@tonic-gate 	    arreq_ack, hcicmd->ac_status);
1012*0Sstevel@tonic-gate 
1013*0Sstevel@tonic-gate 	/*
1014*0Sstevel@tonic-gate 	 * We got a valid request that we were able to read in. Call into the
1015*0Sstevel@tonic-gate 	 * services layer based on the type of request.
1016*0Sstevel@tonic-gate 	 */
1017*0Sstevel@tonic-gate 	switch (tcode) {
1018*0Sstevel@tonic-gate 	case IEEE1394_TCODE_READ_QUADLET:
1019*0Sstevel@tonic-gate 	case IEEE1394_TCODE_READ_BLOCK:
1020*0Sstevel@tonic-gate 		h1394_read_request(async_handle->as_drvinfo->di_sl_private,
1021*0Sstevel@tonic-gate 		    hcicmd->ac_cmd);
1022*0Sstevel@tonic-gate 		break;
1023*0Sstevel@tonic-gate 	case IEEE1394_TCODE_WRITE_QUADLET:
1024*0Sstevel@tonic-gate 	case IEEE1394_TCODE_WRITE_BLOCK:
1025*0Sstevel@tonic-gate 		h1394_write_request(async_handle->as_drvinfo->di_sl_private,
1026*0Sstevel@tonic-gate 		    hcicmd->ac_cmd);
1027*0Sstevel@tonic-gate 		break;
1028*0Sstevel@tonic-gate 	case IEEE1394_TCODE_LOCK:
1029*0Sstevel@tonic-gate 		h1394_lock_request(async_handle->as_drvinfo->di_sl_private,
1030*0Sstevel@tonic-gate 		    hcicmd->ac_cmd);
1031*0Sstevel@tonic-gate 		break;
1032*0Sstevel@tonic-gate 	case IEEE1394_TCODE_PHY:
1033*0Sstevel@tonic-gate 		/*
1034*0Sstevel@tonic-gate 		 * OpenHCI only handles 1 PHY quadlet at a time. If a selfid
1035*0Sstevel@tonic-gate 		 * packet was received with multiple quadlets, we will treat
1036*0Sstevel@tonic-gate 		 * each quadlet as a separate call.  We do not notify the
1037*0Sstevel@tonic-gate 		 * services layer through the normal command interface, we will
1038*0Sstevel@tonic-gate 		 * treat it like a command internally and then free up the
1039*0Sstevel@tonic-gate 		 * command ourselves when we are done with it.
1040*0Sstevel@tonic-gate 		 */
1041*0Sstevel@tonic-gate 		h1394_phy_packet(async_handle->as_drvinfo->di_sl_private,
1042*0Sstevel@tonic-gate 		    &hcicmd->ac_cmd->cmd_u.q.quadlet_data, 1,
1043*0Sstevel@tonic-gate 		    hcicmd->ac_priv->recv_tstamp);
1044*0Sstevel@tonic-gate 		/* free alloc'd command */
1045*0Sstevel@tonic-gate 		hci1394_async_response_complete(async_handle, hcicmd->ac_cmd,
1046*0Sstevel@tonic-gate 		    hcicmd->ac_priv);
1047*0Sstevel@tonic-gate 		break;
1048*0Sstevel@tonic-gate 	default:
1049*0Sstevel@tonic-gate 		/* free alloc'd command */
1050*0Sstevel@tonic-gate 		hci1394_async_response_complete(async_handle, hcicmd->ac_cmd,
1051*0Sstevel@tonic-gate 		    hcicmd->ac_priv);
1052*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_arreq_tcode_err,
1053*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_uint, arreq_tcode, tcode);
1054*0Sstevel@tonic-gate 		break;
1055*0Sstevel@tonic-gate 	}
1056*0Sstevel@tonic-gate 
1057*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_process_exit,
1058*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1059*0Sstevel@tonic-gate 
1060*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
1061*0Sstevel@tonic-gate }
1062*0Sstevel@tonic-gate 
1063*0Sstevel@tonic-gate 
1064*0Sstevel@tonic-gate /*
1065*0Sstevel@tonic-gate  * hci1394_async_atresp_process()
1066*0Sstevel@tonic-gate  *    Process an atresp, if one has completed. This is called during interrupt
1067*0Sstevel@tonic-gate  *    processing and will process a completed atresp. It returns status if an
1068*0Sstevel@tonic-gate  *    atresp was processed so that the ISR knows that it needs to be called
1069*0Sstevel@tonic-gate  *    again to see if another ATRESP has completed. flush_q set to B_TRUE tells
1070*0Sstevel@tonic-gate  *    this routine to process all commands regardless of their completion
1071*0Sstevel@tonic-gate  *    status.  This is used during bus reset processing to remove all commands
1072*0Sstevel@tonic-gate  *    from the Q.
1073*0Sstevel@tonic-gate  */
1074*0Sstevel@tonic-gate int
hci1394_async_atresp_process(hci1394_async_handle_t async_handle,boolean_t flush_q,boolean_t * response_available)1075*0Sstevel@tonic-gate hci1394_async_atresp_process(hci1394_async_handle_t async_handle,
1076*0Sstevel@tonic-gate     boolean_t flush_q, boolean_t *response_available)
1077*0Sstevel@tonic-gate {
1078*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
1079*0Sstevel@tonic-gate 	hci1394_q_cmd_t *qcmd;
1080*0Sstevel@tonic-gate 	int cmd_status;
1081*0Sstevel@tonic-gate 
1082*0Sstevel@tonic-gate 
1083*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
1084*0Sstevel@tonic-gate 	ASSERT(response_available != NULL);
1085*0Sstevel@tonic-gate 
1086*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_process_enter,
1087*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1088*0Sstevel@tonic-gate 
1089*0Sstevel@tonic-gate 	/*
1090*0Sstevel@tonic-gate 	 * Get the next ATRESP that has completed (if one has). Space is free'd
1091*0Sstevel@tonic-gate 	 * up in atresp_q and atresp_data_q as part of this function call.
1092*0Sstevel@tonic-gate 	 */
1093*0Sstevel@tonic-gate 	hci1394_q_at_next(async_handle->as_atresp_q, flush_q, &qcmd);
1094*0Sstevel@tonic-gate 
1095*0Sstevel@tonic-gate 	/*
1096*0Sstevel@tonic-gate 	 * See if there were anymore requests on ATRESP Q. A NULL means there
1097*0Sstevel@tonic-gate 	 * were no completed commands left on the Q.
1098*0Sstevel@tonic-gate 	 */
1099*0Sstevel@tonic-gate 	if (qcmd == NULL) {
1100*0Sstevel@tonic-gate 		*response_available = B_FALSE;
1101*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_atresp_process_exit,
1102*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1103*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
1104*0Sstevel@tonic-gate 	}
1105*0Sstevel@tonic-gate 
1106*0Sstevel@tonic-gate 	/* There is a completed ATRESP, setup the HAL command pointer */
1107*0Sstevel@tonic-gate 	*response_available = B_TRUE;
1108*0Sstevel@tonic-gate 	hcicmd = (hci1394_async_cmd_t *)qcmd->qc_arg;
1109*0Sstevel@tonic-gate 
1110*0Sstevel@tonic-gate 	TNF_PROBE_1_DEBUG(hci1394_atresp_ack, HCI1394_TNF_HAL, "", tnf_uint,
1111*0Sstevel@tonic-gate 	    atresp_ack, qcmd->qc_status);
1112*0Sstevel@tonic-gate 
1113*0Sstevel@tonic-gate 	/* save away the command completed timestamp for the services layer */
1114*0Sstevel@tonic-gate 	hcicmd->ac_priv->ack_tstamp = qcmd->qc_timestamp;
1115*0Sstevel@tonic-gate 
1116*0Sstevel@tonic-gate 	/*
1117*0Sstevel@tonic-gate 	 * setup our return command status based on the ACK from the HW. See the
1118*0Sstevel@tonic-gate 	 * OpenHCI 1.0 spec (table 3.2 on pg. 18) for more information about
1119*0Sstevel@tonic-gate 	 * these ACK/EVT's.
1120*0Sstevel@tonic-gate 	 */
1121*0Sstevel@tonic-gate 	switch (qcmd->qc_status) {
1122*0Sstevel@tonic-gate 	case OHCI_ACK_COMPLETE:
1123*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_SUCCESS;
1124*0Sstevel@tonic-gate 		break;
1125*0Sstevel@tonic-gate 
1126*0Sstevel@tonic-gate 	/*
1127*0Sstevel@tonic-gate 	 * we can get a nostatus during a bus reset (i.e. we shutdown the AT
1128*0Sstevel@tonic-gate 	 * engine before it flushed all the commands)
1129*0Sstevel@tonic-gate 	 */
1130*0Sstevel@tonic-gate 	case OHCI_EVT_FLUSHED:
1131*0Sstevel@tonic-gate 	case OHCI_EVT_NO_STATUS:
1132*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EBUSRESET;
1133*0Sstevel@tonic-gate 		break;
1134*0Sstevel@tonic-gate 
1135*0Sstevel@tonic-gate 	case OHCI_EVT_MISSING_ACK:
1136*0Sstevel@tonic-gate 	case OHCI_EVT_TIMEOUT:
1137*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ETIMEOUT;
1138*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1139*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1140*0Sstevel@tonic-gate 		break;
1141*0Sstevel@tonic-gate 
1142*0Sstevel@tonic-gate 	case OHCI_ACK_BUSY_X:
1143*0Sstevel@tonic-gate 	case OHCI_ACK_BUSY_A:
1144*0Sstevel@tonic-gate 	case OHCI_ACK_BUSY_B:
1145*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDEVICE_BUSY;
1146*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1147*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1148*0Sstevel@tonic-gate 		break;
1149*0Sstevel@tonic-gate 
1150*0Sstevel@tonic-gate 	case OHCI_ACK_TARDY:
1151*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDEVICE_POWERUP;
1152*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1153*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1154*0Sstevel@tonic-gate 		break;
1155*0Sstevel@tonic-gate 
1156*0Sstevel@tonic-gate 	case OHCI_ACK_DATA_ERROR:
1157*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EDATA_ERROR;
1158*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1159*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1160*0Sstevel@tonic-gate 		break;
1161*0Sstevel@tonic-gate 
1162*0Sstevel@tonic-gate 	case OHCI_ACK_TYPE_ERROR:
1163*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ETYPE_ERROR;
1164*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1165*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1166*0Sstevel@tonic-gate 		break;
1167*0Sstevel@tonic-gate 
1168*0Sstevel@tonic-gate 	case OHCI_ACK_CONFLICT_ERROR:
1169*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_ERSRC_CONFLICT;
1170*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1171*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1172*0Sstevel@tonic-gate 		break;
1173*0Sstevel@tonic-gate 
1174*0Sstevel@tonic-gate 	case OHCI_ACK_ADDRESS_ERROR:
1175*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EADDR_ERROR;
1176*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1177*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1178*0Sstevel@tonic-gate 		break;
1179*0Sstevel@tonic-gate 
1180*0Sstevel@tonic-gate 	case OHCI_EVT_UNKNOWN:
1181*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EUNKNOWN_ERROR;
1182*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1183*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1184*0Sstevel@tonic-gate 		break;
1185*0Sstevel@tonic-gate 
1186*0Sstevel@tonic-gate 	case OHCI_EVT_UNDERRUN:
1187*0Sstevel@tonic-gate 	case OHCI_EVT_DATA_READ:
1188*0Sstevel@tonic-gate 	case OHCI_EVT_TCODE_ERR:
1189*0Sstevel@tonic-gate 	case OHCI_EVT_DESCRIPTOR_READ:
1190*0Sstevel@tonic-gate 	default:
1191*0Sstevel@tonic-gate 		cmd_status = H1394_CMD_EUNKNOWN_ERROR;
1192*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_atresp_ack_err, HCI1394_TNF_HAL_ERROR,
1193*0Sstevel@tonic-gate 		    "", tnf_uint, atresp_ack, qcmd->qc_status);
1194*0Sstevel@tonic-gate 		break;
1195*0Sstevel@tonic-gate 	}
1196*0Sstevel@tonic-gate 
1197*0Sstevel@tonic-gate 	/* tell the services layer that the command has completed */
1198*0Sstevel@tonic-gate 	h1394_cmd_is_complete(async_handle->as_drvinfo->di_sl_private,
1199*0Sstevel@tonic-gate 	    hcicmd->ac_cmd, H1394_AT_RESP, cmd_status);
1200*0Sstevel@tonic-gate 
1201*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_process_exit,
1202*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1203*0Sstevel@tonic-gate 
1204*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
1205*0Sstevel@tonic-gate }
1206*0Sstevel@tonic-gate 
1207*0Sstevel@tonic-gate 
1208*0Sstevel@tonic-gate /*
1209*0Sstevel@tonic-gate  * hci1394_async_arresp_read()
1210*0Sstevel@tonic-gate  *    Read ARRESP in from memory into 1394 Framework command. We read the tcode
1211*0Sstevel@tonic-gate  *    which tells us which kind of arresp the packet is, get the size of the
1212*0Sstevel@tonic-gate  *    response, read in the sender, tlabel, and response code, and then
1213*0Sstevel@tonic-gate  *    lookup the command based on the sender and tlabel. Once we get the command
1214*0Sstevel@tonic-gate  *    (corresponding to the ATREQ), we will copy the rest of the response into
1215*0Sstevel@tonic-gate  *    that command.
1216*0Sstevel@tonic-gate  *
1217*0Sstevel@tonic-gate  *    The only time this routine should return DDI_FAILURE is if it was unable
1218*0Sstevel@tonic-gate  *    to maintain a good state in the ARRESP Q (i.e. an unknown response was
1219*0Sstevel@tonic-gate  *    received and we can not cleanup after it.)  If we detect a recoverable
1220*0Sstevel@tonic-gate  *    error, and it doesn't make sense to pass the response up to the Services
1221*0Sstevel@tonic-gate  *    Layer, we should return DDI_SUCCESS with hcicmd = NULL.
1222*0Sstevel@tonic-gate  */
1223*0Sstevel@tonic-gate static int
hci1394_async_arresp_read(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,uint_t * tcode,hci1394_async_cmd_t ** hcicmd,uint_t * size)1224*0Sstevel@tonic-gate hci1394_async_arresp_read(hci1394_async_handle_t async_handle,
1225*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt,  uint_t *tcode, hci1394_async_cmd_t **hcicmd,
1226*0Sstevel@tonic-gate     uint_t *size)
1227*0Sstevel@tonic-gate {
1228*0Sstevel@tonic-gate 	hci1394_tlabel_info_t ac_tlabel;
1229*0Sstevel@tonic-gate 	h1394_cmd_priv_t *cmd_priv;
1230*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
1231*0Sstevel@tonic-gate 	uint32_t *status_addr;
1232*0Sstevel@tonic-gate 	uint_t data_length;
1233*0Sstevel@tonic-gate 	uint32_t quadlet;
1234*0Sstevel@tonic-gate 	void *command;
1235*0Sstevel@tonic-gate 	uint_t rcode;
1236*0Sstevel@tonic-gate 	uint_t ack;
1237*0Sstevel@tonic-gate 	int status;
1238*0Sstevel@tonic-gate 
1239*0Sstevel@tonic-gate 
1240*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
1241*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
1242*0Sstevel@tonic-gate 	ASSERT(tcode != NULL);
1243*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
1244*0Sstevel@tonic-gate 	ASSERT(size != NULL);
1245*0Sstevel@tonic-gate 
1246*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_enter,
1247*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1248*0Sstevel@tonic-gate 
1249*0Sstevel@tonic-gate 	/* read in the arresp tcode */
1250*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arresp_q, &pkt->q1);
1251*0Sstevel@tonic-gate 	*tcode = HCI1394_DESC_TCODE_GET(quadlet);
1252*0Sstevel@tonic-gate 
1253*0Sstevel@tonic-gate 	/* Get the size of the arresp */
1254*0Sstevel@tonic-gate 	status = hci1394_async_arresp_size_get(*tcode,
1255*0Sstevel@tonic-gate 	    async_handle->as_arresp_q, &pkt->q1, size);
1256*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
1257*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_arresp_read_size_fail,
1258*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
1259*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1260*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1261*0Sstevel@tonic-gate 		return (DDI_FAILURE);
1262*0Sstevel@tonic-gate 	}
1263*0Sstevel@tonic-gate 
1264*0Sstevel@tonic-gate 	/* Read in the tlabel, destination, and rcode (response code) */
1265*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arresp_q, &pkt->q1);
1266*0Sstevel@tonic-gate 	ac_tlabel.tbi_tlabel = HCI1394_DESC_TLABEL_GET(quadlet);
1267*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arresp_q, &pkt->q2);
1268*0Sstevel@tonic-gate 	ac_tlabel.tbi_destination = HCI1394_DESC_DESTID_GET(quadlet);
1269*0Sstevel@tonic-gate 	rcode = HCI1394_DESC_RCODE_GET(quadlet);
1270*0Sstevel@tonic-gate 
1271*0Sstevel@tonic-gate 	/* Lookup the ATREQ framework command this response goes with */
1272*0Sstevel@tonic-gate 	hci1394_tlabel_lookup(async_handle->as_tlabel, &ac_tlabel, &command);
1273*0Sstevel@tonic-gate 
1274*0Sstevel@tonic-gate 	/*
1275*0Sstevel@tonic-gate 	 * If there is not a cooresponding ATREQ command, this is an error. We
1276*0Sstevel@tonic-gate 	 * will ignore this response but still return success so we cleanup
1277*0Sstevel@tonic-gate 	 * after it and go on with other arresp's. This could happend if a
1278*0Sstevel@tonic-gate 	 * response was sent after the command has timed out or if the target
1279*0Sstevel@tonic-gate 	 * device is misbehaving. (we have seen both cases)
1280*0Sstevel@tonic-gate 	 */
1281*0Sstevel@tonic-gate 	*hcicmd = (hci1394_async_cmd_t *)command;
1282*0Sstevel@tonic-gate 	if ((*hcicmd) == NULL) {
1283*0Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_invalid_tlabel, HCI1394_TNF_HAL_ERROR,
1284*0Sstevel@tonic-gate 		    "", tnf_uint, nodeid,
1285*0Sstevel@tonic-gate 		    IEEE1394_NODE_NUM(ac_tlabel.tbi_destination), tnf_uint,
1286*0Sstevel@tonic-gate 		    rx_tlabel, ac_tlabel.tbi_tlabel);
1287*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1288*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1289*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
1290*0Sstevel@tonic-gate 	}
1291*0Sstevel@tonic-gate 
1292*0Sstevel@tonic-gate 	/*
1293*0Sstevel@tonic-gate 	 * copy the response code into the hal private command space. Setup
1294*0Sstevel@tonic-gate 	 * shortcuts to the 1394 framework command (cmd) and the HAL/SL private
1295*0Sstevel@tonic-gate 	 * area (cmd_priv). A command is made up of 4 parts. There is the public
1296*0Sstevel@tonic-gate 	 * part which is accessable to the target driver, there is the Services
1297*0Sstevel@tonic-gate 	 * Layer private part which is only accessible to the services layer,
1298*0Sstevel@tonic-gate 	 * there is the SL/HAL private area which is where the SL and HAL share
1299*0Sstevel@tonic-gate 	 * information about a particular command, and there is the HAL private
1300*0Sstevel@tonic-gate 	 * area where we keep track of our command specific state information.
1301*0Sstevel@tonic-gate 	 */
1302*0Sstevel@tonic-gate 	(*hcicmd)->ac_status = rcode;
1303*0Sstevel@tonic-gate 	cmd = (*hcicmd)->ac_cmd;
1304*0Sstevel@tonic-gate 	cmd_priv = (*hcicmd)->ac_priv;
1305*0Sstevel@tonic-gate 
1306*0Sstevel@tonic-gate 	/*
1307*0Sstevel@tonic-gate 	 * Calculate the address where the status of the ARRESP and timestamp is
1308*0Sstevel@tonic-gate 	 * kept at.  It is the last quadlet in the response. Save away the
1309*0Sstevel@tonic-gate 	 * timestamp.
1310*0Sstevel@tonic-gate 	 */
1311*0Sstevel@tonic-gate 	status_addr = (uint32_t *)((uintptr_t)pkt + (uintptr_t)*size -
1312*0Sstevel@tonic-gate 	    (uintptr_t)IEEE1394_QUADLET);
1313*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arresp_q, status_addr);
1314*0Sstevel@tonic-gate 	cmd_priv->recv_tstamp = HCI1394_DESC_TIMESTAMP_GET(quadlet);
1315*0Sstevel@tonic-gate 
1316*0Sstevel@tonic-gate 	/*
1317*0Sstevel@tonic-gate 	 * if we did not get an ACK_COMPLETE, we will use the ack error instead
1318*0Sstevel@tonic-gate 	 * of the response in the packet for our status. We use special mask to
1319*0Sstevel@tonic-gate 	 * separate the reponses from the ACKs (ASYNC_ARRESP_ACK_ERROR). We will
1320*0Sstevel@tonic-gate 	 * return success with hcicmd set to the command so that this error gets
1321*0Sstevel@tonic-gate 	 * sent up to the Services Layer.
1322*0Sstevel@tonic-gate 	 */
1323*0Sstevel@tonic-gate 	ack = HCI1394_DESC_EVT_GET(quadlet);
1324*0Sstevel@tonic-gate 	if (ack != OHCI_ACK_COMPLETE) {
1325*0Sstevel@tonic-gate 		/* use the ack error instead of rcode for the command status */
1326*0Sstevel@tonic-gate 		(*hcicmd)->ac_status = ack | ASYNC_ARRESP_ACK_ERROR;
1327*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_arresp_bad_ack, HCI1394_TNF_HAL_ERROR,
1328*0Sstevel@tonic-gate 		    "", tnf_uint, arresp_ack, ack);
1329*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1330*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1331*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
1332*0Sstevel@tonic-gate 	}
1333*0Sstevel@tonic-gate 
1334*0Sstevel@tonic-gate 	TNF_PROBE_1_DEBUG(hci1394_atrresp_resp, HCI1394_TNF_HAL, "", tnf_uint,
1335*0Sstevel@tonic-gate 	    arresp_resp, rcode);
1336*0Sstevel@tonic-gate 
1337*0Sstevel@tonic-gate 	/*
1338*0Sstevel@tonic-gate 	 * If we get to this point we have gotten a valid ACK on the response
1339*0Sstevel@tonic-gate 	 * and have matched up the response with an ATREQ. Now we check the
1340*0Sstevel@tonic-gate 	 * response code. If it is not resp_complete, we do not have anything
1341*0Sstevel@tonic-gate 	 * left to look at in the response. Return successfully.
1342*0Sstevel@tonic-gate 	 */
1343*0Sstevel@tonic-gate 	if (rcode != IEEE1394_RESP_COMPLETE) {
1344*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1345*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1346*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
1347*0Sstevel@tonic-gate 	}
1348*0Sstevel@tonic-gate 
1349*0Sstevel@tonic-gate 	/*
1350*0Sstevel@tonic-gate 	 * Read the rest of the response (based on which kind of response it is)
1351*0Sstevel@tonic-gate 	 * into the 1394 framework command. In all of the different responses,
1352*0Sstevel@tonic-gate 	 * we check to make sure the response matches the original request. We
1353*0Sstevel@tonic-gate 	 * originally did not have this check but found a device or two which
1354*0Sstevel@tonic-gate 	 * did not behave very well and would cause us to corrupt our commands.
1355*0Sstevel@tonic-gate 	 * Now we check :-) We will return success when we get this error since
1356*0Sstevel@tonic-gate 	 * we can recover from it.
1357*0Sstevel@tonic-gate 	 */
1358*0Sstevel@tonic-gate 	switch (*tcode) {
1359*0Sstevel@tonic-gate 	case IEEE1394_TCODE_WRITE_RESP:
1360*0Sstevel@tonic-gate 		/*
1361*0Sstevel@tonic-gate 		 * make sure the ATREQ was a quadlet/block write. The same
1362*0Sstevel@tonic-gate 		 * response is sent back for those two type of ATREQs.
1363*0Sstevel@tonic-gate 		 */
1364*0Sstevel@tonic-gate 		if ((cmd->cmd_type != CMD1394_ASYNCH_WR_QUAD) &&
1365*0Sstevel@tonic-gate 		    (cmd->cmd_type != CMD1394_ASYNCH_WR_BLOCK)) {
1366*0Sstevel@tonic-gate 			(*hcicmd)->ac_status = H1394_CMD_EDEVICE_ERROR;
1367*0Sstevel@tonic-gate 			TNF_PROBE_2(hci1394_async_arresp_lockresp_fail,
1368*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "", tnf_string, errmsg,
1369*0Sstevel@tonic-gate 			    "Invalid response sent for write request", tnf_uint,
1370*0Sstevel@tonic-gate 			    arresp_tcode, *tcode);
1371*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1372*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1373*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1374*0Sstevel@tonic-gate 		}
1375*0Sstevel@tonic-gate 		break;
1376*0Sstevel@tonic-gate 
1377*0Sstevel@tonic-gate 	case IEEE1394_TCODE_READ_QUADLET_RESP:
1378*0Sstevel@tonic-gate 		/* make sure the ATREQ was a quadlet read */
1379*0Sstevel@tonic-gate 		if (cmd->cmd_type != CMD1394_ASYNCH_RD_QUAD) {
1380*0Sstevel@tonic-gate 			(*hcicmd)->ac_status = H1394_CMD_EDEVICE_ERROR;
1381*0Sstevel@tonic-gate 			TNF_PROBE_2(hci1394_async_arresp_lockresp_fail,
1382*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "", tnf_string, errmsg,
1383*0Sstevel@tonic-gate 			    "Invalid response sent for qrd request", tnf_uint,
1384*0Sstevel@tonic-gate 			    arresp_tcode, *tcode);
1385*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1386*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1387*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1388*0Sstevel@tonic-gate 		}
1389*0Sstevel@tonic-gate 
1390*0Sstevel@tonic-gate 		/*
1391*0Sstevel@tonic-gate 		 * read the quadlet read response in.  Data is treated as a byte
1392*0Sstevel@tonic-gate 		 * stream.
1393*0Sstevel@tonic-gate 		 */
1394*0Sstevel@tonic-gate 		hci1394_q_ar_rep_get8(async_handle->as_arresp_q,
1395*0Sstevel@tonic-gate 		    (uint8_t *)&cmd->cmd_u.q.quadlet_data,
1396*0Sstevel@tonic-gate 		    (uint8_t *)&pkt->q4, IEEE1394_QUADLET);
1397*0Sstevel@tonic-gate 		break;
1398*0Sstevel@tonic-gate 
1399*0Sstevel@tonic-gate 	case IEEE1394_TCODE_READ_BLOCK_RESP:
1400*0Sstevel@tonic-gate 		/* make sure the ATREQ was a block read */
1401*0Sstevel@tonic-gate 		if (cmd->cmd_type != CMD1394_ASYNCH_RD_BLOCK) {
1402*0Sstevel@tonic-gate 			(*hcicmd)->ac_status = H1394_CMD_EDEVICE_ERROR;
1403*0Sstevel@tonic-gate 			TNF_PROBE_2(hci1394_async_arresp_lockresp_fail,
1404*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "", tnf_string, errmsg,
1405*0Sstevel@tonic-gate 			    "Invalid response sent for brd request", tnf_uint,
1406*0Sstevel@tonic-gate 			    arresp_tcode, *tcode);
1407*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1408*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1409*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1410*0Sstevel@tonic-gate 		}
1411*0Sstevel@tonic-gate 
1412*0Sstevel@tonic-gate 		/*
1413*0Sstevel@tonic-gate 		 * read in the data length.  Make sure the data length is the
1414*0Sstevel@tonic-gate 		 * same size as the read block request size that went out.
1415*0Sstevel@tonic-gate 		 */
1416*0Sstevel@tonic-gate 		quadlet = hci1394_q_ar_get32(async_handle->as_arresp_q,
1417*0Sstevel@tonic-gate 		    &pkt->q4);
1418*0Sstevel@tonic-gate 		data_length = HCI1394_DESC_DATALEN_GET(quadlet);
1419*0Sstevel@tonic-gate 		if (data_length != cmd_priv->mblk.length) {
1420*0Sstevel@tonic-gate 			(*hcicmd)->ac_status = H1394_CMD_EDEVICE_ERROR;
1421*0Sstevel@tonic-gate 			TNF_PROBE_3(hci1394_async_arresp_brdsz_fail,
1422*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "", tnf_string,
1423*0Sstevel@tonic-gate 			    errmsg, "Block read response size is bad",
1424*0Sstevel@tonic-gate 			    tnf_uint, requested_size, cmd_priv->mblk.length,
1425*0Sstevel@tonic-gate 			    tnf_uint, response_size, data_length);
1426*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1427*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1428*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1429*0Sstevel@tonic-gate 		}
1430*0Sstevel@tonic-gate 
1431*0Sstevel@tonic-gate 		/* Copy the read block data into the command mblk */
1432*0Sstevel@tonic-gate 		hci1394_q_ar_copy_to_mblk(async_handle->as_arresp_q,
1433*0Sstevel@tonic-gate 		    (uint8_t *)&pkt->q5, &cmd_priv->mblk);
1434*0Sstevel@tonic-gate 		break;
1435*0Sstevel@tonic-gate 
1436*0Sstevel@tonic-gate 	case IEEE1394_TCODE_LOCK_RESP:
1437*0Sstevel@tonic-gate 		/* read in the data length */
1438*0Sstevel@tonic-gate 		quadlet = hci1394_q_ar_get32(async_handle->as_arresp_q,
1439*0Sstevel@tonic-gate 		    &pkt->q4);
1440*0Sstevel@tonic-gate 		data_length = HCI1394_DESC_DATALEN_GET(quadlet);
1441*0Sstevel@tonic-gate 
1442*0Sstevel@tonic-gate 		if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_32) {
1443*0Sstevel@tonic-gate 			/*
1444*0Sstevel@tonic-gate 			 * read in the data length.  Make sure the data length
1445*0Sstevel@tonic-gate 			 * is the valid for a lock32 response (1 quadlet)
1446*0Sstevel@tonic-gate 			 */
1447*0Sstevel@tonic-gate 			if (data_length != IEEE1394_QUADLET) {
1448*0Sstevel@tonic-gate 				(*hcicmd)->ac_status = H1394_CMD_EDEVICE_ERROR;
1449*0Sstevel@tonic-gate 				TNF_PROBE_2(hci1394_async_arresp_l32sz_fail,
1450*0Sstevel@tonic-gate 				    HCI1394_TNF_HAL_STACK, "", tnf_string,
1451*0Sstevel@tonic-gate 				    errmsg, "Invalid size for lock32 response",
1452*0Sstevel@tonic-gate 				    tnf_uint, data_size, data_length);
1453*0Sstevel@tonic-gate 				TNF_PROBE_0_DEBUG(
1454*0Sstevel@tonic-gate 				    hci1394_async_arresp_read_exit,
1455*0Sstevel@tonic-gate 				    HCI1394_TNF_HAL_STACK, "");
1456*0Sstevel@tonic-gate 				return (DDI_SUCCESS);
1457*0Sstevel@tonic-gate 			}
1458*0Sstevel@tonic-gate 
1459*0Sstevel@tonic-gate 			/*
1460*0Sstevel@tonic-gate 			 * read the lock32 response in. Data is treated as a
1461*0Sstevel@tonic-gate 			 * byte stream unless it is an arithmetic lock
1462*0Sstevel@tonic-gate 			 * operation. In that case we treat data like a 32-bit
1463*0Sstevel@tonic-gate 			 * word.
1464*0Sstevel@tonic-gate 			 */
1465*0Sstevel@tonic-gate 			hci1394_q_ar_rep_get8(async_handle->as_arresp_q,
1466*0Sstevel@tonic-gate 			    (uint8_t *)&cmd->cmd_u.l32.old_value,
1467*0Sstevel@tonic-gate 			    (uint8_t *)&pkt->q5, IEEE1394_QUADLET);
1468*0Sstevel@tonic-gate 			cmd->cmd_u.l32.old_value = HCI1394_ARITH_LOCK_SWAP32(
1469*0Sstevel@tonic-gate 			    cmd->cmd_u.l32.lock_type, cmd->cmd_u.l32.old_value);
1470*0Sstevel@tonic-gate 
1471*0Sstevel@tonic-gate 		} else if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_64) {
1472*0Sstevel@tonic-gate 			/*
1473*0Sstevel@tonic-gate 			 * read in the data length.  Make sure the data length
1474*0Sstevel@tonic-gate 			 * is the valid for a lock64 response (1 octlet)
1475*0Sstevel@tonic-gate 			 */
1476*0Sstevel@tonic-gate 			if (data_length != IEEE1394_OCTLET) {
1477*0Sstevel@tonic-gate 				(*hcicmd)->ac_status = H1394_CMD_EDEVICE_ERROR;
1478*0Sstevel@tonic-gate 				TNF_PROBE_2(hci1394_async_arresp_l64sz_fail,
1479*0Sstevel@tonic-gate 				    HCI1394_TNF_HAL_STACK, "", tnf_string,
1480*0Sstevel@tonic-gate 				    errmsg, "Invalid size for lock64 response",
1481*0Sstevel@tonic-gate 				    tnf_uint, data_size, data_length);
1482*0Sstevel@tonic-gate 				TNF_PROBE_0_DEBUG(
1483*0Sstevel@tonic-gate 				    hci1394_async_arresp_read_exit,
1484*0Sstevel@tonic-gate 				    HCI1394_TNF_HAL_STACK, "");
1485*0Sstevel@tonic-gate 				return (DDI_SUCCESS);
1486*0Sstevel@tonic-gate 			}
1487*0Sstevel@tonic-gate 
1488*0Sstevel@tonic-gate 			/*
1489*0Sstevel@tonic-gate 			 * read the lock64 response in. Data is treated as a
1490*0Sstevel@tonic-gate 			 * byte stream unless it is an arithmetic lock
1491*0Sstevel@tonic-gate 			 * operation. In that case we treat data like a 64-bit
1492*0Sstevel@tonic-gate 			 * word.
1493*0Sstevel@tonic-gate 			 */
1494*0Sstevel@tonic-gate 			hci1394_q_ar_rep_get8(async_handle->as_arresp_q,
1495*0Sstevel@tonic-gate 			    (uint8_t *)&cmd->cmd_u.l64.old_value,
1496*0Sstevel@tonic-gate 			    (uint8_t *)&pkt->q5, IEEE1394_OCTLET);
1497*0Sstevel@tonic-gate 			cmd->cmd_u.l64.old_value = HCI1394_ARITH_LOCK_SWAP64(
1498*0Sstevel@tonic-gate 			    cmd->cmd_u.l64.lock_type, cmd->cmd_u.l64.old_value);
1499*0Sstevel@tonic-gate 
1500*0Sstevel@tonic-gate 		/*
1501*0Sstevel@tonic-gate 		 * we sent out a request that was NOT a lock request and got
1502*0Sstevel@tonic-gate 		 * back a lock response.
1503*0Sstevel@tonic-gate 		 */
1504*0Sstevel@tonic-gate 		} else {
1505*0Sstevel@tonic-gate 			(*hcicmd)->ac_status = H1394_CMD_EDEVICE_ERROR;
1506*0Sstevel@tonic-gate 			TNF_PROBE_2(hci1394_async_arresp_lockresp_fail,
1507*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "", tnf_string, errmsg,
1508*0Sstevel@tonic-gate 			    "Invalid response sent for lock request", tnf_uint,
1509*0Sstevel@tonic-gate 			    arresp_tcode, *tcode);
1510*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1511*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1512*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1513*0Sstevel@tonic-gate 		}
1514*0Sstevel@tonic-gate 		break;
1515*0Sstevel@tonic-gate 
1516*0Sstevel@tonic-gate 	default:
1517*0Sstevel@tonic-gate 		/* we got a tcode that we don't know about. Return error */
1518*0Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_async_arresp_tcode_err,
1519*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_string, errmsg,
1520*0Sstevel@tonic-gate 		    "unknown ARRESP received", tnf_uint, arresp_tcode, *tcode);
1521*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1522*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1523*0Sstevel@tonic-gate 		return (DDI_FAILURE);
1524*0Sstevel@tonic-gate 	}
1525*0Sstevel@tonic-gate 
1526*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_read_exit,
1527*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1528*0Sstevel@tonic-gate 
1529*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
1530*0Sstevel@tonic-gate }
1531*0Sstevel@tonic-gate 
1532*0Sstevel@tonic-gate 
1533*0Sstevel@tonic-gate /*
1534*0Sstevel@tonic-gate  * hci1394_async_arreq_read()
1535*0Sstevel@tonic-gate  *    Read ARREQ in from memory into a 1394 Framework command. Allocate a 1394
1536*0Sstevel@tonic-gate  *    framework command, read in the ARREQ, and before passing it up to the
1537*0Sstevel@tonic-gate  *    services layer, see if it was a valid broadcast request.
1538*0Sstevel@tonic-gate  *
1539*0Sstevel@tonic-gate  *    The only time this routine should return DDI_FAILURE is if it was unable
1540*0Sstevel@tonic-gate  *    to maintain a good state in the ARREQ Q (i.e. an unknown request was
1541*0Sstevel@tonic-gate  *    received and we can not cleanup after it.)  If we detect a recoverable
1542*0Sstevel@tonic-gate  *    error we should return DDI_SUCCESS with hcicmd = NULL.
1543*0Sstevel@tonic-gate  */
1544*0Sstevel@tonic-gate static int
hci1394_async_arreq_read(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,uint_t * tcode,hci1394_async_cmd_t ** hcicmd,uint_t * size)1545*0Sstevel@tonic-gate hci1394_async_arreq_read(hci1394_async_handle_t async_handle,
1546*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, uint_t *tcode, hci1394_async_cmd_t **hcicmd,
1547*0Sstevel@tonic-gate     uint_t *size)
1548*0Sstevel@tonic-gate {
1549*0Sstevel@tonic-gate 	h1394_cmd_priv_t *cmd_priv;
1550*0Sstevel@tonic-gate 	boolean_t is_reset_token;
1551*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
1552*0Sstevel@tonic-gate 	uint32_t quadlet;
1553*0Sstevel@tonic-gate 	int status;
1554*0Sstevel@tonic-gate 
1555*0Sstevel@tonic-gate 
1556*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
1557*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
1558*0Sstevel@tonic-gate 	ASSERT(tcode != NULL);
1559*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
1560*0Sstevel@tonic-gate 	ASSERT(size != NULL);
1561*0Sstevel@tonic-gate 
1562*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_enter,
1563*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1564*0Sstevel@tonic-gate 
1565*0Sstevel@tonic-gate 	/* read in the arresp tcode */
1566*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q1);
1567*0Sstevel@tonic-gate 	*tcode = HCI1394_DESC_TCODE_GET(quadlet);
1568*0Sstevel@tonic-gate 
1569*0Sstevel@tonic-gate 	/*
1570*0Sstevel@tonic-gate 	 * Allocated 1394 framework command.  The Services layer takes care of
1571*0Sstevel@tonic-gate 	 * cacheing commands. This is called during interrupt processing so we
1572*0Sstevel@tonic-gate 	 * do not want to sleep.
1573*0Sstevel@tonic-gate 	 */
1574*0Sstevel@tonic-gate 	status = h1394_alloc_cmd(async_handle->as_drvinfo->di_sl_private,
1575*0Sstevel@tonic-gate 	    H1394_ALLOC_CMD_NOSLEEP, &cmd, &cmd_priv);
1576*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
1577*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_arreq_read_cmdalloc_fail,
1578*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
1579*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1580*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1581*0Sstevel@tonic-gate 		return (DDI_FAILURE);
1582*0Sstevel@tonic-gate 	}
1583*0Sstevel@tonic-gate 
1584*0Sstevel@tonic-gate 	/* Initialize the HAL private command info */
1585*0Sstevel@tonic-gate 	hci1394_async_hcicmd_init(async_handle, cmd, cmd_priv, hcicmd);
1586*0Sstevel@tonic-gate 
1587*0Sstevel@tonic-gate 	/*
1588*0Sstevel@tonic-gate 	 * There are two generations in the command structure, one in the public
1589*0Sstevel@tonic-gate 	 * space and one in the HAL/SL private shared space. We need to fill in
1590*0Sstevel@tonic-gate 	 * both.  We only use the private one internally.
1591*0Sstevel@tonic-gate 	 */
1592*0Sstevel@tonic-gate 	cmd_priv->bus_generation = async_handle->as_drvinfo->di_gencnt;
1593*0Sstevel@tonic-gate 	cmd->bus_generation = async_handle->as_drvinfo->di_gencnt;
1594*0Sstevel@tonic-gate 
1595*0Sstevel@tonic-gate 	/*
1596*0Sstevel@tonic-gate 	 * Read the request (based on which kind of request it is) into the 1394
1597*0Sstevel@tonic-gate 	 * framework command.
1598*0Sstevel@tonic-gate 	 */
1599*0Sstevel@tonic-gate 	switch (*tcode) {
1600*0Sstevel@tonic-gate 	case IEEE1394_TCODE_READ_QUADLET:
1601*0Sstevel@tonic-gate 		/*
1602*0Sstevel@tonic-gate 		 * We got a ARREQ quadlet read request. Read in the packet.
1603*0Sstevel@tonic-gate 		 * If there is a problem with the packet (i.e. we don't get
1604*0Sstevel@tonic-gate 		 * DDI_SUCCESS), we will free up the command and return NULL in
1605*0Sstevel@tonic-gate 		 * hcicmd to indicate that we did not get a valid ARREQ to
1606*0Sstevel@tonic-gate 		 * process.
1607*0Sstevel@tonic-gate 		 */
1608*0Sstevel@tonic-gate 		status = hci1394_async_arreq_read_qrd(async_handle, pkt,
1609*0Sstevel@tonic-gate 		    *hcicmd, size);
1610*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
1611*0Sstevel@tonic-gate 			hci1394_async_response_complete(async_handle, cmd,
1612*0Sstevel@tonic-gate 			    cmd_priv);
1613*0Sstevel@tonic-gate 			*hcicmd = NULL;
1614*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_arreq_read_qrd_fail,
1615*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
1616*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1617*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1618*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1619*0Sstevel@tonic-gate 		}
1620*0Sstevel@tonic-gate 		break;
1621*0Sstevel@tonic-gate 
1622*0Sstevel@tonic-gate 	case IEEE1394_TCODE_WRITE_QUADLET:
1623*0Sstevel@tonic-gate 		/*
1624*0Sstevel@tonic-gate 		 * We got a ARREQ quadlet write request. Read in the packet.
1625*0Sstevel@tonic-gate 		 * If there is a problem with the packet (i.e. we don't get
1626*0Sstevel@tonic-gate 		 * DDI_SUCCESS), we will free up the command and return NULL in
1627*0Sstevel@tonic-gate 		 * hcicmd to indicate that we did not get a valid ARREQ to
1628*0Sstevel@tonic-gate 		 * process.
1629*0Sstevel@tonic-gate 		 */
1630*0Sstevel@tonic-gate 		status = hci1394_async_arreq_read_qwr(async_handle, pkt,
1631*0Sstevel@tonic-gate 		    *hcicmd, size);
1632*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
1633*0Sstevel@tonic-gate 			hci1394_async_response_complete(async_handle, cmd,
1634*0Sstevel@tonic-gate 			    cmd_priv);
1635*0Sstevel@tonic-gate 			*hcicmd = NULL;
1636*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_arreq_read_qwr_fail,
1637*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
1638*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1639*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1640*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1641*0Sstevel@tonic-gate 		}
1642*0Sstevel@tonic-gate 		break;
1643*0Sstevel@tonic-gate 
1644*0Sstevel@tonic-gate 	case IEEE1394_TCODE_READ_BLOCK:
1645*0Sstevel@tonic-gate 		/*
1646*0Sstevel@tonic-gate 		 * We got a ARREQ block read request. Read in the packet.
1647*0Sstevel@tonic-gate 		 * If there is a problem with the packet (i.e. we don't get
1648*0Sstevel@tonic-gate 		 * DDI_SUCCESS), we will free up the command and return NULL in
1649*0Sstevel@tonic-gate 		 * hcicmd to indicate that we did not get a valid ARREQ to
1650*0Sstevel@tonic-gate 		 * process.
1651*0Sstevel@tonic-gate 		 */
1652*0Sstevel@tonic-gate 		status = hci1394_async_arreq_read_brd(async_handle, pkt,
1653*0Sstevel@tonic-gate 		    *hcicmd, size);
1654*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
1655*0Sstevel@tonic-gate 			hci1394_async_response_complete(async_handle, cmd,
1656*0Sstevel@tonic-gate 			    cmd_priv);
1657*0Sstevel@tonic-gate 			*hcicmd = NULL;
1658*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_arreq_read_brd_fail,
1659*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
1660*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1661*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1662*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1663*0Sstevel@tonic-gate 		}
1664*0Sstevel@tonic-gate 		break;
1665*0Sstevel@tonic-gate 
1666*0Sstevel@tonic-gate 	case IEEE1394_TCODE_WRITE_BLOCK:
1667*0Sstevel@tonic-gate 		/*
1668*0Sstevel@tonic-gate 		 * We got a ARREQ block write request. Read in the packet.
1669*0Sstevel@tonic-gate 		 * If there is a problem with the packet (i.e. we don't get
1670*0Sstevel@tonic-gate 		 * DDI_SUCCESS), we will free up the command and return NULL in
1671*0Sstevel@tonic-gate 		 * hcicmd to indicate that we did not get a valid ARREQ to
1672*0Sstevel@tonic-gate 		 * process.
1673*0Sstevel@tonic-gate 		 */
1674*0Sstevel@tonic-gate 		status = hci1394_async_arreq_read_bwr(async_handle, pkt,
1675*0Sstevel@tonic-gate 		    *hcicmd, size);
1676*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
1677*0Sstevel@tonic-gate 			hci1394_async_response_complete(async_handle, cmd,
1678*0Sstevel@tonic-gate 			    cmd_priv);
1679*0Sstevel@tonic-gate 			*hcicmd = NULL;
1680*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_arreq_read_bwr_fail,
1681*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
1682*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1683*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1684*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1685*0Sstevel@tonic-gate 		}
1686*0Sstevel@tonic-gate 		break;
1687*0Sstevel@tonic-gate 
1688*0Sstevel@tonic-gate 	case IEEE1394_TCODE_LOCK:
1689*0Sstevel@tonic-gate 		/*
1690*0Sstevel@tonic-gate 		 * We got a ARREQ lock request. Read in the packet.
1691*0Sstevel@tonic-gate 		 * If there is a problem with the packet (i.e. we don't get
1692*0Sstevel@tonic-gate 		 * DDI_SUCCESS), we will free up the command and return NULL in
1693*0Sstevel@tonic-gate 		 * hcicmd to indicate that we did not get a valid ARREQ to
1694*0Sstevel@tonic-gate 		 * process.
1695*0Sstevel@tonic-gate 		 */
1696*0Sstevel@tonic-gate 		status = hci1394_async_arreq_read_lck(async_handle, pkt,
1697*0Sstevel@tonic-gate 		    *hcicmd, size);
1698*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
1699*0Sstevel@tonic-gate 			hci1394_async_response_complete(async_handle, cmd,
1700*0Sstevel@tonic-gate 			    cmd_priv);
1701*0Sstevel@tonic-gate 			*hcicmd = NULL;
1702*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_arreq_read_lck_fail,
1703*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
1704*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1705*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1706*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1707*0Sstevel@tonic-gate 		}
1708*0Sstevel@tonic-gate 		break;
1709*0Sstevel@tonic-gate 
1710*0Sstevel@tonic-gate 	case IEEE1394_TCODE_PHY:
1711*0Sstevel@tonic-gate 		/*
1712*0Sstevel@tonic-gate 		 * We got a PHY packet in the ARREQ buffer. Read in the packet.
1713*0Sstevel@tonic-gate 		 * If there is a problem with the packet (i.e. we don't get
1714*0Sstevel@tonic-gate 		 * DDI_SUCCESS), we will free up the command and return NULL in
1715*0Sstevel@tonic-gate 		 * hcicmd to indicate that we did not get a valid ARREQ to
1716*0Sstevel@tonic-gate 		 * process.
1717*0Sstevel@tonic-gate 		 */
1718*0Sstevel@tonic-gate 		status = hci1394_async_arreq_read_phy(async_handle, pkt,
1719*0Sstevel@tonic-gate 		    *hcicmd, size, &is_reset_token);
1720*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
1721*0Sstevel@tonic-gate 			hci1394_async_response_complete(async_handle, cmd,
1722*0Sstevel@tonic-gate 			    cmd_priv);
1723*0Sstevel@tonic-gate 			*hcicmd = NULL;
1724*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_arreq_read_phy_fail,
1725*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
1726*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1727*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1728*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1729*0Sstevel@tonic-gate 		}
1730*0Sstevel@tonic-gate 
1731*0Sstevel@tonic-gate 		/*
1732*0Sstevel@tonic-gate 		 * If we got a bus reset token, free up the command and return
1733*0Sstevel@tonic-gate 		 * NULL in hcicmd to indicate that we did not get a valid ARREQ
1734*0Sstevel@tonic-gate 		 * to process.
1735*0Sstevel@tonic-gate 		 */
1736*0Sstevel@tonic-gate 		if (is_reset_token == B_TRUE) {
1737*0Sstevel@tonic-gate 			hci1394_async_response_complete(async_handle, cmd,
1738*0Sstevel@tonic-gate 			    cmd_priv);
1739*0Sstevel@tonic-gate 			*hcicmd = NULL;
1740*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1741*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
1742*0Sstevel@tonic-gate 			return (DDI_SUCCESS);
1743*0Sstevel@tonic-gate 		}
1744*0Sstevel@tonic-gate 		break;
1745*0Sstevel@tonic-gate 
1746*0Sstevel@tonic-gate 	default:
1747*0Sstevel@tonic-gate 		/* we got a tcode that we don't know about. Return error */
1748*0Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_async_arreq_tcode_err,
1749*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_string, errmsg,
1750*0Sstevel@tonic-gate 		    "unknown ARREQ received", tnf_uint, arreq_tcode, *tcode);
1751*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1752*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1753*0Sstevel@tonic-gate 		return (DDI_FAILURE);
1754*0Sstevel@tonic-gate 	}
1755*0Sstevel@tonic-gate 
1756*0Sstevel@tonic-gate 	/*
1757*0Sstevel@tonic-gate 	 * If this command was broadcast and it was not a write, drop the
1758*0Sstevel@tonic-gate 	 * command since it's an invalid request. We will free up the command
1759*0Sstevel@tonic-gate 	 * and return NULL in hcicmd to indicate that we did not get a valid
1760*0Sstevel@tonic-gate 	 * ARREQ to process.
1761*0Sstevel@tonic-gate 	 */
1762*0Sstevel@tonic-gate 	if ((((*hcicmd)->ac_dest & IEEE1394_NODE_NUM_MASK) ==
1763*0Sstevel@tonic-gate 	    IEEE1394_BROADCAST_NODEID) && ((*tcode !=
1764*0Sstevel@tonic-gate 	    IEEE1394_TCODE_WRITE_QUADLET) && (*tcode !=
1765*0Sstevel@tonic-gate 	    IEEE1394_TCODE_WRITE_BLOCK))) {
1766*0Sstevel@tonic-gate 		hci1394_async_response_complete(async_handle, cmd, cmd_priv);
1767*0Sstevel@tonic-gate 		*hcicmd = NULL;
1768*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_arreq_read_bcast_fail,
1769*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
1770*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1771*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1772*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
1773*0Sstevel@tonic-gate 
1774*0Sstevel@tonic-gate 	/*
1775*0Sstevel@tonic-gate 	 * It is a valid broadcast command, set that field in the public
1776*0Sstevel@tonic-gate 	 * command structure.
1777*0Sstevel@tonic-gate 	 */
1778*0Sstevel@tonic-gate 	} else if ((((*hcicmd)->ac_dest & IEEE1394_NODE_NUM_MASK) ==
1779*0Sstevel@tonic-gate 	    IEEE1394_BROADCAST_NODEID)) {
1780*0Sstevel@tonic-gate 		cmd->broadcast = 1;
1781*0Sstevel@tonic-gate 	}
1782*0Sstevel@tonic-gate 
1783*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
1784*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1785*0Sstevel@tonic-gate 
1786*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
1787*0Sstevel@tonic-gate }
1788*0Sstevel@tonic-gate 
1789*0Sstevel@tonic-gate 
1790*0Sstevel@tonic-gate /*
1791*0Sstevel@tonic-gate  * hci1394_async_arreq_read_qrd()
1792*0Sstevel@tonic-gate  *    Read ARREQ quadlet read into the 1394 Framework command. This routine will
1793*0Sstevel@tonic-gate  *    return DDI_FAILURE if it was not able to read the request succesfully.
1794*0Sstevel@tonic-gate  */
1795*0Sstevel@tonic-gate static int
hci1394_async_arreq_read_qrd(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,hci1394_async_cmd_t * hcicmd,uint_t * size)1796*0Sstevel@tonic-gate hci1394_async_arreq_read_qrd(hci1394_async_handle_t async_handle,
1797*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size)
1798*0Sstevel@tonic-gate {
1799*0Sstevel@tonic-gate 	h1394_cmd_priv_t *cmd_priv;
1800*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
1801*0Sstevel@tonic-gate 	uint32_t quadlet;
1802*0Sstevel@tonic-gate 
1803*0Sstevel@tonic-gate 
1804*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
1805*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
1806*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
1807*0Sstevel@tonic-gate 	ASSERT(size != NULL);
1808*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qrd_enter,
1809*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1810*0Sstevel@tonic-gate 
1811*0Sstevel@tonic-gate 	/* Setup shortcuts, command type, and size of request */
1812*0Sstevel@tonic-gate 	cmd = hcicmd->ac_cmd;
1813*0Sstevel@tonic-gate 	cmd_priv = hcicmd->ac_priv;
1814*0Sstevel@tonic-gate 	cmd->cmd_type = CMD1394_ASYNCH_RD_QUAD;
1815*0Sstevel@tonic-gate 	*size = DESC_SZ_AR_READQUAD_REQ;
1816*0Sstevel@tonic-gate 
1817*0Sstevel@tonic-gate 	/*
1818*0Sstevel@tonic-gate 	 * read in the ARREQ ACK/EVT, the speed, the time we received it, and
1819*0Sstevel@tonic-gate 	 * calculate the ATRESP timeout for when we send it.
1820*0Sstevel@tonic-gate 	 */
1821*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q4);
1822*0Sstevel@tonic-gate 	hcicmd->ac_status = HCI1394_DESC_EVT_GET(quadlet);
1823*0Sstevel@tonic-gate 	cmd_priv->speed = HCI1394_DESC_AR_SPD_GET(quadlet);
1824*0Sstevel@tonic-gate 	cmd_priv->recv_tstamp = HCI1394_DESC_TIMESTAMP_GET(quadlet);
1825*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_timestamp = hci1394_async_timeout_calc(async_handle,
1826*0Sstevel@tonic-gate 	    cmd_priv->recv_tstamp);
1827*0Sstevel@tonic-gate 
1828*0Sstevel@tonic-gate 	/*
1829*0Sstevel@tonic-gate 	 * if the ARREQ ACK was bad, we were unable to successfully read in this
1830*0Sstevel@tonic-gate 	 * request.  Return failure.
1831*0Sstevel@tonic-gate 	 */
1832*0Sstevel@tonic-gate 	if ((hcicmd->ac_status != OHCI_ACK_COMPLETE) &&
1833*0Sstevel@tonic-gate 	    (hcicmd->ac_status != OHCI_ACK_PENDING)) {
1834*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_arreq_qrd_ack_fail,
1835*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_uint, arreq_ack,
1836*0Sstevel@tonic-gate 		    hcicmd->ac_status);
1837*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qrd_exit,
1838*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1839*0Sstevel@tonic-gate 		return (DDI_FAILURE);
1840*0Sstevel@tonic-gate 	}
1841*0Sstevel@tonic-gate 
1842*0Sstevel@tonic-gate 	/*
1843*0Sstevel@tonic-gate 	 * Read in the tlabel and destination. We don't use an mblk for this
1844*0Sstevel@tonic-gate 	 * request.
1845*0Sstevel@tonic-gate 	 */
1846*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q1);
1847*0Sstevel@tonic-gate 	hcicmd->ac_dest = HCI1394_DESC_DESTID_GET(quadlet);
1848*0Sstevel@tonic-gate 	hcicmd->ac_tlabel.tbi_tlabel = HCI1394_DESC_TLABEL_GET(quadlet);
1849*0Sstevel@tonic-gate 	hcicmd->ac_mblk_alloc = B_FALSE;
1850*0Sstevel@tonic-gate 
1851*0Sstevel@tonic-gate 	/*
1852*0Sstevel@tonic-gate 	 * Read in the sender so we know who to send the ATRESP to and read in
1853*0Sstevel@tonic-gate 	 * the 1394 48-bit address for this request.
1854*0Sstevel@tonic-gate 	 */
1855*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q2);
1856*0Sstevel@tonic-gate 	cmd->nodeID = HCI1394_DESC_SRCID_GET(quadlet);
1857*0Sstevel@tonic-gate 	cmd->cmd_addr = HCI1394_TO_ADDR_HI(quadlet);
1858*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q3);
1859*0Sstevel@tonic-gate 	cmd->cmd_addr |= HCI1394_TO_ADDR_LO(quadlet);
1860*0Sstevel@tonic-gate 
1861*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qrd_exit,
1862*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1863*0Sstevel@tonic-gate 
1864*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
1865*0Sstevel@tonic-gate }
1866*0Sstevel@tonic-gate 
1867*0Sstevel@tonic-gate 
1868*0Sstevel@tonic-gate /*
1869*0Sstevel@tonic-gate  * hci1394_async_arreq_read_qwr()
1870*0Sstevel@tonic-gate  *    Read ARREQ quadlet write into the 1394 Framework command. This routine
1871*0Sstevel@tonic-gate  *    will return DDI_FAILURE if it was not able to read the request
1872*0Sstevel@tonic-gate  *    succesfully.
1873*0Sstevel@tonic-gate  */
1874*0Sstevel@tonic-gate static int
hci1394_async_arreq_read_qwr(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,hci1394_async_cmd_t * hcicmd,uint_t * size)1875*0Sstevel@tonic-gate hci1394_async_arreq_read_qwr(hci1394_async_handle_t async_handle,
1876*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size)
1877*0Sstevel@tonic-gate {
1878*0Sstevel@tonic-gate 	h1394_cmd_priv_t *cmd_priv;
1879*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
1880*0Sstevel@tonic-gate 	uint32_t quadlet;
1881*0Sstevel@tonic-gate 
1882*0Sstevel@tonic-gate 
1883*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
1884*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
1885*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
1886*0Sstevel@tonic-gate 	ASSERT(size != NULL);
1887*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qwr_enter,
1888*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1889*0Sstevel@tonic-gate 
1890*0Sstevel@tonic-gate 	/* Setup shortcuts, command type, and size of request */
1891*0Sstevel@tonic-gate 	cmd = hcicmd->ac_cmd;
1892*0Sstevel@tonic-gate 	cmd_priv = hcicmd->ac_priv;
1893*0Sstevel@tonic-gate 	cmd->cmd_type = CMD1394_ASYNCH_WR_QUAD;
1894*0Sstevel@tonic-gate 	*size = DESC_SZ_AR_WRITEQUAD_REQ;
1895*0Sstevel@tonic-gate 
1896*0Sstevel@tonic-gate 	/*
1897*0Sstevel@tonic-gate 	 * read in the ARREQ ACK/EVT, the speed, the time we received it, and
1898*0Sstevel@tonic-gate 	 * calculate the ATRESP timeout for when we send it.
1899*0Sstevel@tonic-gate 	 */
1900*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q5);
1901*0Sstevel@tonic-gate 	hcicmd->ac_status = HCI1394_DESC_EVT_GET(quadlet);
1902*0Sstevel@tonic-gate 	cmd_priv->speed = HCI1394_DESC_AR_SPD_GET(quadlet);
1903*0Sstevel@tonic-gate 	cmd_priv->recv_tstamp = HCI1394_DESC_TIMESTAMP_GET(quadlet);
1904*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_timestamp = hci1394_async_timeout_calc(async_handle,
1905*0Sstevel@tonic-gate 	    cmd_priv->recv_tstamp);
1906*0Sstevel@tonic-gate 
1907*0Sstevel@tonic-gate 	/*
1908*0Sstevel@tonic-gate 	 * if the ARREQ ACK was bad, we were unable to successfully read in this
1909*0Sstevel@tonic-gate 	 * request.  Return failure.
1910*0Sstevel@tonic-gate 	 */
1911*0Sstevel@tonic-gate 	if ((hcicmd->ac_status != OHCI_ACK_COMPLETE) &&
1912*0Sstevel@tonic-gate 	    (hcicmd->ac_status != OHCI_ACK_PENDING)) {
1913*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_arreq_qwr_ack_fail,
1914*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_uint, arreq_ack,
1915*0Sstevel@tonic-gate 		    hcicmd->ac_status);
1916*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qwr_exit,
1917*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
1918*0Sstevel@tonic-gate 		return (DDI_FAILURE);
1919*0Sstevel@tonic-gate 	}
1920*0Sstevel@tonic-gate 
1921*0Sstevel@tonic-gate 	/*
1922*0Sstevel@tonic-gate 	 * Read in the tlabel and destination. We don't use an mblk for this
1923*0Sstevel@tonic-gate 	 * request.
1924*0Sstevel@tonic-gate 	 */
1925*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q1);
1926*0Sstevel@tonic-gate 	hcicmd->ac_dest = HCI1394_DESC_DESTID_GET(quadlet);
1927*0Sstevel@tonic-gate 	hcicmd->ac_tlabel.tbi_tlabel = HCI1394_DESC_TLABEL_GET(quadlet);
1928*0Sstevel@tonic-gate 	hcicmd->ac_mblk_alloc = B_FALSE;
1929*0Sstevel@tonic-gate 
1930*0Sstevel@tonic-gate 	/*
1931*0Sstevel@tonic-gate 	 * Read in the sender so we know who to send the ATRESP to. Read in
1932*0Sstevel@tonic-gate 	 * the 1394 48-bit address for this request. Copy the data quadlet into
1933*0Sstevel@tonic-gate 	 * the command.  The data quadlet is treated like a byte stream.
1934*0Sstevel@tonic-gate 	 */
1935*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q2);
1936*0Sstevel@tonic-gate 	cmd->nodeID = HCI1394_DESC_SRCID_GET(quadlet);
1937*0Sstevel@tonic-gate 	cmd->cmd_addr = HCI1394_TO_ADDR_HI(quadlet);
1938*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q3);
1939*0Sstevel@tonic-gate 	cmd->cmd_addr |= HCI1394_TO_ADDR_LO(quadlet);
1940*0Sstevel@tonic-gate 	hci1394_q_ar_rep_get8(async_handle->as_arreq_q,
1941*0Sstevel@tonic-gate 	    (uint8_t *)&cmd->cmd_u.q.quadlet_data, (uint8_t *)&pkt->q4,
1942*0Sstevel@tonic-gate 	    IEEE1394_QUADLET);
1943*0Sstevel@tonic-gate 
1944*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qwr_exit,
1945*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1946*0Sstevel@tonic-gate 
1947*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
1948*0Sstevel@tonic-gate }
1949*0Sstevel@tonic-gate 
1950*0Sstevel@tonic-gate 
1951*0Sstevel@tonic-gate /*
1952*0Sstevel@tonic-gate  * hci1394_async_arreq_read_brd()
1953*0Sstevel@tonic-gate  *    Read ARREQ block read into the 1394 Framework command. This routine will
1954*0Sstevel@tonic-gate  *    return DDI_FAILURE if it was not able to read the request succesfully.
1955*0Sstevel@tonic-gate  */
1956*0Sstevel@tonic-gate static int
hci1394_async_arreq_read_brd(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,hci1394_async_cmd_t * hcicmd,uint_t * size)1957*0Sstevel@tonic-gate hci1394_async_arreq_read_brd(hci1394_async_handle_t async_handle,
1958*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size)
1959*0Sstevel@tonic-gate {
1960*0Sstevel@tonic-gate 	h1394_cmd_priv_t *cmd_priv;
1961*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
1962*0Sstevel@tonic-gate 	uint32_t quadlet;
1963*0Sstevel@tonic-gate 
1964*0Sstevel@tonic-gate 
1965*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
1966*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
1967*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
1968*0Sstevel@tonic-gate 	ASSERT(size != NULL);
1969*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_brd_enter,
1970*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
1971*0Sstevel@tonic-gate 
1972*0Sstevel@tonic-gate 	/* Setup shortcuts, command type, and size of request */
1973*0Sstevel@tonic-gate 	cmd = hcicmd->ac_cmd;
1974*0Sstevel@tonic-gate 	cmd_priv = hcicmd->ac_priv;
1975*0Sstevel@tonic-gate 	cmd->cmd_type = CMD1394_ASYNCH_RD_BLOCK;
1976*0Sstevel@tonic-gate 	*size = DESC_SZ_AR_READBLOCK_REQ;
1977*0Sstevel@tonic-gate 
1978*0Sstevel@tonic-gate 	/*
1979*0Sstevel@tonic-gate 	 * read in the ARREQ ACK/EVT, the speed, the time we received it, and
1980*0Sstevel@tonic-gate 	 * calculate the ATRESP timeout for when we send it.
1981*0Sstevel@tonic-gate 	 */
1982*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q5);
1983*0Sstevel@tonic-gate 	hcicmd->ac_status = HCI1394_DESC_EVT_GET(quadlet);
1984*0Sstevel@tonic-gate 	cmd_priv->speed = HCI1394_DESC_AR_SPD_GET(quadlet);
1985*0Sstevel@tonic-gate 	cmd_priv->recv_tstamp = HCI1394_DESC_TIMESTAMP_GET(quadlet);
1986*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_timestamp = hci1394_async_timeout_calc(async_handle,
1987*0Sstevel@tonic-gate 	    cmd_priv->recv_tstamp);
1988*0Sstevel@tonic-gate 
1989*0Sstevel@tonic-gate 	/*
1990*0Sstevel@tonic-gate 	 * if the ARREQ ACK was bad, we were unable to successfully read in this
1991*0Sstevel@tonic-gate 	 * request.  Return failure.
1992*0Sstevel@tonic-gate 	 */
1993*0Sstevel@tonic-gate 	if ((hcicmd->ac_status != OHCI_ACK_COMPLETE) &&
1994*0Sstevel@tonic-gate 	    (hcicmd->ac_status != OHCI_ACK_PENDING)) {
1995*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_arreq_brd_ack_fail,
1996*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_uint, arreq_ack,
1997*0Sstevel@tonic-gate 		    hcicmd->ac_status);
1998*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_brd_exit,
1999*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2000*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2001*0Sstevel@tonic-gate 	}
2002*0Sstevel@tonic-gate 
2003*0Sstevel@tonic-gate 	/* Read in the tlabel and destination */
2004*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q1);
2005*0Sstevel@tonic-gate 	hcicmd->ac_dest = HCI1394_DESC_DESTID_GET(quadlet);
2006*0Sstevel@tonic-gate 	hcicmd->ac_tlabel.tbi_tlabel = HCI1394_DESC_TLABEL_GET(quadlet);
2007*0Sstevel@tonic-gate 
2008*0Sstevel@tonic-gate 	/*
2009*0Sstevel@tonic-gate 	 * Read in the sender so we know who to send the ATRESP to. Read in
2010*0Sstevel@tonic-gate 	 * the 1394 48-bit address for this request. Read in the block data size
2011*0Sstevel@tonic-gate 	 * and allocate an mblk of that size.
2012*0Sstevel@tonic-gate 	 */
2013*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q2);
2014*0Sstevel@tonic-gate 	cmd->nodeID = HCI1394_DESC_SRCID_GET(quadlet);
2015*0Sstevel@tonic-gate 	cmd->cmd_addr = HCI1394_TO_ADDR_HI(quadlet);
2016*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q3);
2017*0Sstevel@tonic-gate 	cmd->cmd_addr |= HCI1394_TO_ADDR_LO(quadlet);
2018*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q4);
2019*0Sstevel@tonic-gate 	cmd->cmd_u.b.blk_length = HCI1394_DESC_DATALEN_GET(quadlet);
2020*0Sstevel@tonic-gate 	cmd->cmd_u.b.data_block = allocb(cmd->cmd_u.b.blk_length, 0);
2021*0Sstevel@tonic-gate 	if (cmd->cmd_u.b.data_block == NULL) {
2022*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_arreq_brd_mblk_fail,
2023*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2024*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_brd_exit,
2025*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2026*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2027*0Sstevel@tonic-gate 	}
2028*0Sstevel@tonic-gate 	hcicmd->ac_mblk_alloc = B_TRUE;
2029*0Sstevel@tonic-gate 
2030*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_brd_exit,
2031*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2032*0Sstevel@tonic-gate 
2033*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2034*0Sstevel@tonic-gate }
2035*0Sstevel@tonic-gate 
2036*0Sstevel@tonic-gate 
2037*0Sstevel@tonic-gate /*
2038*0Sstevel@tonic-gate  * hci1394_async_arreq_read_bwr()
2039*0Sstevel@tonic-gate  *    Read ARREQ block write into the 1394 Framework command. This routine will
2040*0Sstevel@tonic-gate  *    return DDI_FAILURE if it was not able to read the request succesfully.
2041*0Sstevel@tonic-gate  */
2042*0Sstevel@tonic-gate static int
hci1394_async_arreq_read_bwr(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,hci1394_async_cmd_t * hcicmd,uint_t * size)2043*0Sstevel@tonic-gate hci1394_async_arreq_read_bwr(hci1394_async_handle_t async_handle,
2044*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size)
2045*0Sstevel@tonic-gate {
2046*0Sstevel@tonic-gate 	h1394_cmd_priv_t *cmd_priv;
2047*0Sstevel@tonic-gate 	uint32_t *local_addr;
2048*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
2049*0Sstevel@tonic-gate 	uint32_t quadlet;
2050*0Sstevel@tonic-gate 
2051*0Sstevel@tonic-gate 
2052*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2053*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
2054*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
2055*0Sstevel@tonic-gate 	ASSERT(size != NULL);
2056*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_bwr_enter,
2057*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2058*0Sstevel@tonic-gate 
2059*0Sstevel@tonic-gate 	/*
2060*0Sstevel@tonic-gate 	 * Setup shortcuts, command type, and size of request. The size of the
2061*0Sstevel@tonic-gate 	 * request is in quadlets, therefore we need to make sure we count in
2062*0Sstevel@tonic-gate 	 * the padding when figureing out the size (i.e. data may be in bytes
2063*0Sstevel@tonic-gate 	 * but the HW always pads to quadlets)
2064*0Sstevel@tonic-gate 	 */
2065*0Sstevel@tonic-gate 	cmd = hcicmd->ac_cmd;
2066*0Sstevel@tonic-gate 	cmd_priv = hcicmd->ac_priv;
2067*0Sstevel@tonic-gate 	cmd->cmd_type = CMD1394_ASYNCH_WR_BLOCK;
2068*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q4);
2069*0Sstevel@tonic-gate 	cmd->cmd_u.b.blk_length = HCI1394_DESC_DATALEN_GET(quadlet);
2070*0Sstevel@tonic-gate 	*size = DESC_SZ_AR_WRITEBLOCK_REQ +
2071*0Sstevel@tonic-gate 	    HCI1394_ALIGN_QUAD(cmd->cmd_u.b.blk_length);
2072*0Sstevel@tonic-gate 
2073*0Sstevel@tonic-gate 	/*
2074*0Sstevel@tonic-gate 	 * read in the ARREQ ACK/EVT, the speed, the time we received it, and
2075*0Sstevel@tonic-gate 	 * calculate the ATRESP timeout for when we send it. The status word is
2076*0Sstevel@tonic-gate 	 * the last quadlet in the packet.
2077*0Sstevel@tonic-gate 	 */
2078*0Sstevel@tonic-gate 	local_addr = (uint32_t *)(((uintptr_t)(&pkt->q5)) +
2079*0Sstevel@tonic-gate 	    ((uintptr_t)HCI1394_ALIGN_QUAD(cmd->cmd_u.b.blk_length)));
2080*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, local_addr);
2081*0Sstevel@tonic-gate 	hcicmd->ac_status = HCI1394_DESC_EVT_GET(quadlet);
2082*0Sstevel@tonic-gate 	cmd_priv->speed = HCI1394_DESC_AR_SPD_GET(quadlet);
2083*0Sstevel@tonic-gate 	cmd_priv->recv_tstamp = HCI1394_DESC_TIMESTAMP_GET(quadlet);
2084*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_timestamp = hci1394_async_timeout_calc(async_handle,
2085*0Sstevel@tonic-gate 	    cmd_priv->recv_tstamp);
2086*0Sstevel@tonic-gate 
2087*0Sstevel@tonic-gate 	/*
2088*0Sstevel@tonic-gate 	 * if the ARREQ ACK was bad, we were unable to successfully read in this
2089*0Sstevel@tonic-gate 	 * request.  Return failure.
2090*0Sstevel@tonic-gate 	 */
2091*0Sstevel@tonic-gate 	if ((hcicmd->ac_status != OHCI_ACK_COMPLETE) &&
2092*0Sstevel@tonic-gate 	    (hcicmd->ac_status != OHCI_ACK_PENDING)) {
2093*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_arreq_bwr_ack_fail,
2094*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_uint, arreq_ack,
2095*0Sstevel@tonic-gate 		    hcicmd->ac_status);
2096*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_bwr_exit,
2097*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2098*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2099*0Sstevel@tonic-gate 	}
2100*0Sstevel@tonic-gate 
2101*0Sstevel@tonic-gate 	/* Read in the tlabel and destination */
2102*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q1);
2103*0Sstevel@tonic-gate 	hcicmd->ac_dest = HCI1394_DESC_DESTID_GET(quadlet);
2104*0Sstevel@tonic-gate 	hcicmd->ac_tlabel.tbi_tlabel = HCI1394_DESC_TLABEL_GET(quadlet);
2105*0Sstevel@tonic-gate 
2106*0Sstevel@tonic-gate 	/*
2107*0Sstevel@tonic-gate 	 * Read in the sender so we know who to send the ATRESP to. Read in
2108*0Sstevel@tonic-gate 	 * the 1394 48-bit address for this request. Read in the block data size
2109*0Sstevel@tonic-gate 	 * and allocate an mblk of that size.
2110*0Sstevel@tonic-gate 	 */
2111*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q2);
2112*0Sstevel@tonic-gate 	cmd->nodeID = HCI1394_DESC_SRCID_GET(quadlet);
2113*0Sstevel@tonic-gate 	cmd->cmd_addr = HCI1394_TO_ADDR_HI(quadlet);
2114*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q3);
2115*0Sstevel@tonic-gate 	cmd->cmd_addr |= HCI1394_TO_ADDR_LO(quadlet);
2116*0Sstevel@tonic-gate 	cmd->cmd_u.b.data_block = allocb(cmd->cmd_u.b.blk_length, 0);
2117*0Sstevel@tonic-gate 	if (cmd->cmd_u.b.data_block == NULL) {
2118*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_arreq_bwr_mblk_fail,
2119*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2120*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_bwr_exit,
2121*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2122*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2123*0Sstevel@tonic-gate 	}
2124*0Sstevel@tonic-gate 	hcicmd->ac_mblk_alloc = B_TRUE;
2125*0Sstevel@tonic-gate 
2126*0Sstevel@tonic-gate 	/* Copy ARREQ write data into mblk_t */
2127*0Sstevel@tonic-gate 	hci1394_q_ar_rep_get8(async_handle->as_arreq_q,
2128*0Sstevel@tonic-gate 	    (uint8_t *)cmd->cmd_u.b.data_block->b_wptr,
2129*0Sstevel@tonic-gate 	    (uint8_t *)&pkt->q5, cmd->cmd_u.b.blk_length);
2130*0Sstevel@tonic-gate 
2131*0Sstevel@tonic-gate 	/* Update mblk_t wptr */
2132*0Sstevel@tonic-gate 	cmd->cmd_u.b.data_block->b_wptr += cmd->cmd_u.b.blk_length;
2133*0Sstevel@tonic-gate 
2134*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_bwr_exit,
2135*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2136*0Sstevel@tonic-gate 
2137*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2138*0Sstevel@tonic-gate }
2139*0Sstevel@tonic-gate 
2140*0Sstevel@tonic-gate 
2141*0Sstevel@tonic-gate /*
2142*0Sstevel@tonic-gate  * hci1394_async_arreq_read_lck()
2143*0Sstevel@tonic-gate  *    Read ARREQ lock request into the 1394 Framework command. This routine will
2144*0Sstevel@tonic-gate  *    return DDI_FAILURE if it was not able to read the request succesfully.
2145*0Sstevel@tonic-gate  */
2146*0Sstevel@tonic-gate static int
hci1394_async_arreq_read_lck(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,hci1394_async_cmd_t * hcicmd,uint_t * size)2147*0Sstevel@tonic-gate hci1394_async_arreq_read_lck(hci1394_async_handle_t async_handle,
2148*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size)
2149*0Sstevel@tonic-gate {
2150*0Sstevel@tonic-gate 	h1394_cmd_priv_t *cmd_priv;
2151*0Sstevel@tonic-gate 	uint32_t *local_addr;
2152*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
2153*0Sstevel@tonic-gate 	uint8_t *data_addr;
2154*0Sstevel@tonic-gate 	uint32_t quadlet;
2155*0Sstevel@tonic-gate 	uint32_t length;
2156*0Sstevel@tonic-gate 
2157*0Sstevel@tonic-gate 
2158*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2159*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
2160*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
2161*0Sstevel@tonic-gate 	ASSERT(size != NULL);
2162*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qrd_enter,
2163*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2164*0Sstevel@tonic-gate 
2165*0Sstevel@tonic-gate 	/*
2166*0Sstevel@tonic-gate 	 * Setup shortcuts, command type, and size of request. The size of the
2167*0Sstevel@tonic-gate 	 * request is in quadlets, therefore we need to make sure we count in
2168*0Sstevel@tonic-gate 	 * the padding when figuring out the size (i.e. data may be in bytes
2169*0Sstevel@tonic-gate 	 * but the HW always pads to quadlets)
2170*0Sstevel@tonic-gate 	 */
2171*0Sstevel@tonic-gate 	cmd = hcicmd->ac_cmd;
2172*0Sstevel@tonic-gate 	cmd_priv = hcicmd->ac_priv;
2173*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q4);
2174*0Sstevel@tonic-gate 	length = HCI1394_DESC_DATALEN_GET(quadlet);
2175*0Sstevel@tonic-gate 	*size = DESC_SZ_AR_LOCK_REQ + HCI1394_ALIGN_QUAD(length);
2176*0Sstevel@tonic-gate 
2177*0Sstevel@tonic-gate 	/* make sure the length is a valid lock request length */
2178*0Sstevel@tonic-gate 	if (length == DESC_TWO_QUADS) {
2179*0Sstevel@tonic-gate 		cmd->cmd_type = CMD1394_ASYNCH_LOCK_32;
2180*0Sstevel@tonic-gate 		cmd->cmd_u.l32.lock_type = HCI1394_DESC_EXTTCODE_GET(quadlet);
2181*0Sstevel@tonic-gate 	} else if (length == DESC_TWO_OCTLETS) {
2182*0Sstevel@tonic-gate 		cmd->cmd_type = CMD1394_ASYNCH_LOCK_64;
2183*0Sstevel@tonic-gate 		cmd->cmd_u.l64.lock_type = HCI1394_DESC_EXTTCODE_GET(quadlet);
2184*0Sstevel@tonic-gate 	} else {
2185*0Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_async_arreq_lck_sz_fail,
2186*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_string, errmsg,
2187*0Sstevel@tonic-gate 		    "unexpected length received", tnf_uint, locklen, length);
2188*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
2189*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2190*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2191*0Sstevel@tonic-gate 	}
2192*0Sstevel@tonic-gate 
2193*0Sstevel@tonic-gate 	/*
2194*0Sstevel@tonic-gate 	 * read in the ARREQ ACK/EVT, the speed, the time we received it, and
2195*0Sstevel@tonic-gate 	 * calculate the ATRESP timeout for when we send it. The status word is
2196*0Sstevel@tonic-gate 	 * the last quadlet in the packet.
2197*0Sstevel@tonic-gate 	 */
2198*0Sstevel@tonic-gate 	local_addr = (uint32_t *)(((uintptr_t)(&pkt->q5)) +
2199*0Sstevel@tonic-gate 	    ((uintptr_t)HCI1394_ALIGN_QUAD(length)));
2200*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, local_addr);
2201*0Sstevel@tonic-gate 	hcicmd->ac_status = HCI1394_DESC_EVT_GET(quadlet);
2202*0Sstevel@tonic-gate 	cmd_priv->speed = HCI1394_DESC_AR_SPD_GET(quadlet);
2203*0Sstevel@tonic-gate 	cmd_priv->recv_tstamp = HCI1394_DESC_TIMESTAMP_GET(quadlet);
2204*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_timestamp = hci1394_async_timeout_calc(async_handle,
2205*0Sstevel@tonic-gate 	    cmd_priv->recv_tstamp);
2206*0Sstevel@tonic-gate 
2207*0Sstevel@tonic-gate 	/*
2208*0Sstevel@tonic-gate 	 * if the ARREQ ACK was bad, we were unable to successfully read in this
2209*0Sstevel@tonic-gate 	 * request.  Return failure.
2210*0Sstevel@tonic-gate 	 */
2211*0Sstevel@tonic-gate 	if ((hcicmd->ac_status != OHCI_ACK_COMPLETE) &&
2212*0Sstevel@tonic-gate 	    (hcicmd->ac_status != OHCI_ACK_PENDING)) {
2213*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_arreq_read_ack_fail,
2214*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_uint, arreq_ack,
2215*0Sstevel@tonic-gate 		    hcicmd->ac_status);
2216*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_exit,
2217*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2218*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2219*0Sstevel@tonic-gate 	}
2220*0Sstevel@tonic-gate 
2221*0Sstevel@tonic-gate 	/* Read in the tlabel and destination */
2222*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q1);
2223*0Sstevel@tonic-gate 	hcicmd->ac_dest = HCI1394_DESC_DESTID_GET(quadlet);
2224*0Sstevel@tonic-gate 	hcicmd->ac_tlabel.tbi_tlabel = HCI1394_DESC_TLABEL_GET(quadlet);
2225*0Sstevel@tonic-gate 	hcicmd->ac_mblk_alloc = B_FALSE;
2226*0Sstevel@tonic-gate 
2227*0Sstevel@tonic-gate 	/*
2228*0Sstevel@tonic-gate 	 * Read in the sender so we know who to send the ATRESP to. Read in
2229*0Sstevel@tonic-gate 	 * the 1394 48-bit address for this request.
2230*0Sstevel@tonic-gate 	 */
2231*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q2);
2232*0Sstevel@tonic-gate 	cmd->nodeID = HCI1394_DESC_SRCID_GET(quadlet);
2233*0Sstevel@tonic-gate 	cmd->cmd_addr = HCI1394_TO_ADDR_HI(quadlet);
2234*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q3);
2235*0Sstevel@tonic-gate 	cmd->cmd_addr |= HCI1394_TO_ADDR_LO(quadlet);
2236*0Sstevel@tonic-gate 
2237*0Sstevel@tonic-gate 	/* Copy ARREQ lock data into 1394 framework command */
2238*0Sstevel@tonic-gate 	if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_32) {
2239*0Sstevel@tonic-gate 		data_addr = (uint8_t *)&pkt->q5;
2240*0Sstevel@tonic-gate 		hci1394_q_ar_rep_get8(async_handle->as_arreq_q,
2241*0Sstevel@tonic-gate 		    (uint8_t *)&cmd->cmd_u.l32.arg_value, data_addr,
2242*0Sstevel@tonic-gate 		    IEEE1394_QUADLET);
2243*0Sstevel@tonic-gate 		data_addr = (uint8_t *)((uintptr_t)data_addr +
2244*0Sstevel@tonic-gate 		    (uintptr_t)IEEE1394_QUADLET);
2245*0Sstevel@tonic-gate 		hci1394_q_ar_rep_get8(async_handle->as_arreq_q,
2246*0Sstevel@tonic-gate 		    (uint8_t *)&cmd->cmd_u.l32.data_value, data_addr,
2247*0Sstevel@tonic-gate 		    IEEE1394_QUADLET);
2248*0Sstevel@tonic-gate 		/*
2249*0Sstevel@tonic-gate 		 * swap these for our correct architecture if we are doing
2250*0Sstevel@tonic-gate 		 * arithmetic lock operations
2251*0Sstevel@tonic-gate 		 */
2252*0Sstevel@tonic-gate 		cmd->cmd_u.l32.arg_value = HCI1394_ARITH_LOCK_SWAP32(
2253*0Sstevel@tonic-gate 		    cmd->cmd_u.l32.lock_type, cmd->cmd_u.l32.arg_value);
2254*0Sstevel@tonic-gate 		cmd->cmd_u.l32.data_value = HCI1394_ARITH_LOCK_SWAP32(
2255*0Sstevel@tonic-gate 		    cmd->cmd_u.l32.lock_type, cmd->cmd_u.l32.data_value);
2256*0Sstevel@tonic-gate 	} else if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_64) {
2257*0Sstevel@tonic-gate 		data_addr = (uint8_t *)&pkt->q5;
2258*0Sstevel@tonic-gate 		hci1394_q_ar_rep_get8(async_handle->as_arreq_q,
2259*0Sstevel@tonic-gate 		    (uint8_t *)&cmd->cmd_u.l64.arg_value, data_addr,
2260*0Sstevel@tonic-gate 		    IEEE1394_OCTLET);
2261*0Sstevel@tonic-gate 		data_addr = (uint8_t *)((uintptr_t)data_addr +
2262*0Sstevel@tonic-gate 		    (uintptr_t)IEEE1394_OCTLET);
2263*0Sstevel@tonic-gate 		hci1394_q_ar_rep_get8(async_handle->as_arreq_q,
2264*0Sstevel@tonic-gate 		    (uint8_t *)&cmd->cmd_u.l64.data_value, data_addr,
2265*0Sstevel@tonic-gate 		    IEEE1394_OCTLET);
2266*0Sstevel@tonic-gate 
2267*0Sstevel@tonic-gate 		/*
2268*0Sstevel@tonic-gate 		 * swap these for our correct architecture if we are doing
2269*0Sstevel@tonic-gate 		 * arithmetic lock operations
2270*0Sstevel@tonic-gate 		 */
2271*0Sstevel@tonic-gate 		cmd->cmd_u.l64.arg_value = HCI1394_ARITH_LOCK_SWAP64(
2272*0Sstevel@tonic-gate 		    cmd->cmd_u.l64.lock_type, cmd->cmd_u.l64.arg_value);
2273*0Sstevel@tonic-gate 		cmd->cmd_u.l64.data_value = HCI1394_ARITH_LOCK_SWAP64(
2274*0Sstevel@tonic-gate 		    cmd->cmd_u.l64.lock_type, cmd->cmd_u.l64.data_value);
2275*0Sstevel@tonic-gate 	}
2276*0Sstevel@tonic-gate 
2277*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_qrd_exit,
2278*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2279*0Sstevel@tonic-gate 
2280*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2281*0Sstevel@tonic-gate }
2282*0Sstevel@tonic-gate 
2283*0Sstevel@tonic-gate 
2284*0Sstevel@tonic-gate /*
2285*0Sstevel@tonic-gate  * hci1394_async_arreq_read_phy()
2286*0Sstevel@tonic-gate  *    Read ARREQ PHY quadlet into the 1394 Framework command. This routine will
2287*0Sstevel@tonic-gate  *    return DDI_FAILURE if it was not able to read the request succesfully.
2288*0Sstevel@tonic-gate  */
2289*0Sstevel@tonic-gate static int
hci1394_async_arreq_read_phy(hci1394_async_handle_t async_handle,hci1394_basic_pkt_t * pkt,hci1394_async_cmd_t * hcicmd,uint_t * size,boolean_t * bus_reset_token)2290*0Sstevel@tonic-gate hci1394_async_arreq_read_phy(hci1394_async_handle_t async_handle,
2291*0Sstevel@tonic-gate     hci1394_basic_pkt_t *pkt, hci1394_async_cmd_t *hcicmd, uint_t *size,
2292*0Sstevel@tonic-gate     boolean_t *bus_reset_token)
2293*0Sstevel@tonic-gate {
2294*0Sstevel@tonic-gate 	cmd1394_cmd_t *cmd;
2295*0Sstevel@tonic-gate 	uint32_t quadlet;
2296*0Sstevel@tonic-gate 	uint32_t data1;
2297*0Sstevel@tonic-gate 	uint32_t data2;
2298*0Sstevel@tonic-gate 
2299*0Sstevel@tonic-gate 
2300*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2301*0Sstevel@tonic-gate 	ASSERT(pkt != NULL);
2302*0Sstevel@tonic-gate 	ASSERT(hcicmd != NULL);
2303*0Sstevel@tonic-gate 	ASSERT(size != NULL);
2304*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_phy_enter,
2305*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2306*0Sstevel@tonic-gate 
2307*0Sstevel@tonic-gate 	/* Setup shortcuts, command type, and size of request */
2308*0Sstevel@tonic-gate 	cmd = hcicmd->ac_cmd;
2309*0Sstevel@tonic-gate 	cmd->cmd_type = CMD1394_ASYNCH_WR_QUAD;
2310*0Sstevel@tonic-gate 	*size = DESC_SZ_AR_PHY;
2311*0Sstevel@tonic-gate 
2312*0Sstevel@tonic-gate 	/*
2313*0Sstevel@tonic-gate 	 * read in the ARREQ ACK/EVT, the speed, the time we received it, and
2314*0Sstevel@tonic-gate 	 * set state that we do not use an mblk for this request.
2315*0Sstevel@tonic-gate 	 */
2316*0Sstevel@tonic-gate 	quadlet = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q4);
2317*0Sstevel@tonic-gate 	hcicmd->ac_status = HCI1394_DESC_EVT_GET(quadlet);
2318*0Sstevel@tonic-gate 	hcicmd->ac_priv->speed = HCI1394_DESC_AR_SPD_GET(quadlet);
2319*0Sstevel@tonic-gate 	hcicmd->ac_priv->recv_tstamp = HCI1394_DESC_TIMESTAMP_GET(quadlet);
2320*0Sstevel@tonic-gate 	hcicmd->ac_mblk_alloc = B_FALSE;
2321*0Sstevel@tonic-gate 
2322*0Sstevel@tonic-gate 	/* Read in the PHY packet quadlet and its check quadlet */
2323*0Sstevel@tonic-gate 	data1 = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q2);
2324*0Sstevel@tonic-gate 	data2 = hci1394_q_ar_get32(async_handle->as_arreq_q, &pkt->q3);
2325*0Sstevel@tonic-gate 
2326*0Sstevel@tonic-gate 	/*
2327*0Sstevel@tonic-gate 	 * if this is a bus reset token, save away the generation. If the bus
2328*0Sstevel@tonic-gate 	 * reset token is for the current generation, we do not need to flush
2329*0Sstevel@tonic-gate 	 * the ARREQ Q anymore.
2330*0Sstevel@tonic-gate 	 */
2331*0Sstevel@tonic-gate 	if (hcicmd->ac_status == OHCI_EVT_BUS_RESET) {
2332*0Sstevel@tonic-gate 		*bus_reset_token = B_TRUE;
2333*0Sstevel@tonic-gate 		async_handle->as_phy_reset = HCI1394_DESC_PHYGEN_GET(data2);
2334*0Sstevel@tonic-gate 		if (async_handle->as_phy_reset == hci1394_ohci_current_busgen(
2335*0Sstevel@tonic-gate 		    async_handle->as_ohci)) {
2336*0Sstevel@tonic-gate 			async_handle->as_flushing_arreq = B_FALSE;
2337*0Sstevel@tonic-gate 		}
2338*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_phy_exit,
2339*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2340*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
2341*0Sstevel@tonic-gate 	}
2342*0Sstevel@tonic-gate 
2343*0Sstevel@tonic-gate 	*bus_reset_token = B_FALSE;
2344*0Sstevel@tonic-gate 
2345*0Sstevel@tonic-gate 	/* if there is a data error in the PHY packet, return failure */
2346*0Sstevel@tonic-gate 	if (data1 != ~data2) {
2347*0Sstevel@tonic-gate 		TNF_PROBE_2(hci1394_async_arreq_phy_xor_fail,
2348*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "", tnf_opaque, first_quadlet,
2349*0Sstevel@tonic-gate 		    data1, tnf_opaque, second_quadlet, data2);
2350*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_phy_exit,
2351*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2352*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2353*0Sstevel@tonic-gate 	}
2354*0Sstevel@tonic-gate 
2355*0Sstevel@tonic-gate 	/* Copy the PHY quadlet to the command */
2356*0Sstevel@tonic-gate 	cmd->cmd_u.q.quadlet_data = data1;
2357*0Sstevel@tonic-gate 
2358*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_read_phy_exit,
2359*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2360*0Sstevel@tonic-gate 
2361*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2362*0Sstevel@tonic-gate }
2363*0Sstevel@tonic-gate 
2364*0Sstevel@tonic-gate 
2365*0Sstevel@tonic-gate /*
2366*0Sstevel@tonic-gate  * hci1394_async_phy()
2367*0Sstevel@tonic-gate  *    Queue up ATREQ phy packet.
2368*0Sstevel@tonic-gate  */
2369*0Sstevel@tonic-gate int
hci1394_async_phy(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,int * result)2370*0Sstevel@tonic-gate hci1394_async_phy(hci1394_async_handle_t async_handle, cmd1394_cmd_t *cmd,
2371*0Sstevel@tonic-gate     h1394_cmd_priv_t *cmd_priv, int *result)
2372*0Sstevel@tonic-gate {
2373*0Sstevel@tonic-gate 	hci1394_basic_pkt_t header;
2374*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
2375*0Sstevel@tonic-gate 	int status;
2376*0Sstevel@tonic-gate 
2377*0Sstevel@tonic-gate 
2378*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2379*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
2380*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
2381*0Sstevel@tonic-gate 	ASSERT(result != NULL);
2382*0Sstevel@tonic-gate 
2383*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_phy_enter, HCI1394_TNF_HAL_STACK, "");
2384*0Sstevel@tonic-gate 
2385*0Sstevel@tonic-gate 	/*
2386*0Sstevel@tonic-gate 	 * make sure this call is during the current bus generation (i.e. no
2387*0Sstevel@tonic-gate 	 * bus resets have occured since this request was made.
2388*0Sstevel@tonic-gate 	 */
2389*0Sstevel@tonic-gate 	if (cmd_priv->bus_generation != hci1394_ohci_current_busgen(
2390*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
2391*0Sstevel@tonic-gate 		*result = H1394_STATUS_INVALID_BUSGEN;
2392*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_phy_exit,
2393*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2394*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2395*0Sstevel@tonic-gate 	}
2396*0Sstevel@tonic-gate 
2397*0Sstevel@tonic-gate 	/* Initialize the private HAL command structure */
2398*0Sstevel@tonic-gate 	hci1394_async_hcicmd_init(async_handle, cmd, cmd_priv, &hcicmd);
2399*0Sstevel@tonic-gate 
2400*0Sstevel@tonic-gate 	/* We do not allocate a tlabel for a PHY packet */
2401*0Sstevel@tonic-gate 	hcicmd->ac_tlabel_alloc = B_FALSE;
2402*0Sstevel@tonic-gate 
2403*0Sstevel@tonic-gate 	/*
2404*0Sstevel@tonic-gate 	 * Setup the packet header information for a ATREQ PHY packet Add in
2405*0Sstevel@tonic-gate 	 * the tcode, phy quadlet, and it's 1's complement.
2406*0Sstevel@tonic-gate 	 */
2407*0Sstevel@tonic-gate 	header.q1 = DESC_ATREQ_Q1_PHY;
2408*0Sstevel@tonic-gate 	header.q2 = cmd->cmd_u.q.quadlet_data;
2409*0Sstevel@tonic-gate 	header.q3 = ~header.q2;
2410*0Sstevel@tonic-gate 
2411*0Sstevel@tonic-gate 	/* Write request into the ATREQ Q. If we fail, we're out of space */
2412*0Sstevel@tonic-gate 	status = hci1394_q_at(async_handle->as_atreq_q, &hcicmd->ac_qcmd,
2413*0Sstevel@tonic-gate 	    &header, DESC_PKT_HDRLEN_AT_PHY, result);
2414*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
2415*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_phy_q_fail, HCI1394_TNF_HAL_ERROR,
2416*0Sstevel@tonic-gate 		    "");
2417*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_phy_exit,
2418*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2419*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2420*0Sstevel@tonic-gate 	}
2421*0Sstevel@tonic-gate 
2422*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_phy_exit, HCI1394_TNF_HAL_STACK, "");
2423*0Sstevel@tonic-gate 
2424*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2425*0Sstevel@tonic-gate }
2426*0Sstevel@tonic-gate 
2427*0Sstevel@tonic-gate 
2428*0Sstevel@tonic-gate /*
2429*0Sstevel@tonic-gate  * hci1394_async_write()
2430*0Sstevel@tonic-gate  *    Queue up ATREQ write. This could be either a block write or a quadlet
2431*0Sstevel@tonic-gate  *    write.
2432*0Sstevel@tonic-gate  */
2433*0Sstevel@tonic-gate int
hci1394_async_write(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,int * result)2434*0Sstevel@tonic-gate hci1394_async_write(hci1394_async_handle_t async_handle, cmd1394_cmd_t *cmd,
2435*0Sstevel@tonic-gate     h1394_cmd_priv_t *cmd_priv, int *result)
2436*0Sstevel@tonic-gate {
2437*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
2438*0Sstevel@tonic-gate 	hci1394_basic_pkt_t header;
2439*0Sstevel@tonic-gate 	int status;
2440*0Sstevel@tonic-gate 
2441*0Sstevel@tonic-gate 
2442*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2443*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
2444*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
2445*0Sstevel@tonic-gate 	ASSERT(result != NULL);
2446*0Sstevel@tonic-gate 
2447*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_write_enter, HCI1394_TNF_HAL_STACK, "");
2448*0Sstevel@tonic-gate 
2449*0Sstevel@tonic-gate 	/*
2450*0Sstevel@tonic-gate 	 * make sure this call is during the current bus generation (i.e. no
2451*0Sstevel@tonic-gate 	 * bus resets have occured since this request was made.
2452*0Sstevel@tonic-gate 	 */
2453*0Sstevel@tonic-gate 	if (cmd_priv->bus_generation != hci1394_ohci_current_busgen(
2454*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
2455*0Sstevel@tonic-gate 		*result = H1394_STATUS_INVALID_BUSGEN;
2456*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_write_exit,
2457*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2458*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2459*0Sstevel@tonic-gate 	}
2460*0Sstevel@tonic-gate 
2461*0Sstevel@tonic-gate 	/* Initialize the private HAL command structure */
2462*0Sstevel@tonic-gate 	hci1394_async_hcicmd_init(async_handle, cmd, cmd_priv, &hcicmd);
2463*0Sstevel@tonic-gate 	hcicmd->ac_dest = (uint_t)(cmd->cmd_addr >> IEEE1394_ADDR_PHY_ID_SHIFT);
2464*0Sstevel@tonic-gate 
2465*0Sstevel@tonic-gate 	/* allocate a tlabel for this request */
2466*0Sstevel@tonic-gate 	status = hci1394_tlabel_alloc(async_handle->as_tlabel, hcicmd->ac_dest,
2467*0Sstevel@tonic-gate 	    &hcicmd->ac_tlabel);
2468*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
2469*0Sstevel@tonic-gate 		*result = H1394_STATUS_EMPTY_TLABEL;
2470*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_write_tlb_fail,
2471*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2472*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_write_exit,
2473*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2474*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2475*0Sstevel@tonic-gate 	}
2476*0Sstevel@tonic-gate 
2477*0Sstevel@tonic-gate 	/*
2478*0Sstevel@tonic-gate 	 * Setup the packet header information for a ATREQ write packet. We
2479*0Sstevel@tonic-gate 	 * will set the tcode later on since this could be a block write or
2480*0Sstevel@tonic-gate 	 * a quadlet write. Set SRCBusId if this write is not a local bus
2481*0Sstevel@tonic-gate 	 * access. Copy in the speed, tlabel, and destination address.
2482*0Sstevel@tonic-gate 	 */
2483*0Sstevel@tonic-gate 	header.q1 = 0;
2484*0Sstevel@tonic-gate 	if ((hcicmd->ac_dest & IEEE1394_BUS_NUM_MASK) !=
2485*0Sstevel@tonic-gate 	    IEEE1394_BUS_NUM_MASK) {
2486*0Sstevel@tonic-gate 		header.q1 |= DESC_AT_SRCBUSID;
2487*0Sstevel@tonic-gate 	}
2488*0Sstevel@tonic-gate 	header.q1 |= HCI1394_DESC_AT_SPD_SET(cmd_priv->speed) |
2489*0Sstevel@tonic-gate 	    HCI1394_DESC_TLABEL_SET(hcicmd->ac_tlabel.tbi_tlabel);
2490*0Sstevel@tonic-gate 	header.q2 = (uint32_t)(cmd->cmd_addr >> 32);
2491*0Sstevel@tonic-gate 	header.q3 = (uint32_t)(cmd->cmd_addr & DESC_PKT_DESTOFFLO_MASK);
2492*0Sstevel@tonic-gate 
2493*0Sstevel@tonic-gate 	/* Register this command w/ its tlabel */
2494*0Sstevel@tonic-gate 	hci1394_tlabel_register(async_handle->as_tlabel, &hcicmd->ac_tlabel,
2495*0Sstevel@tonic-gate 	    hcicmd);
2496*0Sstevel@tonic-gate 
2497*0Sstevel@tonic-gate 	/* If this is a quadlet write ATREQ */
2498*0Sstevel@tonic-gate 	if (cmd->cmd_type == CMD1394_ASYNCH_WR_QUAD) {
2499*0Sstevel@tonic-gate 		/*
2500*0Sstevel@tonic-gate 		 * setup the tcode for a quadlet write request and copy in
2501*0Sstevel@tonic-gate 		 * the quadlet data. Endian issues will be taken care of in
2502*0Sstevel@tonic-gate 		 * hci1394_q_at().
2503*0Sstevel@tonic-gate 		 */
2504*0Sstevel@tonic-gate 		header.q1 |= DESC_ATREQ_Q1_QWR;
2505*0Sstevel@tonic-gate 		header.q4 = cmd->cmd_u.q.quadlet_data;
2506*0Sstevel@tonic-gate 
2507*0Sstevel@tonic-gate 		/*
2508*0Sstevel@tonic-gate 		 * Write the request into the ATREQ Q. If we fail, we are out
2509*0Sstevel@tonic-gate 		 * of space.
2510*0Sstevel@tonic-gate 		 */
2511*0Sstevel@tonic-gate 		status = hci1394_q_at(async_handle->as_atreq_q,
2512*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_WRITEQUAD,
2513*0Sstevel@tonic-gate 		    result);
2514*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
2515*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_write_q_fail,
2516*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
2517*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_write_exit,
2518*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
2519*0Sstevel@tonic-gate 			return (DDI_FAILURE);
2520*0Sstevel@tonic-gate 		}
2521*0Sstevel@tonic-gate 
2522*0Sstevel@tonic-gate 	/* This is a block write ATREQ */
2523*0Sstevel@tonic-gate 	} else {
2524*0Sstevel@tonic-gate 		/* setup the tcode and the length of the block write */
2525*0Sstevel@tonic-gate 		header.q1 |= DESC_ATREQ_Q1_BWR;
2526*0Sstevel@tonic-gate 		header.q4 = HCI1394_DESC_DATALEN_SET(cmd_priv->mblk.length);
2527*0Sstevel@tonic-gate 
2528*0Sstevel@tonic-gate 		/*
2529*0Sstevel@tonic-gate 		 * Write the request into the ATREQ Q. If we fail, we are out
2530*0Sstevel@tonic-gate 		 * of space. The data is in a mblk(s). We use a special
2531*0Sstevel@tonic-gate 		 * interface in the HAL/SL private command block to handle
2532*0Sstevel@tonic-gate 		 * partial transfers out of the mblk due to packet size
2533*0Sstevel@tonic-gate 		 * restrictions.
2534*0Sstevel@tonic-gate 		 */
2535*0Sstevel@tonic-gate 		status = hci1394_q_at_with_mblk(async_handle->as_atreq_q,
2536*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_WRITEBLOCK,
2537*0Sstevel@tonic-gate 		    &cmd_priv->mblk, result);
2538*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
2539*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_write_qmblk_fail,
2540*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
2541*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_write_exit,
2542*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
2543*0Sstevel@tonic-gate 			return (DDI_FAILURE);
2544*0Sstevel@tonic-gate 		}
2545*0Sstevel@tonic-gate 	}
2546*0Sstevel@tonic-gate 
2547*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_write_exit, HCI1394_TNF_HAL_STACK, "");
2548*0Sstevel@tonic-gate 
2549*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2550*0Sstevel@tonic-gate }
2551*0Sstevel@tonic-gate 
2552*0Sstevel@tonic-gate 
2553*0Sstevel@tonic-gate /*
2554*0Sstevel@tonic-gate  * hci1394_async_read()
2555*0Sstevel@tonic-gate  *    Queue up ATREQ read. This could be either a block read or a quadlet
2556*0Sstevel@tonic-gate  *    read.
2557*0Sstevel@tonic-gate  */
2558*0Sstevel@tonic-gate int
hci1394_async_read(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,int * result)2559*0Sstevel@tonic-gate hci1394_async_read(hci1394_async_handle_t async_handle, cmd1394_cmd_t *cmd,
2560*0Sstevel@tonic-gate     h1394_cmd_priv_t *cmd_priv, int *result)
2561*0Sstevel@tonic-gate {
2562*0Sstevel@tonic-gate 	hci1394_basic_pkt_t header;
2563*0Sstevel@tonic-gate 	int status;
2564*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
2565*0Sstevel@tonic-gate 
2566*0Sstevel@tonic-gate 
2567*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2568*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
2569*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
2570*0Sstevel@tonic-gate 	ASSERT(result != NULL);
2571*0Sstevel@tonic-gate 
2572*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_read_enter, HCI1394_TNF_HAL_STACK, "");
2573*0Sstevel@tonic-gate 
2574*0Sstevel@tonic-gate 	/*
2575*0Sstevel@tonic-gate 	 * make sure this call is during the current bus generation (i.e. no
2576*0Sstevel@tonic-gate 	 * bus resets have occured since this request was made.
2577*0Sstevel@tonic-gate 	 */
2578*0Sstevel@tonic-gate 	if (cmd_priv->bus_generation != hci1394_ohci_current_busgen(
2579*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
2580*0Sstevel@tonic-gate 		*result = H1394_STATUS_INVALID_BUSGEN;
2581*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_read_exit,
2582*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2583*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2584*0Sstevel@tonic-gate 	}
2585*0Sstevel@tonic-gate 
2586*0Sstevel@tonic-gate 	/* Initialize the private HAL command structure */
2587*0Sstevel@tonic-gate 	hci1394_async_hcicmd_init(async_handle, cmd, cmd_priv, &hcicmd);
2588*0Sstevel@tonic-gate 	hcicmd->ac_dest = (uint_t)(cmd->cmd_addr >> IEEE1394_ADDR_PHY_ID_SHIFT);
2589*0Sstevel@tonic-gate 
2590*0Sstevel@tonic-gate 	/* allocate a tlabel for this request */
2591*0Sstevel@tonic-gate 	status = hci1394_tlabel_alloc(async_handle->as_tlabel, hcicmd->ac_dest,
2592*0Sstevel@tonic-gate 	    &hcicmd->ac_tlabel);
2593*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
2594*0Sstevel@tonic-gate 		*result = H1394_STATUS_EMPTY_TLABEL;
2595*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_read_tlb_fail,
2596*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2597*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_read_exit,
2598*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2599*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2600*0Sstevel@tonic-gate 	}
2601*0Sstevel@tonic-gate 
2602*0Sstevel@tonic-gate 	/*
2603*0Sstevel@tonic-gate 	 * Setup the packet header information for a ATREQ read packet. We
2604*0Sstevel@tonic-gate 	 * will set the tcode later on since this could be a block read or
2605*0Sstevel@tonic-gate 	 * a quadlet read. Set SRCBusId if this read is not a local bus
2606*0Sstevel@tonic-gate 	 * access. Copy in the speed, tlabel, and destination address.
2607*0Sstevel@tonic-gate 	 */
2608*0Sstevel@tonic-gate 	header.q1 = 0;
2609*0Sstevel@tonic-gate 	if ((hcicmd->ac_dest & IEEE1394_BUS_NUM_MASK) !=
2610*0Sstevel@tonic-gate 	    IEEE1394_BUS_NUM_MASK) {
2611*0Sstevel@tonic-gate 		header.q1 |= DESC_AT_SRCBUSID;
2612*0Sstevel@tonic-gate 	}
2613*0Sstevel@tonic-gate 	header.q1 |= HCI1394_DESC_AT_SPD_SET(cmd_priv->speed) |
2614*0Sstevel@tonic-gate 	    HCI1394_DESC_TLABEL_SET(hcicmd->ac_tlabel.tbi_tlabel);
2615*0Sstevel@tonic-gate 	header.q2 = (uint32_t)(cmd->cmd_addr >> 32);
2616*0Sstevel@tonic-gate 	header.q3 = (uint32_t)(cmd->cmd_addr & DESC_PKT_DESTOFFLO_MASK);
2617*0Sstevel@tonic-gate 
2618*0Sstevel@tonic-gate 	/* Register this command w/ its tlabel */
2619*0Sstevel@tonic-gate 	hci1394_tlabel_register(async_handle->as_tlabel, &hcicmd->ac_tlabel,
2620*0Sstevel@tonic-gate 	    hcicmd);
2621*0Sstevel@tonic-gate 
2622*0Sstevel@tonic-gate 	/* If this is a quadlet read ATREQ */
2623*0Sstevel@tonic-gate 	if (cmd->cmd_type == CMD1394_ASYNCH_RD_QUAD) {
2624*0Sstevel@tonic-gate 		/* setup the tcode for a quadlet read request */
2625*0Sstevel@tonic-gate 		header.q1 |= DESC_ATREQ_Q1_QRD;
2626*0Sstevel@tonic-gate 		header.q4 = 0;
2627*0Sstevel@tonic-gate 
2628*0Sstevel@tonic-gate 		/*
2629*0Sstevel@tonic-gate 		 * Write the request into the ATREQ Q. If we fail, we are out
2630*0Sstevel@tonic-gate 		 * of space.
2631*0Sstevel@tonic-gate 		 */
2632*0Sstevel@tonic-gate 		status = hci1394_q_at(async_handle->as_atreq_q,
2633*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_READQUAD,
2634*0Sstevel@tonic-gate 		    result);
2635*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
2636*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_read_q_fail,
2637*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
2638*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_read_exit,
2639*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
2640*0Sstevel@tonic-gate 			return (DDI_FAILURE);
2641*0Sstevel@tonic-gate 		}
2642*0Sstevel@tonic-gate 
2643*0Sstevel@tonic-gate 	} else {
2644*0Sstevel@tonic-gate 		/* setup the tcode and the length of the block read */
2645*0Sstevel@tonic-gate 		header.q1 |= DESC_ATREQ_Q1_BRD;
2646*0Sstevel@tonic-gate 		header.q4 = HCI1394_DESC_DATALEN_SET(cmd_priv->mblk.length);
2647*0Sstevel@tonic-gate 
2648*0Sstevel@tonic-gate 		/*
2649*0Sstevel@tonic-gate 		 * Write the request into the ATREQ Q. If we fail, we are out
2650*0Sstevel@tonic-gate 		 * of space.
2651*0Sstevel@tonic-gate 		 */
2652*0Sstevel@tonic-gate 		status = hci1394_q_at(async_handle->as_atreq_q,
2653*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_READBLOCK,
2654*0Sstevel@tonic-gate 		    result);
2655*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
2656*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_read_qb_fail,
2657*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
2658*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_read_exit,
2659*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
2660*0Sstevel@tonic-gate 			return (DDI_FAILURE);
2661*0Sstevel@tonic-gate 		}
2662*0Sstevel@tonic-gate 	}
2663*0Sstevel@tonic-gate 
2664*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_read_exit, HCI1394_TNF_HAL_STACK, "");
2665*0Sstevel@tonic-gate 
2666*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2667*0Sstevel@tonic-gate }
2668*0Sstevel@tonic-gate 
2669*0Sstevel@tonic-gate 
2670*0Sstevel@tonic-gate /*
2671*0Sstevel@tonic-gate  * hci1394_async_lock()
2672*0Sstevel@tonic-gate  *    Queue up ATREQ lock. This could be either a 32-bit or 64-bit lock
2673*0Sstevel@tonic-gate  *    request.
2674*0Sstevel@tonic-gate  */
2675*0Sstevel@tonic-gate int
hci1394_async_lock(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,int * result)2676*0Sstevel@tonic-gate hci1394_async_lock(hci1394_async_handle_t async_handle, cmd1394_cmd_t *cmd,
2677*0Sstevel@tonic-gate     h1394_cmd_priv_t *cmd_priv, int *result)
2678*0Sstevel@tonic-gate {
2679*0Sstevel@tonic-gate 	hci1394_basic_pkt_t header;
2680*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
2681*0Sstevel@tonic-gate 	uint32_t data32[2];
2682*0Sstevel@tonic-gate 	uint64_t data64[2];
2683*0Sstevel@tonic-gate 	uint8_t *datap;
2684*0Sstevel@tonic-gate 	uint_t size;
2685*0Sstevel@tonic-gate 	int status;
2686*0Sstevel@tonic-gate 
2687*0Sstevel@tonic-gate 
2688*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2689*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
2690*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
2691*0Sstevel@tonic-gate 	ASSERT(result != NULL);
2692*0Sstevel@tonic-gate 
2693*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_lock_enter, HCI1394_TNF_HAL_STACK, "");
2694*0Sstevel@tonic-gate 
2695*0Sstevel@tonic-gate 	/*
2696*0Sstevel@tonic-gate 	 * make sure this call is during the current bus generation (i.e. no
2697*0Sstevel@tonic-gate 	 * bus resets have occured since this request was made.
2698*0Sstevel@tonic-gate 	 */
2699*0Sstevel@tonic-gate 	if (cmd_priv->bus_generation != hci1394_ohci_current_busgen(
2700*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
2701*0Sstevel@tonic-gate 		*result = H1394_STATUS_INVALID_BUSGEN;
2702*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_exit,
2703*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2704*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2705*0Sstevel@tonic-gate 	}
2706*0Sstevel@tonic-gate 
2707*0Sstevel@tonic-gate 	/* Initialize the private HAL command structure */
2708*0Sstevel@tonic-gate 	hci1394_async_hcicmd_init(async_handle, cmd, cmd_priv, &hcicmd);
2709*0Sstevel@tonic-gate 	hcicmd->ac_dest = (uint_t)(cmd->cmd_addr >> IEEE1394_ADDR_PHY_ID_SHIFT);
2710*0Sstevel@tonic-gate 
2711*0Sstevel@tonic-gate 	/* allocate a tlabel for this request */
2712*0Sstevel@tonic-gate 	status = hci1394_tlabel_alloc(async_handle->as_tlabel, hcicmd->ac_dest,
2713*0Sstevel@tonic-gate 	    &hcicmd->ac_tlabel);
2714*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
2715*0Sstevel@tonic-gate 		*result = H1394_STATUS_EMPTY_TLABEL;
2716*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_lock_tlb_fail,
2717*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2718*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_exit,
2719*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2720*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2721*0Sstevel@tonic-gate 	}
2722*0Sstevel@tonic-gate 
2723*0Sstevel@tonic-gate 	/* Register this command w/ its tlabel */
2724*0Sstevel@tonic-gate 	hci1394_tlabel_register(async_handle->as_tlabel, &hcicmd->ac_tlabel,
2725*0Sstevel@tonic-gate 	    hcicmd);
2726*0Sstevel@tonic-gate 
2727*0Sstevel@tonic-gate 	/*
2728*0Sstevel@tonic-gate 	 * Setup the packet header information for a ATREQ lock packet. Set
2729*0Sstevel@tonic-gate 	 * the tcode up as a lock request. Set SRCBusId if this lock is not a
2730*0Sstevel@tonic-gate 	 * local bus access. Copy in the speed, tlabel, and destination
2731*0Sstevel@tonic-gate 	 * address.
2732*0Sstevel@tonic-gate 	 */
2733*0Sstevel@tonic-gate 	header.q1 = DESC_ATREQ_Q1_LCK;
2734*0Sstevel@tonic-gate 	if ((hcicmd->ac_dest & IEEE1394_BUS_NUM_MASK) !=
2735*0Sstevel@tonic-gate 	    IEEE1394_BUS_NUM_MASK) {
2736*0Sstevel@tonic-gate 		header.q1 |= DESC_AT_SRCBUSID;
2737*0Sstevel@tonic-gate 	}
2738*0Sstevel@tonic-gate 	header.q1 |= HCI1394_DESC_AT_SPD_SET(cmd_priv->speed) |
2739*0Sstevel@tonic-gate 	    HCI1394_DESC_TLABEL_SET(hcicmd->ac_tlabel.tbi_tlabel);
2740*0Sstevel@tonic-gate 	header.q2 = (uint32_t)(cmd->cmd_addr >> 32);
2741*0Sstevel@tonic-gate 	header.q3 = (uint32_t)(cmd->cmd_addr & DESC_PKT_DESTOFFLO_MASK);
2742*0Sstevel@tonic-gate 
2743*0Sstevel@tonic-gate 	/*
2744*0Sstevel@tonic-gate 	 * Setup the lock length based on what size lock operation we are
2745*0Sstevel@tonic-gate 	 * performing. If it isn't a lock32 or lock64, we have encountered an
2746*0Sstevel@tonic-gate 	 * internal error. Copy the lock data into a local data buffer. Perform
2747*0Sstevel@tonic-gate 	 * a byte swap if it is an arithmetic lock operation and we are on a
2748*0Sstevel@tonic-gate 	 * little endian machine.
2749*0Sstevel@tonic-gate 	 */
2750*0Sstevel@tonic-gate 	if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_32) {
2751*0Sstevel@tonic-gate 		size = DESC_TWO_QUADS;
2752*0Sstevel@tonic-gate 		header.q4 = HCI1394_DESC_DATALEN_SET(size) |
2753*0Sstevel@tonic-gate 		    HCI1394_DESC_EXTTCODE_SET(cmd->cmd_u.l32.lock_type);
2754*0Sstevel@tonic-gate 		data32[0] = HCI1394_ARITH_LOCK_SWAP32(
2755*0Sstevel@tonic-gate 		    cmd->cmd_u.l32.lock_type, cmd->cmd_u.l32.arg_value);
2756*0Sstevel@tonic-gate 		data32[1] = HCI1394_ARITH_LOCK_SWAP32(
2757*0Sstevel@tonic-gate 		    cmd->cmd_u.l32.lock_type, cmd->cmd_u.l32.data_value);
2758*0Sstevel@tonic-gate 		datap = (uint8_t *)data32;
2759*0Sstevel@tonic-gate 	} else if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_64) {
2760*0Sstevel@tonic-gate 		size = DESC_TWO_OCTLETS;
2761*0Sstevel@tonic-gate 		header.q4 = HCI1394_DESC_DATALEN_SET(size) |
2762*0Sstevel@tonic-gate 		    HCI1394_DESC_EXTTCODE_SET(cmd->cmd_u.l64.lock_type);
2763*0Sstevel@tonic-gate 		data64[0] = HCI1394_ARITH_LOCK_SWAP64(
2764*0Sstevel@tonic-gate 		    cmd->cmd_u.l64.lock_type, cmd->cmd_u.l64.arg_value);
2765*0Sstevel@tonic-gate 		data64[1] = HCI1394_ARITH_LOCK_SWAP64(
2766*0Sstevel@tonic-gate 		    cmd->cmd_u.l64.lock_type, cmd->cmd_u.l64.data_value);
2767*0Sstevel@tonic-gate 		datap = (uint8_t *)data64;
2768*0Sstevel@tonic-gate 	} else {
2769*0Sstevel@tonic-gate 		*result = H1394_STATUS_INTERNAL_ERROR;
2770*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_lock_length_fail,
2771*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2772*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_exit,
2773*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2774*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2775*0Sstevel@tonic-gate 	}
2776*0Sstevel@tonic-gate 
2777*0Sstevel@tonic-gate 	/* Write request into the ATREQ Q. If we fail, we're out of space */
2778*0Sstevel@tonic-gate 	status = hci1394_q_at_with_data(async_handle->as_atreq_q,
2779*0Sstevel@tonic-gate 	    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_LOCK, datap, size,
2780*0Sstevel@tonic-gate 	    result);
2781*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
2782*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_lock_q_fail,
2783*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2784*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_exit,
2785*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2786*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2787*0Sstevel@tonic-gate 	}
2788*0Sstevel@tonic-gate 
2789*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_lock_exit, HCI1394_TNF_HAL_STACK, "");
2790*0Sstevel@tonic-gate 
2791*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2792*0Sstevel@tonic-gate }
2793*0Sstevel@tonic-gate 
2794*0Sstevel@tonic-gate 
2795*0Sstevel@tonic-gate /*
2796*0Sstevel@tonic-gate  * hci1394_async_write_response()
2797*0Sstevel@tonic-gate  *    Send a write ATRESP. This routine should be called from the Services
2798*0Sstevel@tonic-gate  *    layer to send a response to a received write request (ARREQ). The same
2799*0Sstevel@tonic-gate  *    response is sent to a quadlet and block write request.
2800*0Sstevel@tonic-gate  */
2801*0Sstevel@tonic-gate int
hci1394_async_write_response(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,int * result)2802*0Sstevel@tonic-gate hci1394_async_write_response(hci1394_async_handle_t async_handle,
2803*0Sstevel@tonic-gate     cmd1394_cmd_t *cmd, h1394_cmd_priv_t *cmd_priv, int *result)
2804*0Sstevel@tonic-gate {
2805*0Sstevel@tonic-gate 	hci1394_basic_pkt_t header;
2806*0Sstevel@tonic-gate 	int status;
2807*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
2808*0Sstevel@tonic-gate 
2809*0Sstevel@tonic-gate 
2810*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2811*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
2812*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
2813*0Sstevel@tonic-gate 	ASSERT(result != NULL);
2814*0Sstevel@tonic-gate 
2815*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_write_response_enter,
2816*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2817*0Sstevel@tonic-gate 
2818*0Sstevel@tonic-gate 	/*
2819*0Sstevel@tonic-gate 	 * make sure this call is during the current bus generation (i.e. no
2820*0Sstevel@tonic-gate 	 * bus resets have occured since this request was made.
2821*0Sstevel@tonic-gate 	 */
2822*0Sstevel@tonic-gate 	if (cmd_priv->bus_generation != hci1394_ohci_current_busgen(
2823*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
2824*0Sstevel@tonic-gate 		*result = H1394_STATUS_INVALID_BUSGEN;
2825*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_write_response_exit,
2826*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2827*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2828*0Sstevel@tonic-gate 	}
2829*0Sstevel@tonic-gate 
2830*0Sstevel@tonic-gate 	/*
2831*0Sstevel@tonic-gate 	 * setup a shortcut to the hal private command area. Copy the generation
2832*0Sstevel@tonic-gate 	 * to the Q area so that we can check the generation when the AT Q is
2833*0Sstevel@tonic-gate 	 * locked. This prevents us from loosing commands due to race
2834*0Sstevel@tonic-gate 	 * conditions.
2835*0Sstevel@tonic-gate 	 */
2836*0Sstevel@tonic-gate 	hcicmd = (hci1394_async_cmd_t *)cmd_priv->hal_overhead;
2837*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_generation = cmd_priv->bus_generation;
2838*0Sstevel@tonic-gate 
2839*0Sstevel@tonic-gate 	/*
2840*0Sstevel@tonic-gate 	 * Setup the packet header information for a ATRESP write packet. Set
2841*0Sstevel@tonic-gate 	 * the tcode for a write response. Set SRCBusId if the addr is not a
2842*0Sstevel@tonic-gate 	 * local bus address. Copy in the speed, tlabel, and response code.
2843*0Sstevel@tonic-gate 	 */
2844*0Sstevel@tonic-gate 	header.q1 = DESC_ATRESP_Q1_WR;
2845*0Sstevel@tonic-gate 	if ((cmd->nodeID & IEEE1394_BUS_NUM_MASK) != IEEE1394_BUS_NUM_MASK) {
2846*0Sstevel@tonic-gate 		header.q1 |= DESC_AT_SRCBUSID;
2847*0Sstevel@tonic-gate 	}
2848*0Sstevel@tonic-gate 	header.q1 |= HCI1394_DESC_AT_SPD_SET(cmd_priv->speed) |
2849*0Sstevel@tonic-gate 	    HCI1394_DESC_TLABEL_SET(hcicmd->ac_tlabel.tbi_tlabel);
2850*0Sstevel@tonic-gate 	header.q2 = (HCI1394_DESC_DESTID_SET(cmd->nodeID) |
2851*0Sstevel@tonic-gate 	    HCI1394_DESC_RCODE_SET(cmd->cmd_result));
2852*0Sstevel@tonic-gate 	header.q3 = 0;
2853*0Sstevel@tonic-gate 
2854*0Sstevel@tonic-gate 	/* Write response into the ATRESP Q. If we fail, we're out of space */
2855*0Sstevel@tonic-gate 	status = hci1394_q_at(async_handle->as_atresp_q, &hcicmd->ac_qcmd,
2856*0Sstevel@tonic-gate 	    &header, DESC_PKT_HDRLEN_AT_WRITE_RESP, result);
2857*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
2858*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_async_write_response_q_fail,
2859*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR, "");
2860*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_write_response_exit,
2861*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2862*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2863*0Sstevel@tonic-gate 	}
2864*0Sstevel@tonic-gate 
2865*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_write_response_exit,
2866*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2867*0Sstevel@tonic-gate 
2868*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
2869*0Sstevel@tonic-gate }
2870*0Sstevel@tonic-gate 
2871*0Sstevel@tonic-gate 
2872*0Sstevel@tonic-gate /*
2873*0Sstevel@tonic-gate  * hci1394_async_read_response()
2874*0Sstevel@tonic-gate  *    Send a read ATRESP. This routine should be called from the Services
2875*0Sstevel@tonic-gate  *    layer to send a response to a received read request (ARREQ). The
2876*0Sstevel@tonic-gate  *    response will differ between quadlet/block read requests.
2877*0Sstevel@tonic-gate  */
2878*0Sstevel@tonic-gate int
hci1394_async_read_response(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,int * result)2879*0Sstevel@tonic-gate hci1394_async_read_response(hci1394_async_handle_t async_handle,
2880*0Sstevel@tonic-gate     cmd1394_cmd_t *cmd, h1394_cmd_priv_t *cmd_priv, int *result)
2881*0Sstevel@tonic-gate {
2882*0Sstevel@tonic-gate 	hci1394_basic_pkt_t header;
2883*0Sstevel@tonic-gate 	int status;
2884*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
2885*0Sstevel@tonic-gate 
2886*0Sstevel@tonic-gate 
2887*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
2888*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
2889*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
2890*0Sstevel@tonic-gate 	ASSERT(result != NULL);
2891*0Sstevel@tonic-gate 
2892*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_read_response_enter,
2893*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
2894*0Sstevel@tonic-gate 
2895*0Sstevel@tonic-gate 	/*
2896*0Sstevel@tonic-gate 	 * make sure this call is during the current bus generation (i.e. no
2897*0Sstevel@tonic-gate 	 * bus resets have occured since this request was made.
2898*0Sstevel@tonic-gate 	 */
2899*0Sstevel@tonic-gate 	if (cmd_priv->bus_generation != hci1394_ohci_current_busgen(
2900*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
2901*0Sstevel@tonic-gate 		*result = H1394_STATUS_INVALID_BUSGEN;
2902*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_read_response_exit,
2903*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
2904*0Sstevel@tonic-gate 		return (DDI_FAILURE);
2905*0Sstevel@tonic-gate 	}
2906*0Sstevel@tonic-gate 
2907*0Sstevel@tonic-gate 	/*
2908*0Sstevel@tonic-gate 	 * setup a shortcut to the hal private command area. Copy the generation
2909*0Sstevel@tonic-gate 	 * to the Q area so that we can check the generation when the AT Q is
2910*0Sstevel@tonic-gate 	 * locked. This prevents us from loosing commands due to race
2911*0Sstevel@tonic-gate 	 * conditions.
2912*0Sstevel@tonic-gate 	 */
2913*0Sstevel@tonic-gate 	hcicmd = (hci1394_async_cmd_t *)cmd_priv->hal_overhead;
2914*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_generation = cmd_priv->bus_generation;
2915*0Sstevel@tonic-gate 
2916*0Sstevel@tonic-gate 	/*
2917*0Sstevel@tonic-gate 	 * Setup the packet header information for a ATRESP read packet. we
2918*0Sstevel@tonic-gate 	 * will set the tcode later based on type of read response. Set
2919*0Sstevel@tonic-gate 	 * SRCBusId if the addr is not a local bus address. Copy in the
2920*0Sstevel@tonic-gate 	 * speed, tlabel, and response code.
2921*0Sstevel@tonic-gate 	 */
2922*0Sstevel@tonic-gate 	header.q1 = 0;
2923*0Sstevel@tonic-gate 	if ((cmd->nodeID & IEEE1394_BUS_NUM_MASK) != IEEE1394_BUS_NUM_MASK) {
2924*0Sstevel@tonic-gate 		header.q1 |= DESC_AT_SRCBUSID;
2925*0Sstevel@tonic-gate 	}
2926*0Sstevel@tonic-gate 	header.q1 |= HCI1394_DESC_AT_SPD_SET(cmd_priv->speed) |
2927*0Sstevel@tonic-gate 	    HCI1394_DESC_TLABEL_SET(hcicmd->ac_tlabel.tbi_tlabel);
2928*0Sstevel@tonic-gate 	header.q2 = (uint32_t)(HCI1394_DESC_DESTID_SET(cmd->nodeID) |
2929*0Sstevel@tonic-gate 	    HCI1394_DESC_RCODE_SET(cmd->cmd_result));
2930*0Sstevel@tonic-gate 	header.q3 = 0;
2931*0Sstevel@tonic-gate 
2932*0Sstevel@tonic-gate 	/* if the response is a read quadlet response */
2933*0Sstevel@tonic-gate 	if (cmd->cmd_type == CMD1394_ASYNCH_RD_QUAD) {
2934*0Sstevel@tonic-gate 		/*
2935*0Sstevel@tonic-gate 		 * setup the tcode for a quadlet read response, If the
2936*0Sstevel@tonic-gate 		 * response code is not resp complete.
2937*0Sstevel@tonic-gate 		 */
2938*0Sstevel@tonic-gate 		header.q1 |= DESC_ATRESP_Q1_QRD;
2939*0Sstevel@tonic-gate 		if (cmd->cmd_result == IEEE1394_RESP_COMPLETE) {
2940*0Sstevel@tonic-gate 			header.q4 = cmd->cmd_u.q.quadlet_data;
2941*0Sstevel@tonic-gate 		} else {
2942*0Sstevel@tonic-gate 			header.q4 = 0x0;
2943*0Sstevel@tonic-gate 		}
2944*0Sstevel@tonic-gate 
2945*0Sstevel@tonic-gate 		/*
2946*0Sstevel@tonic-gate 		 * Write response into the ATRESP Q. If we fail, we're out of
2947*0Sstevel@tonic-gate 		 * space.
2948*0Sstevel@tonic-gate 		 */
2949*0Sstevel@tonic-gate 		status = hci1394_q_at(async_handle->as_atresp_q,
2950*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_READQUAD_RESP,
2951*0Sstevel@tonic-gate 		    result);
2952*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
2953*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_read_response_q_fail,
2954*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
2955*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_read_response_exit,
2956*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
2957*0Sstevel@tonic-gate 			return (DDI_FAILURE);
2958*0Sstevel@tonic-gate 		}
2959*0Sstevel@tonic-gate 
2960*0Sstevel@tonic-gate 	/*
2961*0Sstevel@tonic-gate 	 * the response is a block read response. If the result is not a
2962*0Sstevel@tonic-gate 	 * resp complete, we are not going to send any data back.
2963*0Sstevel@tonic-gate 	 */
2964*0Sstevel@tonic-gate 	} else if ((cmd->cmd_type == CMD1394_ASYNCH_RD_BLOCK) &&
2965*0Sstevel@tonic-gate 	    (cmd->cmd_result != IEEE1394_RESP_COMPLETE)) {
2966*0Sstevel@tonic-gate 		/*
2967*0Sstevel@tonic-gate 		 * Setup the tcode for a block read response, set the data
2968*0Sstevel@tonic-gate 		 * length to zero since we had an error.
2969*0Sstevel@tonic-gate 		 */
2970*0Sstevel@tonic-gate 		header.q1 |= DESC_ATRESP_Q1_BRD;
2971*0Sstevel@tonic-gate 		header.q4 = 0x0;
2972*0Sstevel@tonic-gate 
2973*0Sstevel@tonic-gate 		/*
2974*0Sstevel@tonic-gate 		 * Write response into the ATRESP Q. If we fail, we're out of
2975*0Sstevel@tonic-gate 		 * space.
2976*0Sstevel@tonic-gate 		 */
2977*0Sstevel@tonic-gate 		status = hci1394_q_at(async_handle->as_atresp_q,
2978*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header,
2979*0Sstevel@tonic-gate 		    DESC_PKT_HDRLEN_AT_READBLOCK_RESP, result);
2980*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
2981*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_read_response_qbf_fail,
2982*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
2983*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_read_response_exit,
2984*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
2985*0Sstevel@tonic-gate 			return (DDI_FAILURE);
2986*0Sstevel@tonic-gate 		}
2987*0Sstevel@tonic-gate 
2988*0Sstevel@tonic-gate 	/*
2989*0Sstevel@tonic-gate 	 * the response is a block read response with a resp complete for the
2990*0Sstevel@tonic-gate 	 * response code. Send back the read data.
2991*0Sstevel@tonic-gate 	 */
2992*0Sstevel@tonic-gate 	} else {
2993*0Sstevel@tonic-gate 		/*
2994*0Sstevel@tonic-gate 		 * Setup the tcode for a block read response, setup the data
2995*0Sstevel@tonic-gate 		 * length.
2996*0Sstevel@tonic-gate 		 */
2997*0Sstevel@tonic-gate 		header.q1 |= DESC_ATRESP_Q1_BRD;
2998*0Sstevel@tonic-gate 		header.q4 = HCI1394_DESC_DATALEN_SET(cmd->cmd_u.b.blk_length);
2999*0Sstevel@tonic-gate 
3000*0Sstevel@tonic-gate 		/*
3001*0Sstevel@tonic-gate 		 * Write response into the ATRESP Q. If we fail, we're out of
3002*0Sstevel@tonic-gate 		 * space. Use the data in the mblk.
3003*0Sstevel@tonic-gate 		 */
3004*0Sstevel@tonic-gate 		status = hci1394_q_at_with_mblk(async_handle->as_atresp_q,
3005*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header,
3006*0Sstevel@tonic-gate 		    DESC_PKT_HDRLEN_AT_READBLOCK_RESP, &cmd_priv->mblk, result);
3007*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
3008*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_read_response_qb_fail,
3009*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
3010*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_read_response_exit,
3011*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
3012*0Sstevel@tonic-gate 			return (DDI_FAILURE);
3013*0Sstevel@tonic-gate 		}
3014*0Sstevel@tonic-gate 	}
3015*0Sstevel@tonic-gate 
3016*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_read_response_exit,
3017*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3018*0Sstevel@tonic-gate 
3019*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
3020*0Sstevel@tonic-gate }
3021*0Sstevel@tonic-gate 
3022*0Sstevel@tonic-gate 
3023*0Sstevel@tonic-gate /*
3024*0Sstevel@tonic-gate  * hci1394_async_lock_response()
3025*0Sstevel@tonic-gate  *    Send a lock ATRESP. This routine should be called from the Services
3026*0Sstevel@tonic-gate  *    layer to send a response to a received lock request (ARREQ). The
3027*0Sstevel@tonic-gate  *    response will differ between 32-bit/64-bit lock requests.
3028*0Sstevel@tonic-gate  */
3029*0Sstevel@tonic-gate int
hci1394_async_lock_response(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,int * result)3030*0Sstevel@tonic-gate hci1394_async_lock_response(hci1394_async_handle_t async_handle,
3031*0Sstevel@tonic-gate     cmd1394_cmd_t *cmd, h1394_cmd_priv_t *cmd_priv, int *result)
3032*0Sstevel@tonic-gate {
3033*0Sstevel@tonic-gate 	hci1394_basic_pkt_t header;
3034*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
3035*0Sstevel@tonic-gate 	uint32_t data32;
3036*0Sstevel@tonic-gate 	uint64_t data64;
3037*0Sstevel@tonic-gate 	uint8_t *datap;
3038*0Sstevel@tonic-gate 	uint_t size;
3039*0Sstevel@tonic-gate 	int status;
3040*0Sstevel@tonic-gate 
3041*0Sstevel@tonic-gate 
3042*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3043*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
3044*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
3045*0Sstevel@tonic-gate 	ASSERT(result != NULL);
3046*0Sstevel@tonic-gate 
3047*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_lock_response_enter,
3048*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3049*0Sstevel@tonic-gate 
3050*0Sstevel@tonic-gate 	/*
3051*0Sstevel@tonic-gate 	 * make sure this call is during the current bus generation (i.e. no
3052*0Sstevel@tonic-gate 	 * bus resets have occured since this request was made.
3053*0Sstevel@tonic-gate 	 */
3054*0Sstevel@tonic-gate 	if (cmd_priv->bus_generation != hci1394_ohci_current_busgen(
3055*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
3056*0Sstevel@tonic-gate 		*result = H1394_STATUS_INVALID_BUSGEN;
3057*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_response_exit,
3058*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
3059*0Sstevel@tonic-gate 		return (DDI_FAILURE);
3060*0Sstevel@tonic-gate 	}
3061*0Sstevel@tonic-gate 
3062*0Sstevel@tonic-gate 	/*
3063*0Sstevel@tonic-gate 	 * setup a shortcut to the hal private command area. Copy the generation
3064*0Sstevel@tonic-gate 	 * to the Q area so that we can check the generation when the AT Q is
3065*0Sstevel@tonic-gate 	 * locked. This prevents us from loosing commands due to race
3066*0Sstevel@tonic-gate 	 * conditions.
3067*0Sstevel@tonic-gate 	 */
3068*0Sstevel@tonic-gate 	hcicmd = (hci1394_async_cmd_t *)cmd_priv->hal_overhead;
3069*0Sstevel@tonic-gate 	hcicmd->ac_qcmd.qc_generation = cmd_priv->bus_generation;
3070*0Sstevel@tonic-gate 
3071*0Sstevel@tonic-gate 	/*
3072*0Sstevel@tonic-gate 	 * Setup the packet header information for a ATRESP lock packet. Set
3073*0Sstevel@tonic-gate 	 * the tcode for a lock response. Set SRCBusId if the addr is not a
3074*0Sstevel@tonic-gate 	 * local bus address. Copy in the speed, tlabel, and response code.
3075*0Sstevel@tonic-gate 	 */
3076*0Sstevel@tonic-gate 	header.q1 = DESC_ATRESP_Q1_LCK;
3077*0Sstevel@tonic-gate 	if ((cmd->nodeID & IEEE1394_BUS_NUM_MASK) != IEEE1394_BUS_NUM_MASK) {
3078*0Sstevel@tonic-gate 		header.q1 |= DESC_AT_SRCBUSID;
3079*0Sstevel@tonic-gate 	}
3080*0Sstevel@tonic-gate 	header.q1 |= HCI1394_DESC_AT_SPD_SET(cmd_priv->speed) |
3081*0Sstevel@tonic-gate 	    HCI1394_DESC_TLABEL_SET(hcicmd->ac_tlabel.tbi_tlabel);
3082*0Sstevel@tonic-gate 	header.q2 = (uint32_t)(HCI1394_DESC_DESTID_SET(cmd->nodeID) |
3083*0Sstevel@tonic-gate 	    HCI1394_DESC_RCODE_SET(cmd->cmd_result));
3084*0Sstevel@tonic-gate 	header.q3 = 0;
3085*0Sstevel@tonic-gate 
3086*0Sstevel@tonic-gate 	/*
3087*0Sstevel@tonic-gate 	 * If the lock result is not a resp complete, we are not going to send
3088*0Sstevel@tonic-gate 	 * any data back.with the response.
3089*0Sstevel@tonic-gate 	 */
3090*0Sstevel@tonic-gate 	if (cmd->cmd_result != IEEE1394_RESP_COMPLETE) {
3091*0Sstevel@tonic-gate 		/* set response size to 0 for error. Set the extended tcode */
3092*0Sstevel@tonic-gate 		size = 0;
3093*0Sstevel@tonic-gate 		if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_32) {
3094*0Sstevel@tonic-gate 			header.q4 = HCI1394_DESC_DATALEN_SET(size) |
3095*0Sstevel@tonic-gate 			    HCI1394_DESC_EXTTCODE_SET(cmd->cmd_u.l32.lock_type);
3096*0Sstevel@tonic-gate 		} else {
3097*0Sstevel@tonic-gate 			header.q4 = HCI1394_DESC_DATALEN_SET(size) |
3098*0Sstevel@tonic-gate 			    HCI1394_DESC_EXTTCODE_SET(cmd->cmd_u.l64.lock_type);
3099*0Sstevel@tonic-gate 		}
3100*0Sstevel@tonic-gate 
3101*0Sstevel@tonic-gate 		/*
3102*0Sstevel@tonic-gate 		 * Write response into the ATRESP Q. If we fail, we're out of
3103*0Sstevel@tonic-gate 		 * space.
3104*0Sstevel@tonic-gate 		 */
3105*0Sstevel@tonic-gate 		status = hci1394_q_at(async_handle->as_atresp_q,
3106*0Sstevel@tonic-gate 		    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_LOCK_RESP,
3107*0Sstevel@tonic-gate 		    result);
3108*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
3109*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_q_alloc_fail,
3110*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
3111*0Sstevel@tonic-gate 			TNF_PROBE_0_DEBUG(hci1394_async_lock_response_exit,
3112*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_STACK, "");
3113*0Sstevel@tonic-gate 			return (DDI_FAILURE);
3114*0Sstevel@tonic-gate 		}
3115*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_response_exit,
3116*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
3117*0Sstevel@tonic-gate 		return (DDI_SUCCESS);
3118*0Sstevel@tonic-gate 	}
3119*0Sstevel@tonic-gate 
3120*0Sstevel@tonic-gate 	/*
3121*0Sstevel@tonic-gate 	 * if the lock result is resp complete, setup the size of the response
3122*0Sstevel@tonic-gate 	 * depending on the lock size and copy the lock response data into a
3123*0Sstevel@tonic-gate 	 * local buffer. If the lock response is an arithmetic operation, swap
3124*0Sstevel@tonic-gate 	 * the data on little endian machines. If we don't know what type of
3125*0Sstevel@tonic-gate 	 * lock operation it is, someone has corrupted the command since we
3126*0Sstevel@tonic-gate 	 * had received the ARREQ.
3127*0Sstevel@tonic-gate 	 */
3128*0Sstevel@tonic-gate 	if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_32) {
3129*0Sstevel@tonic-gate 		size = IEEE1394_QUADLET;
3130*0Sstevel@tonic-gate 		header.q4 = HCI1394_DESC_DATALEN_SET(size) |
3131*0Sstevel@tonic-gate 		    HCI1394_DESC_EXTTCODE_SET(cmd->cmd_u.l32.lock_type);
3132*0Sstevel@tonic-gate 		data32 = HCI1394_ARITH_LOCK_SWAP32(
3133*0Sstevel@tonic-gate 		    cmd->cmd_u.l32.lock_type, cmd->cmd_u.l32.old_value);
3134*0Sstevel@tonic-gate 		datap = (uint8_t *)&data32;
3135*0Sstevel@tonic-gate 	} else if (cmd->cmd_type == CMD1394_ASYNCH_LOCK_64) {
3136*0Sstevel@tonic-gate 		size = IEEE1394_OCTLET;
3137*0Sstevel@tonic-gate 		header.q4 = HCI1394_DESC_DATALEN_SET(size) |
3138*0Sstevel@tonic-gate 		    HCI1394_DESC_EXTTCODE_SET(cmd->cmd_u.l64.lock_type);
3139*0Sstevel@tonic-gate 		data64 = HCI1394_ARITH_LOCK_SWAP64(
3140*0Sstevel@tonic-gate 		    cmd->cmd_u.l64.lock_type, cmd->cmd_u.l64.old_value);
3141*0Sstevel@tonic-gate 		datap = (uint8_t *)&data64;
3142*0Sstevel@tonic-gate 	} else {
3143*0Sstevel@tonic-gate 		*result = H1394_STATUS_INTERNAL_ERROR;
3144*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_lock_type_fail, HCI1394_TNF_HAL_ERROR, "");
3145*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_response_exit,
3146*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
3147*0Sstevel@tonic-gate 		return (DDI_FAILURE);
3148*0Sstevel@tonic-gate 	}
3149*0Sstevel@tonic-gate 
3150*0Sstevel@tonic-gate 	/*
3151*0Sstevel@tonic-gate 	 * Write response into the ATRESP Q. If we fail, we're out of space.
3152*0Sstevel@tonic-gate 	 * Use the local data buffer that we copied the data to above.
3153*0Sstevel@tonic-gate 	 */
3154*0Sstevel@tonic-gate 	status = hci1394_q_at_with_data(async_handle->as_atresp_q,
3155*0Sstevel@tonic-gate 	    &hcicmd->ac_qcmd, &header, DESC_PKT_HDRLEN_AT_LOCK_RESP, datap,
3156*0Sstevel@tonic-gate 	    size, result);
3157*0Sstevel@tonic-gate 	if (status != DDI_SUCCESS) {
3158*0Sstevel@tonic-gate 		TNF_PROBE_0(hci1394_q_alloc_fail, HCI1394_TNF_HAL_ERROR, "");
3159*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_lock_response_exit,
3160*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
3161*0Sstevel@tonic-gate 		return (DDI_FAILURE);
3162*0Sstevel@tonic-gate 	}
3163*0Sstevel@tonic-gate 
3164*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_lock_response_exit,
3165*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3166*0Sstevel@tonic-gate 
3167*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
3168*0Sstevel@tonic-gate }
3169*0Sstevel@tonic-gate 
3170*0Sstevel@tonic-gate 
3171*0Sstevel@tonic-gate /*
3172*0Sstevel@tonic-gate  * hci1394_async_response_complete()
3173*0Sstevel@tonic-gate  *    Free up space allocted during an ARREQ.  This is called when the target
3174*0Sstevel@tonic-gate  *    driver and Services Layer are done with a command which was by the HAL
3175*0Sstevel@tonic-gate  *    during ARREQ processing.  This routine will also free up any allocated
3176*0Sstevel@tonic-gate  *    mblks.
3177*0Sstevel@tonic-gate  *
3178*0Sstevel@tonic-gate  *    NOTE: a target driver can hold on to a block write ARREQ mblk by setting
3179*0Sstevel@tonic-gate  *    the mblk pointer to NULL.  This ONLY applies to block write ARREQs. The
3180*0Sstevel@tonic-gate  *    HAL will no longer track the mblk for this case.
3181*0Sstevel@tonic-gate  */
3182*0Sstevel@tonic-gate void
hci1394_async_response_complete(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv)3183*0Sstevel@tonic-gate hci1394_async_response_complete(hci1394_async_handle_t async_handle,
3184*0Sstevel@tonic-gate     cmd1394_cmd_t *cmd, h1394_cmd_priv_t *cmd_priv)
3185*0Sstevel@tonic-gate {
3186*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
3187*0Sstevel@tonic-gate 
3188*0Sstevel@tonic-gate 
3189*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3190*0Sstevel@tonic-gate 	ASSERT(cmd != NULL);
3191*0Sstevel@tonic-gate 	ASSERT(cmd_priv != NULL);
3192*0Sstevel@tonic-gate 
3193*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_response_complete_enter,
3194*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3195*0Sstevel@tonic-gate 
3196*0Sstevel@tonic-gate 	hcicmd = (hci1394_async_cmd_t *)cmd_priv->hal_overhead;
3197*0Sstevel@tonic-gate 
3198*0Sstevel@tonic-gate 	/* If we allocated an mblk for this command */
3199*0Sstevel@tonic-gate 	if (hcicmd->ac_mblk_alloc == B_TRUE) {
3200*0Sstevel@tonic-gate 		/*
3201*0Sstevel@tonic-gate 		 * Don't free mblk if it is set to NULL. This allows a target
3202*0Sstevel@tonic-gate 		 * driver to hold on to it in the case of a block write ARREQ.
3203*0Sstevel@tonic-gate 		 */
3204*0Sstevel@tonic-gate 		if (cmd->cmd_u.b.data_block != NULL) {
3205*0Sstevel@tonic-gate 			freeb(cmd->cmd_u.b.data_block);
3206*0Sstevel@tonic-gate 		}
3207*0Sstevel@tonic-gate 	}
3208*0Sstevel@tonic-gate 
3209*0Sstevel@tonic-gate 	/* free up the 1394 framework command */
3210*0Sstevel@tonic-gate 	(void) h1394_free_cmd((void *)async_handle->as_drvinfo->di_sl_private,
3211*0Sstevel@tonic-gate 	    &cmd);
3212*0Sstevel@tonic-gate 
3213*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_response_complete_exit,
3214*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3215*0Sstevel@tonic-gate }
3216*0Sstevel@tonic-gate 
3217*0Sstevel@tonic-gate 
3218*0Sstevel@tonic-gate /*
3219*0Sstevel@tonic-gate  * hci1394_async_pending_timeout()
3220*0Sstevel@tonic-gate  *    This is the ARREQ Pending timeout callback routine.  It is called from
3221*0Sstevel@tonic-gate  *    the tlist code. There is a race condition with the ARRESP interrupt
3222*0Sstevel@tonic-gate  *    handler (hci1394_async_arresp_process) which requires a mutex to
3223*0Sstevel@tonic-gate  *    lock around the mark of the bad tlabel.
3224*0Sstevel@tonic-gate  *
3225*0Sstevel@tonic-gate  *    Once we enter this routine, the command has timed out. If the command is
3226*0Sstevel@tonic-gate  *    in both the ARRESP handler and here, we will consider it to have timed
3227*0Sstevel@tonic-gate  *    out. That code path handles the race condition more easily.
3228*0Sstevel@tonic-gate  */
3229*0Sstevel@tonic-gate static void
hci1394_async_pending_timeout(hci1394_tlist_node_t * node,void * arg)3230*0Sstevel@tonic-gate hci1394_async_pending_timeout(hci1394_tlist_node_t *node, void *arg)
3231*0Sstevel@tonic-gate {
3232*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3233*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
3234*0Sstevel@tonic-gate 
3235*0Sstevel@tonic-gate 
3236*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)arg;
3237*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3238*0Sstevel@tonic-gate 	ASSERT(node != NULL);
3239*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_pending_timeout_enter,
3240*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3241*0Sstevel@tonic-gate 
3242*0Sstevel@tonic-gate 	hcicmd = (hci1394_async_cmd_t *)node->tln_addr;
3243*0Sstevel@tonic-gate 
3244*0Sstevel@tonic-gate 	/*
3245*0Sstevel@tonic-gate 	 * We do NOT want to set the command state here. That should only be
3246*0Sstevel@tonic-gate 	 * done in the ISR. The state does nothing for us here.
3247*0Sstevel@tonic-gate 	 */
3248*0Sstevel@tonic-gate 
3249*0Sstevel@tonic-gate 	/*
3250*0Sstevel@tonic-gate 	 * We want a lock around tlabel_lookup/reading data into the cmd in the
3251*0Sstevel@tonic-gate 	 * ARRESP ISR processing and a lock around the tlabel_bad in this
3252*0Sstevel@tonic-gate 	 * routine. This ensures that we will not be touching the command
3253*0Sstevel@tonic-gate 	 * structure after we pass it up to the Services Layer. If we mark it as
3254*0Sstevel@tonic-gate 	 * bad first, the lookup will fail. If we get to the lookup first, the
3255*0Sstevel@tonic-gate 	 * pending list delete will fail in arresp_process() which will tell
3256*0Sstevel@tonic-gate 	 * that guy that we are in the middle of doing the timeout processing
3257*0Sstevel@tonic-gate 	 * for this command.  The ARRESP logic will just drop the response and
3258*0Sstevel@tonic-gate 	 * continue on.
3259*0Sstevel@tonic-gate 	 */
3260*0Sstevel@tonic-gate 	mutex_enter(&hcicmd->ac_async->as_atomic_lookup);
3261*0Sstevel@tonic-gate 	hci1394_tlabel_bad(async_handle->as_tlabel, &hcicmd->ac_tlabel);
3262*0Sstevel@tonic-gate 	mutex_exit(&hcicmd->ac_async->as_atomic_lookup);
3263*0Sstevel@tonic-gate 
3264*0Sstevel@tonic-gate 	/* Tell the Services Layer that the command has timed out */
3265*0Sstevel@tonic-gate 	h1394_cmd_is_complete(async_handle->as_drvinfo->di_sl_private,
3266*0Sstevel@tonic-gate 	    hcicmd->ac_cmd, H1394_AT_REQ, H1394_CMD_ETIMEOUT);
3267*0Sstevel@tonic-gate 
3268*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_pending_timeout_exit,
3269*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3270*0Sstevel@tonic-gate }
3271*0Sstevel@tonic-gate 
3272*0Sstevel@tonic-gate 
3273*0Sstevel@tonic-gate /*
3274*0Sstevel@tonic-gate  * hci1394_async_timeout_calc()
3275*0Sstevel@tonic-gate  *    Calculate the timeout for an ATRESP. When an ARREQ is received, this
3276*0Sstevel@tonic-gate  *    routine is called with the time the ARREQ was received. It returns the
3277*0Sstevel@tonic-gate  *    time when the ATRESP is considered to have timed out. We timeout after
3278*0Sstevel@tonic-gate  *    split_timeout has gone by. Split timeout and the returned value are in bus
3279*0Sstevel@tonic-gate  *    cycles.
3280*0Sstevel@tonic-gate  */
3281*0Sstevel@tonic-gate static uint_t
hci1394_async_timeout_calc(hci1394_async_handle_t async_handle,uint_t current_time)3282*0Sstevel@tonic-gate hci1394_async_timeout_calc(hci1394_async_handle_t async_handle,
3283*0Sstevel@tonic-gate     uint_t current_time)
3284*0Sstevel@tonic-gate {
3285*0Sstevel@tonic-gate 	uint_t split_timeout;
3286*0Sstevel@tonic-gate 	uint_t temp;
3287*0Sstevel@tonic-gate 	uint_t carry;
3288*0Sstevel@tonic-gate 	uint_t z;
3289*0Sstevel@tonic-gate 
3290*0Sstevel@tonic-gate 
3291*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_timeout_calc_enter,
3292*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3293*0Sstevel@tonic-gate 
3294*0Sstevel@tonic-gate 	/* Get the current split timeout */
3295*0Sstevel@tonic-gate 	split_timeout = hci1394_csr_split_timeout_get(async_handle->as_csr);
3296*0Sstevel@tonic-gate 
3297*0Sstevel@tonic-gate 	/*
3298*0Sstevel@tonic-gate 	 * The cycle count is broken up into two sections, the 3-bit seconds
3299*0Sstevel@tonic-gate 	 * field and the 13-bit cycle count. The cycle count is in 125uS
3300*0Sstevel@tonic-gate 	 * increments.  The maximum value of cycle count is 7999 (8000 is one
3301*0Sstevel@tonic-gate 	 * second). With 13-bits, we could store up to 8191. Therefore, we don't
3302*0Sstevel@tonic-gate 	 * have a simple 16-bit addition. Hence, the code we see below.
3303*0Sstevel@tonic-gate 	 */
3304*0Sstevel@tonic-gate 
3305*0Sstevel@tonic-gate 	/*
3306*0Sstevel@tonic-gate 	 * calculate the new cycle count based on the cycle count from current
3307*0Sstevel@tonic-gate 	 * time and the split timeout. If this new value is not greater than the
3308*0Sstevel@tonic-gate 	 * maximum cycle count, we don't have a carry. Go to the next step.
3309*0Sstevel@tonic-gate 	 */
3310*0Sstevel@tonic-gate 	temp = (current_time & OHCI_CYCLE_CNT_MASK) + (split_timeout &
3311*0Sstevel@tonic-gate 	    OHCI_CYCLE_CNT_MASK);
3312*0Sstevel@tonic-gate 	if (temp < OHCI_MAX_CYCLE_CNT) {
3313*0Sstevel@tonic-gate 		carry = 0;
3314*0Sstevel@tonic-gate 
3315*0Sstevel@tonic-gate 	/*
3316*0Sstevel@tonic-gate 	 * the new cycle count adds up to more than the maximum cycle count,
3317*0Sstevel@tonic-gate 	 * set the carry state and adjust the total accordingly.
3318*0Sstevel@tonic-gate 	 */
3319*0Sstevel@tonic-gate 	} else {
3320*0Sstevel@tonic-gate 		temp = temp - OHCI_MAX_CYCLE_CNT;
3321*0Sstevel@tonic-gate 		carry = 1;
3322*0Sstevel@tonic-gate 	}
3323*0Sstevel@tonic-gate 
3324*0Sstevel@tonic-gate 	/*
3325*0Sstevel@tonic-gate 	 * The timeout time equals the seconds added with the carry (1 or 0
3326*0Sstevel@tonic-gate 	 * seconds), added with the adjusted (if necessary) cycle count.
3327*0Sstevel@tonic-gate 	 * Mask the final value to get rid of any second rollovers.
3328*0Sstevel@tonic-gate 	 */
3329*0Sstevel@tonic-gate 	z = (current_time & OHCI_CYCLE_SEC_MASK) + (split_timeout &
3330*0Sstevel@tonic-gate 	    OHCI_CYCLE_SEC_MASK) + (carry << OHCI_CYCLE_SEC_SHIFT) + temp;
3331*0Sstevel@tonic-gate 	z = z & OHCI_TIMESTAMP_MASK;
3332*0Sstevel@tonic-gate 
3333*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_timeout_calc_exit,
3334*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3335*0Sstevel@tonic-gate 
3336*0Sstevel@tonic-gate 	return (z);
3337*0Sstevel@tonic-gate }
3338*0Sstevel@tonic-gate 
3339*0Sstevel@tonic-gate 
3340*0Sstevel@tonic-gate /*
3341*0Sstevel@tonic-gate  * hci1394_async_arresp_size_get()
3342*0Sstevel@tonic-gate  *    Return the size of the arresp that was received in q_handle at addr.
3343*0Sstevel@tonic-gate  */
3344*0Sstevel@tonic-gate static int
hci1394_async_arresp_size_get(uint_t tcode,hci1394_q_handle_t q_handle,uint32_t * addr,uint_t * size)3345*0Sstevel@tonic-gate hci1394_async_arresp_size_get(uint_t tcode, hci1394_q_handle_t q_handle,
3346*0Sstevel@tonic-gate     uint32_t *addr, uint_t *size)
3347*0Sstevel@tonic-gate {
3348*0Sstevel@tonic-gate 	uint_t data_length;
3349*0Sstevel@tonic-gate 	uint32_t quadlet;
3350*0Sstevel@tonic-gate 
3351*0Sstevel@tonic-gate 
3352*0Sstevel@tonic-gate 	ASSERT(q_handle != NULL);
3353*0Sstevel@tonic-gate 	ASSERT(addr != NULL);
3354*0Sstevel@tonic-gate 	ASSERT(size != NULL);
3355*0Sstevel@tonic-gate 
3356*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_get_arresp_size_enter,
3357*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3358*0Sstevel@tonic-gate 
3359*0Sstevel@tonic-gate 	if (tcode == IEEE1394_TCODE_WRITE_RESP) {
3360*0Sstevel@tonic-gate 		*size = DESC_PKT_HDRLEN_AT_WRITE_RESP + IEEE1394_QUADLET;
3361*0Sstevel@tonic-gate 	} else if (tcode == IEEE1394_TCODE_READ_QUADLET_RESP) {
3362*0Sstevel@tonic-gate 		*size = DESC_PKT_HDRLEN_AT_READQUAD_RESP + IEEE1394_QUADLET;
3363*0Sstevel@tonic-gate 	} else if (tcode == IEEE1394_TCODE_READ_BLOCK_RESP) {
3364*0Sstevel@tonic-gate 		quadlet = hci1394_q_ar_get32(q_handle, &addr[3]);
3365*0Sstevel@tonic-gate 		data_length = HCI1394_DESC_DATALEN_GET(quadlet);
3366*0Sstevel@tonic-gate 		/*
3367*0Sstevel@tonic-gate 		 * response size is in quadlets, therefore we need to
3368*0Sstevel@tonic-gate 		 * make sure we count in the padding when figuring out
3369*0Sstevel@tonic-gate 		 * the size used up for this response
3370*0Sstevel@tonic-gate 		 */
3371*0Sstevel@tonic-gate 		*size = DESC_PKT_HDRLEN_AT_READBLOCK_RESP +
3372*0Sstevel@tonic-gate 		    HCI1394_ALIGN_QUAD(data_length) + IEEE1394_QUADLET;
3373*0Sstevel@tonic-gate 	} else if (tcode == IEEE1394_TCODE_LOCK_RESP) {
3374*0Sstevel@tonic-gate 		quadlet = hci1394_q_ar_get32(q_handle, &addr[3]);
3375*0Sstevel@tonic-gate 		data_length = HCI1394_DESC_DATALEN_GET(quadlet);
3376*0Sstevel@tonic-gate 		/*
3377*0Sstevel@tonic-gate 		 * response size is in quadlets, therefore we need to
3378*0Sstevel@tonic-gate 		 * make sure we count in the padding when figuring out
3379*0Sstevel@tonic-gate 		 * the size used up for this response
3380*0Sstevel@tonic-gate 		 */
3381*0Sstevel@tonic-gate 		*size = DESC_PKT_HDRLEN_AT_LOCK_RESP +
3382*0Sstevel@tonic-gate 		    HCI1394_ALIGN_QUAD(data_length) + IEEE1394_QUADLET;
3383*0Sstevel@tonic-gate 	} else {
3384*0Sstevel@tonic-gate 		TNF_PROBE_1(hci1394_async_arresp_size_tcode_err,
3385*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_ERROR,
3386*0Sstevel@tonic-gate 		    "unknown ARRESP received", tnf_uint, arresp_tcode, tcode);
3387*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_get_arresp_size_exit,
3388*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
3389*0Sstevel@tonic-gate 		return (DDI_FAILURE);
3390*0Sstevel@tonic-gate 	}
3391*0Sstevel@tonic-gate 
3392*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_get_arresp_size_exit,
3393*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3394*0Sstevel@tonic-gate 
3395*0Sstevel@tonic-gate 	return (DDI_SUCCESS);
3396*0Sstevel@tonic-gate }
3397*0Sstevel@tonic-gate 
3398*0Sstevel@tonic-gate 
3399*0Sstevel@tonic-gate /*
3400*0Sstevel@tonic-gate  * hci1394_async_pending_list_flush()
3401*0Sstevel@tonic-gate  *    Flush out the ATREQ pending list. All commands still on the ATREQ pending
3402*0Sstevel@tonic-gate  *    list are considered to be completed due to a bus reset. The ATREQ and
3403*0Sstevel@tonic-gate  *    ARRESP Q's should be flushed before the pending Q is flushed. The ATREQ
3404*0Sstevel@tonic-gate  *    could have more ACK pendings and the ARRESP could have valid responses to
3405*0Sstevel@tonic-gate  *    pended requests.
3406*0Sstevel@tonic-gate  */
3407*0Sstevel@tonic-gate void
hci1394_async_pending_list_flush(hci1394_async_handle_t async_handle)3408*0Sstevel@tonic-gate hci1394_async_pending_list_flush(hci1394_async_handle_t async_handle)
3409*0Sstevel@tonic-gate {
3410*0Sstevel@tonic-gate 	hci1394_tlist_node_t *node;
3411*0Sstevel@tonic-gate 	hci1394_async_cmd_t *hcicmd;
3412*0Sstevel@tonic-gate 
3413*0Sstevel@tonic-gate 
3414*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3415*0Sstevel@tonic-gate 
3416*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_pending_list_flush_enter,
3417*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3418*0Sstevel@tonic-gate 
3419*0Sstevel@tonic-gate 	do {
3420*0Sstevel@tonic-gate 		/*
3421*0Sstevel@tonic-gate 		 * get the first node on the pending list. This routine also
3422*0Sstevel@tonic-gate 		 * removes the node from the list.
3423*0Sstevel@tonic-gate 		 */
3424*0Sstevel@tonic-gate 		hci1394_tlist_get(async_handle->as_pending_list, &node);
3425*0Sstevel@tonic-gate 		if (node != NULL) {
3426*0Sstevel@tonic-gate 			/* set the command state to completed */
3427*0Sstevel@tonic-gate 			hcicmd = (hci1394_async_cmd_t *)node->tln_addr;
3428*0Sstevel@tonic-gate 			hcicmd->ac_state = HCI1394_CMD_STATE_COMPLETED;
3429*0Sstevel@tonic-gate 
3430*0Sstevel@tonic-gate 			/*
3431*0Sstevel@tonic-gate 			 * Send the command up to the Services Layer with
3432*0Sstevel@tonic-gate 			 * completed due to the bus reset for status.
3433*0Sstevel@tonic-gate 			 */
3434*0Sstevel@tonic-gate 			h1394_cmd_is_complete(
3435*0Sstevel@tonic-gate 			    async_handle->as_drvinfo->di_sl_private,
3436*0Sstevel@tonic-gate 			    hcicmd->ac_cmd, H1394_AT_REQ,
3437*0Sstevel@tonic-gate 			    H1394_CMD_EBUSRESET);
3438*0Sstevel@tonic-gate 		}
3439*0Sstevel@tonic-gate 	} while (node != NULL);
3440*0Sstevel@tonic-gate 
3441*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_pending_list_flush_exit,
3442*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3443*0Sstevel@tonic-gate }
3444*0Sstevel@tonic-gate 
3445*0Sstevel@tonic-gate 
3446*0Sstevel@tonic-gate /*
3447*0Sstevel@tonic-gate  * hci1394_async_atreq_start()
3448*0Sstevel@tonic-gate  *    Setup the command pointer for the first descriptor to be fetched and
3449*0Sstevel@tonic-gate  *    then set the run bit. This routine will be called the first time
3450*0Sstevel@tonic-gate  *    a descriptor is added to the Q.
3451*0Sstevel@tonic-gate  */
3452*0Sstevel@tonic-gate static void
hci1394_async_atreq_start(void * async,uint32_t command_ptr)3453*0Sstevel@tonic-gate hci1394_async_atreq_start(void *async, uint32_t command_ptr)
3454*0Sstevel@tonic-gate {
3455*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3456*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3457*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_start_enter,
3458*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3459*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3460*0Sstevel@tonic-gate 	hci1394_ohci_atreq_start(async_handle->as_ohci, command_ptr);
3461*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_start_exit,
3462*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3463*0Sstevel@tonic-gate }
3464*0Sstevel@tonic-gate 
3465*0Sstevel@tonic-gate 
3466*0Sstevel@tonic-gate /*
3467*0Sstevel@tonic-gate  * hci1394_async_atreq_wake()
3468*0Sstevel@tonic-gate  *    Set the wake bit for the ATREQ DMA engine. This routine will be called
3469*0Sstevel@tonic-gate  *    from the Q logic after placing a descriptor on the Q.
3470*0Sstevel@tonic-gate  */
3471*0Sstevel@tonic-gate static void
hci1394_async_atreq_wake(void * async)3472*0Sstevel@tonic-gate hci1394_async_atreq_wake(void *async)
3473*0Sstevel@tonic-gate {
3474*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3475*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3476*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_wake_enter,
3477*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3478*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3479*0Sstevel@tonic-gate 	hci1394_ohci_atreq_wake(async_handle->as_ohci);
3480*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_wake_exit,
3481*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3482*0Sstevel@tonic-gate }
3483*0Sstevel@tonic-gate 
3484*0Sstevel@tonic-gate 
3485*0Sstevel@tonic-gate /*
3486*0Sstevel@tonic-gate  * hci1394_async_atreq_reset()
3487*0Sstevel@tonic-gate  *    Reset the atreq Q.  The AT DMA engines must be stopped every bus reset.
3488*0Sstevel@tonic-gate  *    They will restart when the next descriptor is added to the Q. We will stop
3489*0Sstevel@tonic-gate  *    the DMA engine and then notify the Q logic that it has been stopped so it
3490*0Sstevel@tonic-gate  *    knows to do a start next time it puts a descriptor on the Q.
3491*0Sstevel@tonic-gate  */
3492*0Sstevel@tonic-gate void
hci1394_async_atreq_reset(hci1394_async_handle_t async_handle)3493*0Sstevel@tonic-gate hci1394_async_atreq_reset(hci1394_async_handle_t async_handle)
3494*0Sstevel@tonic-gate {
3495*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3496*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_reset_enter,
3497*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3498*0Sstevel@tonic-gate 	hci1394_ohci_atreq_stop(async_handle->as_ohci);
3499*0Sstevel@tonic-gate 	hci1394_q_stop(async_handle->as_atreq_q);
3500*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_reset_exit,
3501*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3502*0Sstevel@tonic-gate }
3503*0Sstevel@tonic-gate 
3504*0Sstevel@tonic-gate 
3505*0Sstevel@tonic-gate /*
3506*0Sstevel@tonic-gate  * hci1394_async_atreq_flush()
3507*0Sstevel@tonic-gate  *    Flush out the atreq Q. This routine is called during bus reset processing.
3508*0Sstevel@tonic-gate  *    it should be called before arresp_flush() and pending_list_flush().
3509*0Sstevel@tonic-gate  */
3510*0Sstevel@tonic-gate static void
hci1394_async_atreq_flush(hci1394_async_handle_t async_handle)3511*0Sstevel@tonic-gate hci1394_async_atreq_flush(hci1394_async_handle_t async_handle)
3512*0Sstevel@tonic-gate {
3513*0Sstevel@tonic-gate 	boolean_t request_available;
3514*0Sstevel@tonic-gate 	int status;
3515*0Sstevel@tonic-gate 
3516*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3517*0Sstevel@tonic-gate 
3518*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_flush_enter,
3519*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3520*0Sstevel@tonic-gate 
3521*0Sstevel@tonic-gate 	/* Clear reqTxComplete interrupt */
3522*0Sstevel@tonic-gate 	hci1394_ohci_intr_clear(async_handle->as_ohci, OHCI_INTR_REQ_TX_CMPLT);
3523*0Sstevel@tonic-gate 
3524*0Sstevel@tonic-gate 	/*
3525*0Sstevel@tonic-gate 	 * Processes all Q'd AT requests.  If the request is pended, it is
3526*0Sstevel@tonic-gate 	 * considered complete relative the the atreq engine.
3527*0Sstevel@tonic-gate 	 * flush_pending_list() will finish up the required processing for
3528*0Sstevel@tonic-gate 	 * pended requests.
3529*0Sstevel@tonic-gate 	 */
3530*0Sstevel@tonic-gate 	do {
3531*0Sstevel@tonic-gate 		/* Flush the atreq Q. Process all Q'd commands */
3532*0Sstevel@tonic-gate 		status = hci1394_async_atreq_process(async_handle,
3533*0Sstevel@tonic-gate 		    B_TRUE, &request_available);
3534*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
3535*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_atreq_process_fail,
3536*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
3537*0Sstevel@tonic-gate 		}
3538*0Sstevel@tonic-gate 	} while (request_available == B_TRUE);
3539*0Sstevel@tonic-gate 
3540*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atreq_flush_exit,
3541*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3542*0Sstevel@tonic-gate }
3543*0Sstevel@tonic-gate 
3544*0Sstevel@tonic-gate 
3545*0Sstevel@tonic-gate /*
3546*0Sstevel@tonic-gate  * hci1394_async_arresp_start()
3547*0Sstevel@tonic-gate  *    Setup the command pointer for the first descriptor to be fetched and
3548*0Sstevel@tonic-gate  *    then set the run bit. This routine will be called the first time
3549*0Sstevel@tonic-gate  *    a descriptor is added to the Q.
3550*0Sstevel@tonic-gate  */
3551*0Sstevel@tonic-gate static void
hci1394_async_arresp_start(void * async,uint32_t command_ptr)3552*0Sstevel@tonic-gate hci1394_async_arresp_start(void *async, uint32_t command_ptr)
3553*0Sstevel@tonic-gate {
3554*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3555*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3556*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_start_enter,
3557*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3558*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3559*0Sstevel@tonic-gate 	hci1394_ohci_arresp_start(async_handle->as_ohci, command_ptr);
3560*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_start_exit,
3561*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3562*0Sstevel@tonic-gate }
3563*0Sstevel@tonic-gate 
3564*0Sstevel@tonic-gate 
3565*0Sstevel@tonic-gate /*
3566*0Sstevel@tonic-gate  * hci1394_async_arresp_wake()
3567*0Sstevel@tonic-gate  *    Set the wake bit for the ARRESP DMA engine. This routine will be called
3568*0Sstevel@tonic-gate  *    from the Q logic after placing a descriptor on the Q.
3569*0Sstevel@tonic-gate  */
3570*0Sstevel@tonic-gate static void
hci1394_async_arresp_wake(void * async)3571*0Sstevel@tonic-gate hci1394_async_arresp_wake(void *async)
3572*0Sstevel@tonic-gate {
3573*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3574*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3575*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_wake_enter,
3576*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3577*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3578*0Sstevel@tonic-gate 	hci1394_ohci_arresp_wake(async_handle->as_ohci);
3579*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_wake_exit,
3580*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3581*0Sstevel@tonic-gate }
3582*0Sstevel@tonic-gate 
3583*0Sstevel@tonic-gate 
3584*0Sstevel@tonic-gate /*
3585*0Sstevel@tonic-gate  * hci1394_async_arresp_flush()
3586*0Sstevel@tonic-gate  *    Flush out the arresp Q. This routine is called during bus reset
3587*0Sstevel@tonic-gate  *    processing. This should be called before pending_list_flush(). All
3588*0Sstevel@tonic-gate  *    receive responses will be processed normally. The tlabels should
3589*0Sstevel@tonic-gate  *    not be reset until after the ARRESP Q has been flushed. Otherwise
3590*0Sstevel@tonic-gate  *    we would reject valid responses.
3591*0Sstevel@tonic-gate  */
3592*0Sstevel@tonic-gate static void
hci1394_async_arresp_flush(hci1394_async_handle_t async_handle)3593*0Sstevel@tonic-gate hci1394_async_arresp_flush(hci1394_async_handle_t async_handle)
3594*0Sstevel@tonic-gate {
3595*0Sstevel@tonic-gate 	boolean_t response_available;
3596*0Sstevel@tonic-gate 	int status;
3597*0Sstevel@tonic-gate 
3598*0Sstevel@tonic-gate 
3599*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3600*0Sstevel@tonic-gate 
3601*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_flush_enter,
3602*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3603*0Sstevel@tonic-gate 
3604*0Sstevel@tonic-gate 	/* Clear reqTxComplete interrupt */
3605*0Sstevel@tonic-gate 	hci1394_ohci_intr_clear(async_handle->as_ohci, OHCI_INTR_RSPKT);
3606*0Sstevel@tonic-gate 
3607*0Sstevel@tonic-gate 	do {
3608*0Sstevel@tonic-gate 		/* Flush the arresp Q. Process all received commands */
3609*0Sstevel@tonic-gate 		status = hci1394_async_arresp_process(async_handle,
3610*0Sstevel@tonic-gate 		    &response_available);
3611*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
3612*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_arresp_process_fail,
3613*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
3614*0Sstevel@tonic-gate 		}
3615*0Sstevel@tonic-gate 	} while (response_available == B_TRUE);
3616*0Sstevel@tonic-gate 
3617*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arresp_flush_enter,
3618*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3619*0Sstevel@tonic-gate }
3620*0Sstevel@tonic-gate 
3621*0Sstevel@tonic-gate 
3622*0Sstevel@tonic-gate /*
3623*0Sstevel@tonic-gate  * hci1394_async_arreq_start()
3624*0Sstevel@tonic-gate  *    Setup the command pointer for the first descriptor to be fetched and
3625*0Sstevel@tonic-gate  *    then set the run bit. This routine will be called the first time
3626*0Sstevel@tonic-gate  *    a descriptor is added to the Q.
3627*0Sstevel@tonic-gate  */
3628*0Sstevel@tonic-gate static void
hci1394_async_arreq_start(void * async,uint32_t command_ptr)3629*0Sstevel@tonic-gate hci1394_async_arreq_start(void *async, uint32_t command_ptr)
3630*0Sstevel@tonic-gate {
3631*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3632*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3633*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_start_enter,
3634*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3635*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3636*0Sstevel@tonic-gate 	hci1394_ohci_arreq_start(async_handle->as_ohci, command_ptr);
3637*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_start_exit,
3638*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3639*0Sstevel@tonic-gate }
3640*0Sstevel@tonic-gate 
3641*0Sstevel@tonic-gate 
3642*0Sstevel@tonic-gate /*
3643*0Sstevel@tonic-gate  * hci1394_async_arreq_wake()
3644*0Sstevel@tonic-gate  *    Set the wake bit for the ARREQ DMA engine. This routine will be called
3645*0Sstevel@tonic-gate  *    from the Q logic after placing a descriptor on the Q.
3646*0Sstevel@tonic-gate  */
3647*0Sstevel@tonic-gate static void
hci1394_async_arreq_wake(void * async)3648*0Sstevel@tonic-gate hci1394_async_arreq_wake(void *async)
3649*0Sstevel@tonic-gate {
3650*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3651*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3652*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_wake_enter,
3653*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3654*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3655*0Sstevel@tonic-gate 	hci1394_ohci_arreq_wake(async_handle->as_ohci);
3656*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_wake_exit,
3657*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3658*0Sstevel@tonic-gate }
3659*0Sstevel@tonic-gate 
3660*0Sstevel@tonic-gate 
3661*0Sstevel@tonic-gate /*
3662*0Sstevel@tonic-gate  * hci1394_async_arreq_flush()
3663*0Sstevel@tonic-gate  *    Flush the ARREQ Q. This will flush up to the bus reset token in the
3664*0Sstevel@tonic-gate  *    ARREQ. There is no order dependency for when routine should get called
3665*0Sstevel@tonic-gate  *    (relative to the other Q flushing routines)
3666*0Sstevel@tonic-gate  */
3667*0Sstevel@tonic-gate static void
hci1394_async_arreq_flush(hci1394_async_handle_t async_handle)3668*0Sstevel@tonic-gate hci1394_async_arreq_flush(hci1394_async_handle_t async_handle)
3669*0Sstevel@tonic-gate {
3670*0Sstevel@tonic-gate 	boolean_t request_available;
3671*0Sstevel@tonic-gate 	int status;
3672*0Sstevel@tonic-gate 
3673*0Sstevel@tonic-gate 
3674*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3675*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_flush_enter,
3676*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3677*0Sstevel@tonic-gate 
3678*0Sstevel@tonic-gate 	/*
3679*0Sstevel@tonic-gate 	 * If the last bus reset token we have seen in
3680*0Sstevel@tonic-gate 	 * hci1394_async_arreq_read_phy() matches the current generation, the
3681*0Sstevel@tonic-gate 	 * ARREQ is already flushed.  We have nothing further to do here so
3682*0Sstevel@tonic-gate 	 * return. This can happen if we are processing ARREQ's and a bus reset
3683*0Sstevel@tonic-gate 	 * occurs. Since we are already in the ISR, we will see the token before
3684*0Sstevel@tonic-gate 	 * the bus reset handler gets to run.
3685*0Sstevel@tonic-gate 	 */
3686*0Sstevel@tonic-gate 	if (async_handle->as_phy_reset == hci1394_ohci_current_busgen(
3687*0Sstevel@tonic-gate 	    async_handle->as_ohci)) {
3688*0Sstevel@tonic-gate 		TNF_PROBE_0_DEBUG(hci1394_async_arreq_flush_exit,
3689*0Sstevel@tonic-gate 		    HCI1394_TNF_HAL_STACK, "");
3690*0Sstevel@tonic-gate 		return;
3691*0Sstevel@tonic-gate 	}
3692*0Sstevel@tonic-gate 
3693*0Sstevel@tonic-gate 	/*
3694*0Sstevel@tonic-gate 	 * set flag to tell hci1394_async_arreq_process() that we should not
3695*0Sstevel@tonic-gate 	 * pass ARREQ's up to the Services Layer.  This will be set to B_FALSE
3696*0Sstevel@tonic-gate 	 * in hci1394_async_arreq_read_phy() when a bus reset token matching
3697*0Sstevel@tonic-gate 	 * the current generation is found.
3698*0Sstevel@tonic-gate 	 */
3699*0Sstevel@tonic-gate 	async_handle->as_flushing_arreq = B_TRUE;
3700*0Sstevel@tonic-gate 
3701*0Sstevel@tonic-gate 	/*
3702*0Sstevel@tonic-gate 	 * Process all requests that have been received or until we find the
3703*0Sstevel@tonic-gate 	 * correct bus reset token.
3704*0Sstevel@tonic-gate 	 */
3705*0Sstevel@tonic-gate 	do {
3706*0Sstevel@tonic-gate 		status = hci1394_async_arreq_process(async_handle,
3707*0Sstevel@tonic-gate 		    &request_available);
3708*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
3709*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_isr_arreq_pr_fail,
3710*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
3711*0Sstevel@tonic-gate 		}
3712*0Sstevel@tonic-gate 	} while ((request_available == B_TRUE) &&
3713*0Sstevel@tonic-gate 	    (async_handle->as_flushing_arreq == B_TRUE));
3714*0Sstevel@tonic-gate 
3715*0Sstevel@tonic-gate 	/*
3716*0Sstevel@tonic-gate 	 * Clear the asserted interrupt if there are no more ARREQ's to process.
3717*0Sstevel@tonic-gate 	 * We could have ARREQ's in the Q after the bus reset token since we
3718*0Sstevel@tonic-gate 	 * will set as_flushing_arreq to FALSE when we see the correct bus reset
3719*0Sstevel@tonic-gate 	 * token in hci1394_async_arreq_read_phy(). If there are more ARREQ's,
3720*0Sstevel@tonic-gate 	 * we will process them later after finishing the reset of bus reset
3721*0Sstevel@tonic-gate 	 * processing.  That is why we will leave the interrupt asserted.
3722*0Sstevel@tonic-gate 	 */
3723*0Sstevel@tonic-gate 	if (request_available == B_FALSE) {
3724*0Sstevel@tonic-gate 		hci1394_ohci_intr_clear(async_handle->as_ohci, OHCI_INTR_RQPKT);
3725*0Sstevel@tonic-gate 	}
3726*0Sstevel@tonic-gate 
3727*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_arreq_flush_exit,
3728*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3729*0Sstevel@tonic-gate }
3730*0Sstevel@tonic-gate 
3731*0Sstevel@tonic-gate 
3732*0Sstevel@tonic-gate /*
3733*0Sstevel@tonic-gate  * hci1394_async_atresp_start()
3734*0Sstevel@tonic-gate  *    Setup the command pointer for the first descriptor to be fetched and
3735*0Sstevel@tonic-gate  *    then set the run bit. This routine will be called the first time
3736*0Sstevel@tonic-gate  *    a descriptor is added to the Q.
3737*0Sstevel@tonic-gate  */
3738*0Sstevel@tonic-gate static void
hci1394_async_atresp_start(void * async,uint32_t command_ptr)3739*0Sstevel@tonic-gate hci1394_async_atresp_start(void *async, uint32_t command_ptr)
3740*0Sstevel@tonic-gate {
3741*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3742*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3743*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_start_enter,
3744*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3745*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3746*0Sstevel@tonic-gate 	hci1394_ohci_atresp_start(async_handle->as_ohci, command_ptr);
3747*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_start_exit,
3748*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3749*0Sstevel@tonic-gate }
3750*0Sstevel@tonic-gate 
3751*0Sstevel@tonic-gate 
3752*0Sstevel@tonic-gate /*
3753*0Sstevel@tonic-gate  * hci1394_async_atresp_wake()
3754*0Sstevel@tonic-gate  *    Set the wake bit for the ATRESP DMA engine. This routine will be called
3755*0Sstevel@tonic-gate  *    from the Q logic after placing a descriptor on the Q.
3756*0Sstevel@tonic-gate  */
3757*0Sstevel@tonic-gate static void
hci1394_async_atresp_wake(void * async)3758*0Sstevel@tonic-gate hci1394_async_atresp_wake(void *async)
3759*0Sstevel@tonic-gate {
3760*0Sstevel@tonic-gate 	hci1394_async_handle_t async_handle;
3761*0Sstevel@tonic-gate 	ASSERT(async != NULL);
3762*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_wake_enter,
3763*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3764*0Sstevel@tonic-gate 	async_handle = (hci1394_async_handle_t)async;
3765*0Sstevel@tonic-gate 	hci1394_ohci_atresp_wake(async_handle->as_ohci);
3766*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_wake_exit,
3767*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3768*0Sstevel@tonic-gate }
3769*0Sstevel@tonic-gate 
3770*0Sstevel@tonic-gate 
3771*0Sstevel@tonic-gate /*
3772*0Sstevel@tonic-gate  * hci1394_async_atresp_reset()
3773*0Sstevel@tonic-gate  *    Reset the atresp Q.  The AT DMA engines must be stopped every bus reset.
3774*0Sstevel@tonic-gate  *    They will restart when the next descriptor is added to the Q. We will stop
3775*0Sstevel@tonic-gate  *    the DMA engine and then notify the Q logic that it has been stopped so it
3776*0Sstevel@tonic-gate  *    knows to do a start next time it puts a descriptor on the Q.
3777*0Sstevel@tonic-gate  */
3778*0Sstevel@tonic-gate void
hci1394_async_atresp_reset(hci1394_async_handle_t async_handle)3779*0Sstevel@tonic-gate hci1394_async_atresp_reset(hci1394_async_handle_t async_handle)
3780*0Sstevel@tonic-gate {
3781*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3782*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_reset_enter,
3783*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3784*0Sstevel@tonic-gate 	hci1394_ohci_atresp_stop(async_handle->as_ohci);
3785*0Sstevel@tonic-gate 	hci1394_q_stop(async_handle->as_atresp_q);
3786*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_reset_exit,
3787*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3788*0Sstevel@tonic-gate }
3789*0Sstevel@tonic-gate 
3790*0Sstevel@tonic-gate 
3791*0Sstevel@tonic-gate /*
3792*0Sstevel@tonic-gate  * hci1394_async_atresp_flush()
3793*0Sstevel@tonic-gate  *    Flush all commands out of the atresp Q. This routine will be called
3794*0Sstevel@tonic-gate  *    during bus reset processing. There is no order dependency for when
3795*0Sstevel@tonic-gate  *    routine should get called (relative to the other Q flushing routines)
3796*0Sstevel@tonic-gate  */
3797*0Sstevel@tonic-gate static void
hci1394_async_atresp_flush(hci1394_async_handle_t async_handle)3798*0Sstevel@tonic-gate hci1394_async_atresp_flush(hci1394_async_handle_t async_handle)
3799*0Sstevel@tonic-gate {
3800*0Sstevel@tonic-gate 	boolean_t response_available;
3801*0Sstevel@tonic-gate 	int status;
3802*0Sstevel@tonic-gate 
3803*0Sstevel@tonic-gate 	ASSERT(async_handle != NULL);
3804*0Sstevel@tonic-gate 
3805*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_flush_enter,
3806*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3807*0Sstevel@tonic-gate 
3808*0Sstevel@tonic-gate 	/* Clear respTxComplete interrupt */
3809*0Sstevel@tonic-gate 	hci1394_ohci_intr_clear(async_handle->as_ohci, OHCI_INTR_RESP_TX_CMPLT);
3810*0Sstevel@tonic-gate 
3811*0Sstevel@tonic-gate 	/* Processes all AT responses */
3812*0Sstevel@tonic-gate 	do {
3813*0Sstevel@tonic-gate 		/* Flush the atresp Q. Process all Q'd commands */
3814*0Sstevel@tonic-gate 		status = hci1394_async_atresp_process(async_handle,
3815*0Sstevel@tonic-gate 		    B_TRUE, &response_available);
3816*0Sstevel@tonic-gate 		if (status != DDI_SUCCESS) {
3817*0Sstevel@tonic-gate 			TNF_PROBE_0(hci1394_async_atresp_process_fail,
3818*0Sstevel@tonic-gate 			    HCI1394_TNF_HAL_ERROR, "");
3819*0Sstevel@tonic-gate 		}
3820*0Sstevel@tonic-gate 	} while (response_available == B_TRUE);
3821*0Sstevel@tonic-gate 
3822*0Sstevel@tonic-gate 	TNF_PROBE_0_DEBUG(hci1394_async_atresp_flush_exit,
3823*0Sstevel@tonic-gate 	    HCI1394_TNF_HAL_STACK, "");
3824*0Sstevel@tonic-gate }
3825*0Sstevel@tonic-gate 
3826*0Sstevel@tonic-gate /*
3827*0Sstevel@tonic-gate  * hci1394_async_hcicmd_init()
3828*0Sstevel@tonic-gate  *    Initialize the private HAL command structure. This should be called from
3829*0Sstevel@tonic-gate  *    ATREQ and ARREQ routines.
3830*0Sstevel@tonic-gate  */
3831*0Sstevel@tonic-gate static void
hci1394_async_hcicmd_init(hci1394_async_handle_t async_handle,cmd1394_cmd_t * cmd,h1394_cmd_priv_t * cmd_priv,hci1394_async_cmd_t ** hcicmd)3832*0Sstevel@tonic-gate hci1394_async_hcicmd_init(hci1394_async_handle_t async_handle,
3833*0Sstevel@tonic-gate     cmd1394_cmd_t *cmd, h1394_cmd_priv_t *cmd_priv,
3834*0Sstevel@tonic-gate     hci1394_async_cmd_t **hcicmd)
3835*0Sstevel@tonic-gate {
3836*0Sstevel@tonic-gate 	*hcicmd = (hci1394_async_cmd_t *)cmd_priv->hal_overhead;
3837*0Sstevel@tonic-gate 	(*hcicmd)->ac_cmd = cmd;
3838*0Sstevel@tonic-gate 	(*hcicmd)->ac_priv = cmd_priv;
3839*0Sstevel@tonic-gate 	(*hcicmd)->ac_async = async_handle;
3840*0Sstevel@tonic-gate 	(*hcicmd)->ac_state = HCI1394_CMD_STATE_IN_PROGRESS;
3841*0Sstevel@tonic-gate 	(*hcicmd)->ac_dest = 0;
3842*0Sstevel@tonic-gate 	(*hcicmd)->ac_tlabel_alloc = B_TRUE;
3843*0Sstevel@tonic-gate 	(*hcicmd)->ac_tlabel.tbi_tlabel = 0;
3844*0Sstevel@tonic-gate 	(*hcicmd)->ac_tlabel.tbi_destination = 0;
3845*0Sstevel@tonic-gate 	(*hcicmd)->ac_status = 0;
3846*0Sstevel@tonic-gate 	(*hcicmd)->ac_qcmd.qc_timestamp = 0;
3847*0Sstevel@tonic-gate 	(*hcicmd)->ac_qcmd.qc_arg = *hcicmd;
3848*0Sstevel@tonic-gate 	(*hcicmd)->ac_qcmd.qc_generation = cmd_priv->bus_generation;
3849*0Sstevel@tonic-gate 	(*hcicmd)->ac_mblk_alloc = B_FALSE;
3850*0Sstevel@tonic-gate }
3851