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 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate * h1394.c
31*0Sstevel@tonic-gate * 1394 Services Layer HAL Interface
32*0Sstevel@tonic-gate * Contains all of the routines that define the HAL to Services Layer
33*0Sstevel@tonic-gate * interface
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/sunddi.h>
39*0Sstevel@tonic-gate #include <sys/modctl.h>
40*0Sstevel@tonic-gate #include <sys/sunndi.h>
41*0Sstevel@tonic-gate #include <sys/cmn_err.h>
42*0Sstevel@tonic-gate #include <sys/types.h>
43*0Sstevel@tonic-gate #include <sys/kmem.h>
44*0Sstevel@tonic-gate #include <sys/thread.h>
45*0Sstevel@tonic-gate #include <sys/proc.h>
46*0Sstevel@tonic-gate #include <sys/disp.h>
47*0Sstevel@tonic-gate #include <sys/time.h>
48*0Sstevel@tonic-gate #include <sys/devctl.h>
49*0Sstevel@tonic-gate #include <sys/tnf_probe.h>
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate #include <sys/1394/t1394.h>
52*0Sstevel@tonic-gate #include <sys/1394/s1394.h>
53*0Sstevel@tonic-gate #include <sys/1394/h1394.h>
54*0Sstevel@tonic-gate #include <sys/1394/ieee1394.h>
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate extern struct bus_ops nx1394_busops;
58*0Sstevel@tonic-gate extern int nx1394_define_events(s1394_hal_t *hal);
59*0Sstevel@tonic-gate extern void nx1394_undefine_events(s1394_hal_t *hal);
60*0Sstevel@tonic-gate extern int s1394_ignore_invalid_gap_cnt;
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate * Function: h1394_init()
64*0Sstevel@tonic-gate * Input(s): modlp The structure containing all of the
65*0Sstevel@tonic-gate * HAL's relevant information
66*0Sstevel@tonic-gate *
67*0Sstevel@tonic-gate * Output(s):
68*0Sstevel@tonic-gate *
69*0Sstevel@tonic-gate * Description: h1394_init() is called by the HAL's _init function and is
70*0Sstevel@tonic-gate * used to set up the nexus bus ops.
71*0Sstevel@tonic-gate */
72*0Sstevel@tonic-gate int
h1394_init(struct modlinkage * modlp)73*0Sstevel@tonic-gate h1394_init(struct modlinkage *modlp)
74*0Sstevel@tonic-gate {
75*0Sstevel@tonic-gate struct dev_ops *devops;
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_init_enter, S1394_TNF_SL_STACK, "");
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate devops = ((struct modldrv *)(modlp->ml_linkage[0]))->drv_dev_ops;
80*0Sstevel@tonic-gate devops->devo_bus_ops = &nx1394_busops;
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_init_exit, S1394_TNF_SL_STACK, "");
83*0Sstevel@tonic-gate return (0);
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate * Function: h1394_fini()
88*0Sstevel@tonic-gate * Input(s): modlp The structure containing all of the
89*0Sstevel@tonic-gate * HAL's relevant information
90*0Sstevel@tonic-gate *
91*0Sstevel@tonic-gate * Output(s):
92*0Sstevel@tonic-gate *
93*0Sstevel@tonic-gate * Description: h1394_fini() is called by the HAL's _fini function and is
94*0Sstevel@tonic-gate * used to NULL out the nexus bus ops.
95*0Sstevel@tonic-gate */
96*0Sstevel@tonic-gate void
h1394_fini(struct modlinkage * modlp)97*0Sstevel@tonic-gate h1394_fini(struct modlinkage *modlp)
98*0Sstevel@tonic-gate {
99*0Sstevel@tonic-gate struct dev_ops *devops;
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_fini_enter, S1394_TNF_SL_STACK, "");
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate devops = ((struct modldrv *)(modlp->ml_linkage[0]))->drv_dev_ops;
104*0Sstevel@tonic-gate devops->devo_bus_ops = NULL;
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_fini_enter, S1394_TNF_SL_STACK, "");
107*0Sstevel@tonic-gate }
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate /*
110*0Sstevel@tonic-gate * Function: h1394_attach()
111*0Sstevel@tonic-gate * Input(s): halinfo The structure containing all of the
112*0Sstevel@tonic-gate * HAL's relevant information
113*0Sstevel@tonic-gate * cmd The ddi_attach_cmd_t that tells us
114*0Sstevel@tonic-gate * if this is a RESUME or a regular
115*0Sstevel@tonic-gate * attach() call
116*0Sstevel@tonic-gate *
117*0Sstevel@tonic-gate * Output(s): sl_private The HAL "handle" to be used for
118*0Sstevel@tonic-gate * all subsequent calls into the
119*0Sstevel@tonic-gate * 1394 Software Framework
120*0Sstevel@tonic-gate *
121*0Sstevel@tonic-gate * Description: h1394_attach() registers the HAL with the 1394 Software
122*0Sstevel@tonic-gate * Framework. It returns a HAL "handle" to be used for
123*0Sstevel@tonic-gate * all subsequent calls into the 1394 Software Framework.
124*0Sstevel@tonic-gate */
125*0Sstevel@tonic-gate int
h1394_attach(h1394_halinfo_t * halinfo,ddi_attach_cmd_t cmd,void ** sl_private)126*0Sstevel@tonic-gate h1394_attach(h1394_halinfo_t *halinfo, ddi_attach_cmd_t cmd, void **sl_private)
127*0Sstevel@tonic-gate {
128*0Sstevel@tonic-gate s1394_hal_t *hal;
129*0Sstevel@tonic-gate int ret;
130*0Sstevel@tonic-gate char buf[32];
131*0Sstevel@tonic-gate uint_t cmd_size;
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_enter, S1394_TNF_SL_STACK, "");
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate ASSERT(sl_private != NULL);
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate /* If this is a DDI_RESUME, return success */
138*0Sstevel@tonic-gate if (cmd == DDI_RESUME) {
139*0Sstevel@tonic-gate hal = (s1394_hal_t *)(*sl_private);
140*0Sstevel@tonic-gate /* If we have a 1394A PHY, then reset the "contender bit" */
141*0Sstevel@tonic-gate if (hal->halinfo.phy == H1394_PHY_1394A)
142*0Sstevel@tonic-gate (void) HAL_CALL(hal).set_contender_bit(
143*0Sstevel@tonic-gate hal->halinfo.hal_private);
144*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK,
145*0Sstevel@tonic-gate "");
146*0Sstevel@tonic-gate return (DDI_SUCCESS);
147*0Sstevel@tonic-gate } else if (cmd != DDI_ATTACH) {
148*0Sstevel@tonic-gate TNF_PROBE_2(h1394_attach_error, S1394_TNF_SL_ERROR, "",
149*0Sstevel@tonic-gate tnf_string, msg, "Invalid ddi_attach_cmd received",
150*0Sstevel@tonic-gate tnf_uint, attach_cmd, (uint_t)cmd);
151*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK,
152*0Sstevel@tonic-gate "");
153*0Sstevel@tonic-gate return (DDI_FAILURE);
154*0Sstevel@tonic-gate }
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate /* Allocate space for s1394_hal_t */
157*0Sstevel@tonic-gate hal = kmem_zalloc(sizeof (s1394_hal_t), KM_SLEEP);
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate /* Setup HAL state */
160*0Sstevel@tonic-gate hal->hal_state = S1394_HAL_INIT;
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate /* Copy in the halinfo struct */
163*0Sstevel@tonic-gate hal->halinfo = *halinfo;
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate /* Create the topology tree mutex */
166*0Sstevel@tonic-gate mutex_init(&hal->topology_tree_mutex, NULL, MUTEX_DRIVER,
167*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate /* Create the Cycle Mater timer mutex */
170*0Sstevel@tonic-gate mutex_init(&hal->cm_timer_mutex, NULL, MUTEX_DRIVER,
171*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gate /* Initialize the Isoch CEC list */
174*0Sstevel@tonic-gate hal->isoch_cec_list_head = NULL;
175*0Sstevel@tonic-gate hal->isoch_cec_list_tail = NULL;
176*0Sstevel@tonic-gate mutex_init(&hal->isoch_cec_list_mutex, NULL, MUTEX_DRIVER,
177*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate /* Initialize the Bus Manager node ID mutex and cv */
180*0Sstevel@tonic-gate mutex_init(&hal->bus_mgr_node_mutex, NULL, MUTEX_DRIVER,
181*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
182*0Sstevel@tonic-gate cv_init(&hal->bus_mgr_node_cv, NULL, CV_DRIVER,
183*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate /* Initialize the Bus Manager node ID - "-1" means undetermined */
186*0Sstevel@tonic-gate hal->bus_mgr_node = -1;
187*0Sstevel@tonic-gate hal->incumbent_bus_mgr = B_FALSE;
188*0Sstevel@tonic-gate
189*0Sstevel@tonic-gate /* Initialize the Target list */
190*0Sstevel@tonic-gate hal->target_head = NULL;
191*0Sstevel@tonic-gate hal->target_tail = NULL;
192*0Sstevel@tonic-gate rw_init(&hal->target_list_rwlock, NULL, RW_DRIVER,
193*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
194*0Sstevel@tonic-gate
195*0Sstevel@tonic-gate /* Setup Request Q's */
196*0Sstevel@tonic-gate hal->outstanding_q_head = NULL;
197*0Sstevel@tonic-gate hal->outstanding_q_tail = NULL;
198*0Sstevel@tonic-gate mutex_init(&hal->outstanding_q_mutex, NULL, MUTEX_DRIVER,
199*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
200*0Sstevel@tonic-gate hal->pending_q_head = NULL;
201*0Sstevel@tonic-gate hal->pending_q_tail = NULL;
202*0Sstevel@tonic-gate mutex_init(&hal->pending_q_mutex, NULL, MUTEX_DRIVER,
203*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate /* Create the kmem_cache for command allocations */
206*0Sstevel@tonic-gate (void) sprintf(buf, "hal%d_cache", ddi_get_instance(hal->halinfo.dip));
207*0Sstevel@tonic-gate cmd_size = sizeof (cmd1394_cmd_t) + sizeof (s1394_cmd_priv_t) +
208*0Sstevel@tonic-gate hal->halinfo.hal_overhead;
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gate hal->hal_kmem_cachep = kmem_cache_create(buf, cmd_size, 8, NULL, NULL,
211*0Sstevel@tonic-gate NULL, NULL, NULL, 0);
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate /* Setup the event stuff */
214*0Sstevel@tonic-gate ret = nx1394_define_events(hal);
215*0Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
216*0Sstevel@tonic-gate /* Clean up before leaving */
217*0Sstevel@tonic-gate s1394_cleanup_for_detach(hal, H1394_CLEANUP_LEVEL0);
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate TNF_PROBE_1(h1394_attach_error, S1394_TNF_SL_ERROR, "",
220*0Sstevel@tonic-gate tnf_string, msg, "Unable to define attach events");
221*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK,
222*0Sstevel@tonic-gate "");
223*0Sstevel@tonic-gate return (DDI_FAILURE);
224*0Sstevel@tonic-gate }
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate /* Initialize the mutexes and cv's used by the bus reset thread */
227*0Sstevel@tonic-gate mutex_init(&hal->br_thread_mutex, NULL, MUTEX_DRIVER,
228*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
229*0Sstevel@tonic-gate cv_init(&hal->br_thread_cv, NULL, CV_DRIVER, hal->halinfo.hw_interrupt);
230*0Sstevel@tonic-gate mutex_init(&hal->br_cmplq_mutex, NULL, MUTEX_DRIVER,
231*0Sstevel@tonic-gate hal->halinfo.hw_interrupt);
232*0Sstevel@tonic-gate cv_init(&hal->br_cmplq_cv, NULL, CV_DRIVER, hal->halinfo.hw_interrupt);
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gate /*
235*0Sstevel@tonic-gate * Create a bus reset thread to handle the device discovery.
236*0Sstevel@tonic-gate * It should take the default stack sizes, it should run
237*0Sstevel@tonic-gate * the s1394_br_thread() routine at the start, passing the
238*0Sstevel@tonic-gate * HAL pointer as its argument. The thread should be put
239*0Sstevel@tonic-gate * on processor p0, its state should be set to runnable,
240*0Sstevel@tonic-gate * but not yet on a processor, and its scheduling priority
241*0Sstevel@tonic-gate * should be the minimum level of any system class.
242*0Sstevel@tonic-gate */
243*0Sstevel@tonic-gate hal->br_thread = thread_create((caddr_t)NULL, 0, s1394_br_thread,
244*0Sstevel@tonic-gate hal, 0, &p0, TS_RUN, minclsyspri);
245*0Sstevel@tonic-gate
246*0Sstevel@tonic-gate /* Until we see a bus reset this HAL has no nodes */
247*0Sstevel@tonic-gate hal->number_of_nodes = 0;
248*0Sstevel@tonic-gate hal->num_bus_reset_till_fail = NUM_BR_FAIL;
249*0Sstevel@tonic-gate
250*0Sstevel@tonic-gate /* Initialize the SelfID Info */
251*0Sstevel@tonic-gate hal->current_buffer = 0;
252*0Sstevel@tonic-gate hal->selfid_buf0 = kmem_zalloc(S1394_SELFID_BUF_SIZE, KM_SLEEP);
253*0Sstevel@tonic-gate hal->selfid_buf1 = kmem_zalloc(S1394_SELFID_BUF_SIZE, KM_SLEEP);
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate /* Initialize kstat structures */
256*0Sstevel@tonic-gate ret = s1394_kstat_init(hal);
257*0Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
258*0Sstevel@tonic-gate /* Clean up before leaving */
259*0Sstevel@tonic-gate s1394_cleanup_for_detach(hal, H1394_CLEANUP_LEVEL3);
260*0Sstevel@tonic-gate
261*0Sstevel@tonic-gate TNF_PROBE_1(h1394_attach_error, S1394_TNF_SL_ERROR, "",
262*0Sstevel@tonic-gate tnf_string, msg, "Failure in s1394_kstat_init");
263*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK,
264*0Sstevel@tonic-gate "");
265*0Sstevel@tonic-gate return (DDI_FAILURE);
266*0Sstevel@tonic-gate }
267*0Sstevel@tonic-gate hal->hal_kstats->guid = hal->halinfo.guid;
268*0Sstevel@tonic-gate
269*0Sstevel@tonic-gate /* Setup the node tree pointers */
270*0Sstevel@tonic-gate hal->old_tree = &hal->last_valid_tree[0];
271*0Sstevel@tonic-gate hal->topology_tree = &hal->current_tree[0];
272*0Sstevel@tonic-gate
273*0Sstevel@tonic-gate /* Initialize the local Config ROM entry */
274*0Sstevel@tonic-gate ret = s1394_init_local_config_rom(hal);
275*0Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
276*0Sstevel@tonic-gate /* Clean up before leaving */
277*0Sstevel@tonic-gate s1394_cleanup_for_detach(hal, H1394_CLEANUP_LEVEL4);
278*0Sstevel@tonic-gate
279*0Sstevel@tonic-gate TNF_PROBE_1(h1394_attach_error, S1394_TNF_SL_ERROR, "",
280*0Sstevel@tonic-gate tnf_string, msg, "Failure in s1394_init_local_config_rom");
281*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK, "");
282*0Sstevel@tonic-gate return (DDI_FAILURE);
283*0Sstevel@tonic-gate }
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate /* Initialize 1394 Address Space */
286*0Sstevel@tonic-gate ret = s1394_init_addr_space(hal);
287*0Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
288*0Sstevel@tonic-gate /* Clean up before leaving */
289*0Sstevel@tonic-gate s1394_cleanup_for_detach(hal, H1394_CLEANUP_LEVEL5);
290*0Sstevel@tonic-gate
291*0Sstevel@tonic-gate TNF_PROBE_1(h1394_attach_error, S1394_TNF_SL_ERROR, "",
292*0Sstevel@tonic-gate tnf_string, msg, "Invalid 1394 address space");
293*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK,
294*0Sstevel@tonic-gate "");
295*0Sstevel@tonic-gate return (DDI_FAILURE);
296*0Sstevel@tonic-gate }
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate /* Initialize FCP subsystem */
299*0Sstevel@tonic-gate ret = s1394_fcp_hal_init(hal);
300*0Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
301*0Sstevel@tonic-gate /* Clean up before leaving */
302*0Sstevel@tonic-gate s1394_cleanup_for_detach(hal, H1394_CLEANUP_LEVEL6);
303*0Sstevel@tonic-gate
304*0Sstevel@tonic-gate TNF_PROBE_1(h1394_attach_error, S1394_TNF_SL_ERROR, "",
305*0Sstevel@tonic-gate tnf_string, msg, "FCP initialization failure");
306*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK,
307*0Sstevel@tonic-gate "");
308*0Sstevel@tonic-gate return (DDI_FAILURE);
309*0Sstevel@tonic-gate }
310*0Sstevel@tonic-gate
311*0Sstevel@tonic-gate /* Initialize the IRM node ID - "-1" means invalid, undetermined */
312*0Sstevel@tonic-gate hal->IRM_node = -1;
313*0Sstevel@tonic-gate
314*0Sstevel@tonic-gate /* If we have a 1394A PHY, then set the "contender bit" */
315*0Sstevel@tonic-gate if (hal->halinfo.phy == H1394_PHY_1394A)
316*0Sstevel@tonic-gate (void) HAL_CALL(hal).set_contender_bit(
317*0Sstevel@tonic-gate hal->halinfo.hal_private);
318*0Sstevel@tonic-gate
319*0Sstevel@tonic-gate /* Add into linked list */
320*0Sstevel@tonic-gate mutex_enter(&s1394_statep->hal_list_mutex);
321*0Sstevel@tonic-gate if ((s1394_statep->hal_head == NULL) &&
322*0Sstevel@tonic-gate (s1394_statep->hal_tail == NULL)) {
323*0Sstevel@tonic-gate s1394_statep->hal_head = hal;
324*0Sstevel@tonic-gate s1394_statep->hal_tail = hal;
325*0Sstevel@tonic-gate } else {
326*0Sstevel@tonic-gate s1394_statep->hal_tail->hal_next = hal;
327*0Sstevel@tonic-gate hal->hal_prev = s1394_statep->hal_tail;
328*0Sstevel@tonic-gate s1394_statep->hal_tail = hal;
329*0Sstevel@tonic-gate }
330*0Sstevel@tonic-gate mutex_exit(&s1394_statep->hal_list_mutex);
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gate /* Fill in services layer private info */
333*0Sstevel@tonic-gate *sl_private = (void *)hal;
334*0Sstevel@tonic-gate
335*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_attach_exit, S1394_TNF_SL_STACK, "");
336*0Sstevel@tonic-gate return (DDI_SUCCESS);
337*0Sstevel@tonic-gate }
338*0Sstevel@tonic-gate
339*0Sstevel@tonic-gate /*
340*0Sstevel@tonic-gate * Function: h1394_detach()
341*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
342*0Sstevel@tonic-gate * h1394_attach()
343*0Sstevel@tonic-gate * cmd The ddi_detach_cmd_t that tells us
344*0Sstevel@tonic-gate * if this is a SUSPEND or a regular
345*0Sstevel@tonic-gate * detach() call
346*0Sstevel@tonic-gate *
347*0Sstevel@tonic-gate * Output(s): DDI_SUCCESS HAL successfully detached
348*0Sstevel@tonic-gate * DDI_FAILURE HAL failed to detach
349*0Sstevel@tonic-gate *
350*0Sstevel@tonic-gate * Description: h1394_detach() unregisters the HAL from the 1394 Software
351*0Sstevel@tonic-gate * Framework. It can be called during a SUSPEND operation or
352*0Sstevel@tonic-gate * for a real detach() event.
353*0Sstevel@tonic-gate */
354*0Sstevel@tonic-gate int
h1394_detach(void ** sl_private,ddi_detach_cmd_t cmd)355*0Sstevel@tonic-gate h1394_detach(void **sl_private, ddi_detach_cmd_t cmd)
356*0Sstevel@tonic-gate {
357*0Sstevel@tonic-gate s1394_hal_t *hal;
358*0Sstevel@tonic-gate
359*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_detach_enter, S1394_TNF_SL_STACK, "");
360*0Sstevel@tonic-gate
361*0Sstevel@tonic-gate hal = (s1394_hal_t *)(*sl_private);
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate switch (cmd) {
364*0Sstevel@tonic-gate case DDI_DETACH:
365*0Sstevel@tonic-gate /* Clean up before leaving */
366*0Sstevel@tonic-gate s1394_cleanup_for_detach(hal, H1394_CLEANUP_LEVEL7);
367*0Sstevel@tonic-gate /* NULL out the HAL "handle" */
368*0Sstevel@tonic-gate *sl_private = NULL;
369*0Sstevel@tonic-gate break;
370*0Sstevel@tonic-gate
371*0Sstevel@tonic-gate case DDI_SUSPEND:
372*0Sstevel@tonic-gate /* Turn off any timers that might be set */
373*0Sstevel@tonic-gate s1394_destroy_timers(hal);
374*0Sstevel@tonic-gate /* Set the hal_was_suspended bit */
375*0Sstevel@tonic-gate hal->hal_was_suspended = B_TRUE;
376*0Sstevel@tonic-gate break;
377*0Sstevel@tonic-gate
378*0Sstevel@tonic-gate default:
379*0Sstevel@tonic-gate TNF_PROBE_2(h1394_attach_error, S1394_TNF_SL_ERROR, "",
380*0Sstevel@tonic-gate tnf_string, msg, "Invalid ddi_detach_cmd_t type specified",
381*0Sstevel@tonic-gate tnf_uint, detach_cmd, (uint_t)cmd);
382*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_detach_exit, S1394_TNF_SL_STACK, "");
383*0Sstevel@tonic-gate return (DDI_FAILURE);
384*0Sstevel@tonic-gate }
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_detach_exit, S1394_TNF_SL_STACK, "");
387*0Sstevel@tonic-gate return (DDI_SUCCESS);
388*0Sstevel@tonic-gate }
389*0Sstevel@tonic-gate
390*0Sstevel@tonic-gate /*
391*0Sstevel@tonic-gate * Function: h1394_alloc_cmd()
392*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
393*0Sstevel@tonic-gate * h1394_attach()
394*0Sstevel@tonic-gate * flags The flags parameter is described below
395*0Sstevel@tonic-gate *
396*0Sstevel@tonic-gate * Output(s): cmdp Pointer to the newly allocated command
397*0Sstevel@tonic-gate * hal_priv_ptr Offset into the command, points to
398*0Sstevel@tonic-gate * the HAL's private area
399*0Sstevel@tonic-gate *
400*0Sstevel@tonic-gate * Description: h1394_alloc_cmd() allocates a command for use with the
401*0Sstevel@tonic-gate * h1394_read_request(), h1394_write_request(), or
402*0Sstevel@tonic-gate * h1394_lock_request() interfaces of the 1394 Software Framework.
403*0Sstevel@tonic-gate * By default, h1394_alloc_cmd() may sleep while allocating
404*0Sstevel@tonic-gate * memory for the command structure. If this is undesirable,
405*0Sstevel@tonic-gate * the HAL may set the H1394_ALLOC_CMD_NOSLEEP bit in the flags
406*0Sstevel@tonic-gate * parameter.
407*0Sstevel@tonic-gate */
408*0Sstevel@tonic-gate int
h1394_alloc_cmd(void * sl_private,uint_t flags,cmd1394_cmd_t ** cmdp,h1394_cmd_priv_t ** hal_priv_ptr)409*0Sstevel@tonic-gate h1394_alloc_cmd(void *sl_private, uint_t flags, cmd1394_cmd_t **cmdp,
410*0Sstevel@tonic-gate h1394_cmd_priv_t **hal_priv_ptr)
411*0Sstevel@tonic-gate {
412*0Sstevel@tonic-gate s1394_hal_t *hal;
413*0Sstevel@tonic-gate s1394_cmd_priv_t *s_priv;
414*0Sstevel@tonic-gate
415*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_alloc_cmd_enter, S1394_TNF_SL_ARREQ_STACK,
416*0Sstevel@tonic-gate "");
417*0Sstevel@tonic-gate
418*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
419*0Sstevel@tonic-gate
420*0Sstevel@tonic-gate if (s1394_alloc_cmd(hal, flags, cmdp) != DDI_SUCCESS) {
421*0Sstevel@tonic-gate TNF_PROBE_1(h1394_alloc_cmd_error, S1394_TNF_SL_ARREQ_ERROR, "",
422*0Sstevel@tonic-gate tnf_string, msg, "Failed to allocate command structure");
423*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_alloc_cmd_exit,
424*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
425*0Sstevel@tonic-gate return (DDI_FAILURE);
426*0Sstevel@tonic-gate }
427*0Sstevel@tonic-gate
428*0Sstevel@tonic-gate /* Get the Services Layer private area */
429*0Sstevel@tonic-gate s_priv = S1394_GET_CMD_PRIV(*cmdp);
430*0Sstevel@tonic-gate
431*0Sstevel@tonic-gate *hal_priv_ptr = &s_priv->hal_cmd_private;
432*0Sstevel@tonic-gate
433*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_alloc_cmd_exit, S1394_TNF_SL_ARREQ_STACK,
434*0Sstevel@tonic-gate "");
435*0Sstevel@tonic-gate return (DDI_SUCCESS);
436*0Sstevel@tonic-gate }
437*0Sstevel@tonic-gate
438*0Sstevel@tonic-gate /*
439*0Sstevel@tonic-gate * Function: h1394_free_cmd()
440*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
441*0Sstevel@tonic-gate * h1394_attach()
442*0Sstevel@tonic-gate * cmdp Pointer to the command to be freed
443*0Sstevel@tonic-gate *
444*0Sstevel@tonic-gate * Output(s): DDI_SUCCESS HAL successfully freed command
445*0Sstevel@tonic-gate * DDI_FAILURE HAL failed to free command
446*0Sstevel@tonic-gate *
447*0Sstevel@tonic-gate * Description: h1394_free_cmd() attempts to free a command that has previously
448*0Sstevel@tonic-gate * been allocated by the HAL. It is possible for h1394_free_cmd()
449*0Sstevel@tonic-gate * to fail because the command is currently in-use by the 1394
450*0Sstevel@tonic-gate * Software Framework.
451*0Sstevel@tonic-gate */
452*0Sstevel@tonic-gate int
h1394_free_cmd(void * sl_private,cmd1394_cmd_t ** cmdp)453*0Sstevel@tonic-gate h1394_free_cmd(void *sl_private, cmd1394_cmd_t **cmdp)
454*0Sstevel@tonic-gate {
455*0Sstevel@tonic-gate s1394_hal_t *hal;
456*0Sstevel@tonic-gate s1394_cmd_priv_t *s_priv;
457*0Sstevel@tonic-gate
458*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_free_cmd_enter, S1394_TNF_SL_ARREQ_STACK,
459*0Sstevel@tonic-gate "");
460*0Sstevel@tonic-gate
461*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
462*0Sstevel@tonic-gate
463*0Sstevel@tonic-gate /* Get the Services Layer private area */
464*0Sstevel@tonic-gate s_priv = S1394_GET_CMD_PRIV(*cmdp);
465*0Sstevel@tonic-gate
466*0Sstevel@tonic-gate /* Check that command isn't in use */
467*0Sstevel@tonic-gate if (s_priv->cmd_in_use == B_TRUE) {
468*0Sstevel@tonic-gate TNF_PROBE_1(h1394_free_cmd_error, S1394_TNF_SL_ARREQ_ERROR, "",
469*0Sstevel@tonic-gate tnf_string, msg, "Attempted to free an in-use command");
470*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_free_cmd_exit, S1394_TNF_SL_ARREQ_STACK,
471*0Sstevel@tonic-gate "");
472*0Sstevel@tonic-gate ASSERT(s_priv->cmd_in_use == B_FALSE);
473*0Sstevel@tonic-gate return (DDI_FAILURE);
474*0Sstevel@tonic-gate }
475*0Sstevel@tonic-gate
476*0Sstevel@tonic-gate kmem_cache_free(hal->hal_kmem_cachep, *cmdp);
477*0Sstevel@tonic-gate
478*0Sstevel@tonic-gate /* Command pointer is set to NULL before returning */
479*0Sstevel@tonic-gate *cmdp = NULL;
480*0Sstevel@tonic-gate
481*0Sstevel@tonic-gate /* kstats - number of cmds freed */
482*0Sstevel@tonic-gate hal->hal_kstats->cmd_free++;
483*0Sstevel@tonic-gate
484*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_free_cmd_exit, S1394_TNF_SL_ARREQ_STACK,
485*0Sstevel@tonic-gate "");
486*0Sstevel@tonic-gate return (DDI_SUCCESS);
487*0Sstevel@tonic-gate }
488*0Sstevel@tonic-gate
489*0Sstevel@tonic-gate /*
490*0Sstevel@tonic-gate * Function: h1394_cmd_is_complete()
491*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
492*0Sstevel@tonic-gate * h1394_attach()
493*0Sstevel@tonic-gate * command_id Pointer to the command that has
494*0Sstevel@tonic-gate * just completed
495*0Sstevel@tonic-gate * cmd_type AT_RESP => AT response or ATREQ =
496*0Sstevel@tonic-gate * AT request
497*0Sstevel@tonic-gate * status Command's completion status
498*0Sstevel@tonic-gate *
499*0Sstevel@tonic-gate * Output(s): None
500*0Sstevel@tonic-gate *
501*0Sstevel@tonic-gate * Description: h1394_cmd_is_complete() is called by the HAL whenever an
502*0Sstevel@tonic-gate * outstanding command has completed (successfully or otherwise).
503*0Sstevel@tonic-gate * After determining whether it was an AT request or and AT
504*0Sstevel@tonic-gate * response that we are handling, the command is dispatched to
505*0Sstevel@tonic-gate * the appropriate handler in the 1394 Software Framework.
506*0Sstevel@tonic-gate */
507*0Sstevel@tonic-gate void
h1394_cmd_is_complete(void * sl_private,cmd1394_cmd_t * command_id,uint32_t cmd_type,int status)508*0Sstevel@tonic-gate h1394_cmd_is_complete(void *sl_private, cmd1394_cmd_t *command_id,
509*0Sstevel@tonic-gate uint32_t cmd_type, int status)
510*0Sstevel@tonic-gate {
511*0Sstevel@tonic-gate s1394_hal_t *hal;
512*0Sstevel@tonic-gate dev_info_t *dip;
513*0Sstevel@tonic-gate
514*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_cmd_is_complete_enter,
515*0Sstevel@tonic-gate S1394_TNF_SL_ATREQ_ATRESP_STACK, "");
516*0Sstevel@tonic-gate
517*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
518*0Sstevel@tonic-gate
519*0Sstevel@tonic-gate /* Is it AT_RESP or AT_REQ? */
520*0Sstevel@tonic-gate switch (cmd_type) {
521*0Sstevel@tonic-gate case H1394_AT_REQ:
522*0Sstevel@tonic-gate s1394_atreq_cmd_complete(hal, command_id, status);
523*0Sstevel@tonic-gate break;
524*0Sstevel@tonic-gate
525*0Sstevel@tonic-gate case H1394_AT_RESP:
526*0Sstevel@tonic-gate s1394_atresp_cmd_complete(hal, command_id, status);
527*0Sstevel@tonic-gate break;
528*0Sstevel@tonic-gate
529*0Sstevel@tonic-gate default:
530*0Sstevel@tonic-gate dip = hal->halinfo.dip;
531*0Sstevel@tonic-gate
532*0Sstevel@tonic-gate /* An unexpected error in the HAL */
533*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
534*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
535*0Sstevel@tonic-gate
536*0Sstevel@tonic-gate /* Disable the HAL */
537*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
538*0Sstevel@tonic-gate
539*0Sstevel@tonic-gate TNF_PROBE_1(h1394_cmd_is_complete_error,
540*0Sstevel@tonic-gate S1394_TNF_SL_ATREQ_ATRESP_ERROR, "",
541*0Sstevel@tonic-gate tnf_string, msg, "Invalid command type specified");
542*0Sstevel@tonic-gate break;
543*0Sstevel@tonic-gate }
544*0Sstevel@tonic-gate
545*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_cmd_is_complete_exit,
546*0Sstevel@tonic-gate S1394_TNF_SL_ATREQ_ATRESP_STACK, "");
547*0Sstevel@tonic-gate }
548*0Sstevel@tonic-gate
549*0Sstevel@tonic-gate /*
550*0Sstevel@tonic-gate * Function: h1394_bus_reset()
551*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
552*0Sstevel@tonic-gate * h1394_attach()
553*0Sstevel@tonic-gate *
554*0Sstevel@tonic-gate * Output(s): selfid_buf_addr The pointer to a buffer into which
555*0Sstevel@tonic-gate * any Self ID packets should be put
556*0Sstevel@tonic-gate *
557*0Sstevel@tonic-gate * Description: h1394_bus_reset() is called whenever a 1394 bus reset event
558*0Sstevel@tonic-gate * is detected by the HAL. This routine simply prepares for
559*0Sstevel@tonic-gate * the subsequent Self ID packets.
560*0Sstevel@tonic-gate */
561*0Sstevel@tonic-gate void
h1394_bus_reset(void * sl_private,void ** selfid_buf_addr)562*0Sstevel@tonic-gate h1394_bus_reset(void *sl_private, void **selfid_buf_addr)
563*0Sstevel@tonic-gate {
564*0Sstevel@tonic-gate s1394_hal_t *hal;
565*0Sstevel@tonic-gate
566*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_bus_reset_enter, S1394_TNF_SL_BR_STACK, "");
567*0Sstevel@tonic-gate
568*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
569*0Sstevel@tonic-gate
570*0Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
571*0Sstevel@tonic-gate
572*0Sstevel@tonic-gate /* Update the HAL's state */
573*0Sstevel@tonic-gate if (hal->hal_state != S1394_HAL_SHUTDOWN) {
574*0Sstevel@tonic-gate hal->hal_state = S1394_HAL_RESET;
575*0Sstevel@tonic-gate } else {
576*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
577*0Sstevel@tonic-gate return;
578*0Sstevel@tonic-gate }
579*0Sstevel@tonic-gate
580*0Sstevel@tonic-gate if (hal->initiated_bus_reset == B_TRUE) {
581*0Sstevel@tonic-gate hal->initiated_bus_reset = B_FALSE;
582*0Sstevel@tonic-gate if (hal->num_bus_reset_till_fail > 0) {
583*0Sstevel@tonic-gate hal->num_bus_reset_till_fail--;
584*0Sstevel@tonic-gate } else {
585*0Sstevel@tonic-gate TNF_PROBE_2(h1394_bus_reset_error,
586*0Sstevel@tonic-gate S1394_TNF_SL_BR_ERROR, "",
587*0Sstevel@tonic-gate tnf_string, msg, "Bus reset fail (too many resets)",
588*0Sstevel@tonic-gate tnf_uint, br_type, hal->initiated_br_reason);
589*0Sstevel@tonic-gate }
590*0Sstevel@tonic-gate } else {
591*0Sstevel@tonic-gate hal->num_bus_reset_till_fail = NUM_BR_FAIL;
592*0Sstevel@tonic-gate }
593*0Sstevel@tonic-gate
594*0Sstevel@tonic-gate /* Reset the IRM node ID */
595*0Sstevel@tonic-gate hal->IRM_node = -1;
596*0Sstevel@tonic-gate
597*0Sstevel@tonic-gate /* Slowest node defaults to IEEE1394_S400 */
598*0Sstevel@tonic-gate hal->slowest_node_speed = IEEE1394_S400;
599*0Sstevel@tonic-gate
600*0Sstevel@tonic-gate /* Pick a SelfID buffer to give */
601*0Sstevel@tonic-gate if (hal->current_buffer == 0) {
602*0Sstevel@tonic-gate *selfid_buf_addr = (void *)hal->selfid_buf1;
603*0Sstevel@tonic-gate hal->current_buffer = 1;
604*0Sstevel@tonic-gate } else {
605*0Sstevel@tonic-gate *selfid_buf_addr = (void *)hal->selfid_buf0;
606*0Sstevel@tonic-gate hal->current_buffer = 0;
607*0Sstevel@tonic-gate }
608*0Sstevel@tonic-gate
609*0Sstevel@tonic-gate /* Disable the CSR topology_map (temporarily) */
610*0Sstevel@tonic-gate s1394_CSR_topology_map_disable(hal);
611*0Sstevel@tonic-gate
612*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
613*0Sstevel@tonic-gate
614*0Sstevel@tonic-gate /* Reset the Bus Manager node ID */
615*0Sstevel@tonic-gate mutex_enter(&hal->bus_mgr_node_mutex);
616*0Sstevel@tonic-gate hal->bus_mgr_node = -1;
617*0Sstevel@tonic-gate mutex_exit(&hal->bus_mgr_node_mutex);
618*0Sstevel@tonic-gate
619*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_bus_reset_exit, S1394_TNF_SL_BR_STACK, "");
620*0Sstevel@tonic-gate }
621*0Sstevel@tonic-gate
622*0Sstevel@tonic-gate /*
623*0Sstevel@tonic-gate * Function: h1394_self_ids()
624*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
625*0Sstevel@tonic-gate * h1394_attach()
626*0Sstevel@tonic-gate * selfid_buf_addr Pointer to the Self ID buffer
627*0Sstevel@tonic-gate * selfid_size The size of the filled part of the
628*0Sstevel@tonic-gate * Self ID buffer
629*0Sstevel@tonic-gate * node_id The local (host) node ID for the
630*0Sstevel@tonic-gate * current generation
631*0Sstevel@tonic-gate * generation_count The current generation number
632*0Sstevel@tonic-gate *
633*0Sstevel@tonic-gate * Output(s): None
634*0Sstevel@tonic-gate *
635*0Sstevel@tonic-gate * Description: h1394_self_ids() does alot of the work at bus reset. It
636*0Sstevel@tonic-gate * takes the Self ID packets and parses them, builds a topology
637*0Sstevel@tonic-gate * tree representation of them, calculates gap count, IRM, speed
638*0Sstevel@tonic-gate * map, does any node matching that's possible, and then wakes
639*0Sstevel@tonic-gate * up the br_thread.
640*0Sstevel@tonic-gate */
641*0Sstevel@tonic-gate void
h1394_self_ids(void * sl_private,void * selfid_buf_addr,uint32_t selfid_size,uint32_t node_id,uint32_t generation_count)642*0Sstevel@tonic-gate h1394_self_ids(void *sl_private, void *selfid_buf_addr, uint32_t selfid_size,
643*0Sstevel@tonic-gate uint32_t node_id, uint32_t generation_count)
644*0Sstevel@tonic-gate {
645*0Sstevel@tonic-gate s1394_hal_t *hal;
646*0Sstevel@tonic-gate int diameter;
647*0Sstevel@tonic-gate uint_t gen_diff, gen_rollover;
648*0Sstevel@tonic-gate boolean_t tree_copied = B_FALSE;
649*0Sstevel@tonic-gate ushort_t saved_number_of_nodes;
650*0Sstevel@tonic-gate
651*0Sstevel@tonic-gate /*
652*0Sstevel@tonic-gate * NOTE: current topology tree is referred to as topology_tree
653*0Sstevel@tonic-gate * and the old topology tree is referred to as old_tree.
654*0Sstevel@tonic-gate * tree_valid indicates selfID buffer checked out OK and we were
655*0Sstevel@tonic-gate * able to build the topology tree.
656*0Sstevel@tonic-gate * tree_processed indicates we read the config ROMs as needed.
657*0Sstevel@tonic-gate */
658*0Sstevel@tonic-gate TNF_PROBE_1_DEBUG(h1394_self_ids_enter, S1394_TNF_SL_BR_STACK, "",
659*0Sstevel@tonic-gate tnf_uint, hal_generation, generation_count);
660*0Sstevel@tonic-gate
661*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
662*0Sstevel@tonic-gate
663*0Sstevel@tonic-gate /* Lock the topology tree */
664*0Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
665*0Sstevel@tonic-gate if (hal->hal_state == S1394_HAL_SHUTDOWN) {
666*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
667*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_exit, S1394_TNF_SL_BR_STACK,
668*0Sstevel@tonic-gate "");
669*0Sstevel@tonic-gate return;
670*0Sstevel@tonic-gate }
671*0Sstevel@tonic-gate
672*0Sstevel@tonic-gate /* kstats - number of selfid completes */
673*0Sstevel@tonic-gate hal->hal_kstats->selfid_complete++;
674*0Sstevel@tonic-gate
675*0Sstevel@tonic-gate if (generation_count > hal->generation_count) {
676*0Sstevel@tonic-gate gen_diff = generation_count - hal->generation_count;
677*0Sstevel@tonic-gate hal->hal_kstats->bus_reset += gen_diff;
678*0Sstevel@tonic-gate } else {
679*0Sstevel@tonic-gate gen_diff = hal->generation_count - generation_count;
680*0Sstevel@tonic-gate /* Use max_generation to determine how many bus resets */
681*0Sstevel@tonic-gate hal->hal_kstats->bus_reset +=
682*0Sstevel@tonic-gate (hal->halinfo.max_generation - gen_diff);
683*0Sstevel@tonic-gate }
684*0Sstevel@tonic-gate
685*0Sstevel@tonic-gate /*
686*0Sstevel@tonic-gate * If the current tree has a valid topology tree (selfids
687*0Sstevel@tonic-gate * checked out OK etc) and config roms read as needed,
688*0Sstevel@tonic-gate * then make it the old tree before building a new one.
689*0Sstevel@tonic-gate */
690*0Sstevel@tonic-gate if ((hal->topology_tree_valid == B_TRUE) &&
691*0Sstevel@tonic-gate (hal->topology_tree_processed == B_TRUE)) {
692*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_tree_copy,
693*0Sstevel@tonic-gate S1394_TNF_SL_BR_STACK, "");
694*0Sstevel@tonic-gate /* Trees are switched after the copy completes */
695*0Sstevel@tonic-gate s1394_copy_old_tree(hal);
696*0Sstevel@tonic-gate tree_copied = B_TRUE;
697*0Sstevel@tonic-gate }
698*0Sstevel@tonic-gate
699*0Sstevel@tonic-gate /* Set the new generation and node id */
700*0Sstevel@tonic-gate hal->node_id = node_id;
701*0Sstevel@tonic-gate hal->generation_count = generation_count;
702*0Sstevel@tonic-gate
703*0Sstevel@tonic-gate /* Invalidate the current topology tree */
704*0Sstevel@tonic-gate hal->topology_tree_valid = B_FALSE;
705*0Sstevel@tonic-gate hal->topology_tree_processed = B_FALSE;
706*0Sstevel@tonic-gate hal->cfgroms_being_read = 0;
707*0Sstevel@tonic-gate
708*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_parse_selfid, S1394_TNF_SL_BR_STACK,
709*0Sstevel@tonic-gate "");
710*0Sstevel@tonic-gate
711*0Sstevel@tonic-gate /*
712*0Sstevel@tonic-gate * Save the number of nodes prior to parsing the self id buffer.
713*0Sstevel@tonic-gate * We need this saved value while initializing the topology tree
714*0Sstevel@tonic-gate * (for non-copy case).
715*0Sstevel@tonic-gate */
716*0Sstevel@tonic-gate saved_number_of_nodes = hal->number_of_nodes;
717*0Sstevel@tonic-gate
718*0Sstevel@tonic-gate /* Parse the SelfID buffer */
719*0Sstevel@tonic-gate if (s1394_parse_selfid_buffer(hal, selfid_buf_addr, selfid_size) !=
720*0Sstevel@tonic-gate DDI_SUCCESS) {
721*0Sstevel@tonic-gate /* Unlock the topology tree */
722*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
723*0Sstevel@tonic-gate TNF_PROBE_1(h1394_self_ids_error, S1394_TNF_SL_BR_ERROR, "",
724*0Sstevel@tonic-gate tnf_string, msg, "Unable to parse selfID buffer");
725*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_exit, S1394_TNF_SL_BR_STACK,
726*0Sstevel@tonic-gate "");
727*0Sstevel@tonic-gate
728*0Sstevel@tonic-gate /* kstats - SelfID buffer error */
729*0Sstevel@tonic-gate hal->hal_kstats->selfid_buffer_error++;
730*0Sstevel@tonic-gate return; /* Error parsing SelfIDs */
731*0Sstevel@tonic-gate }
732*0Sstevel@tonic-gate
733*0Sstevel@tonic-gate /* Sort the SelfID packets by node number (if it's a 1995 PHY) */
734*0Sstevel@tonic-gate if (hal->halinfo.phy == H1394_PHY_1995) {
735*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_sort, S1394_TNF_SL_BR_STACK,
736*0Sstevel@tonic-gate "");
737*0Sstevel@tonic-gate s1394_sort_selfids(hal);
738*0Sstevel@tonic-gate }
739*0Sstevel@tonic-gate
740*0Sstevel@tonic-gate /*
741*0Sstevel@tonic-gate * Update the cycle master timer - if the timer is set and
742*0Sstevel@tonic-gate * we were the root but we are not anymore, then disable it.
743*0Sstevel@tonic-gate */
744*0Sstevel@tonic-gate mutex_enter(&hal->cm_timer_mutex);
745*0Sstevel@tonic-gate if ((hal->cm_timer_set == B_TRUE) &&
746*0Sstevel@tonic-gate ((hal->old_number_of_nodes - 1) ==
747*0Sstevel@tonic-gate IEEE1394_NODE_NUM(hal->old_node_id)) &&
748*0Sstevel@tonic-gate ((hal->number_of_nodes - 1) !=
749*0Sstevel@tonic-gate IEEE1394_NODE_NUM(hal->node_id))) {
750*0Sstevel@tonic-gate mutex_exit(&hal->cm_timer_mutex);
751*0Sstevel@tonic-gate (void) untimeout(hal->cm_timer);
752*0Sstevel@tonic-gate } else {
753*0Sstevel@tonic-gate mutex_exit(&hal->cm_timer_mutex);
754*0Sstevel@tonic-gate }
755*0Sstevel@tonic-gate
756*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_init_topology, S1394_TNF_SL_BR_STACK,
757*0Sstevel@tonic-gate "");
758*0Sstevel@tonic-gate s1394_init_topology_tree(hal, tree_copied, saved_number_of_nodes);
759*0Sstevel@tonic-gate
760*0Sstevel@tonic-gate /* Determine the 1394 bus gap count */
761*0Sstevel@tonic-gate hal->gap_count = s1394_get_current_gap_count(hal);
762*0Sstevel@tonic-gate /* If gap counts are inconsistent, reset */
763*0Sstevel@tonic-gate if (hal->gap_count == -1) {
764*0Sstevel@tonic-gate /* Unlock the topology tree */
765*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
766*0Sstevel@tonic-gate TNF_PROBE_1(h1394_self_ids_error, S1394_TNF_SL_BR_ERROR, "",
767*0Sstevel@tonic-gate tnf_string, msg, "Invalid gap counts in SelfID pkts");
768*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_exit, S1394_TNF_SL_BR_STACK,
769*0Sstevel@tonic-gate "");
770*0Sstevel@tonic-gate
771*0Sstevel@tonic-gate /* kstats - SelfID buffer error (invalid gap counts) */
772*0Sstevel@tonic-gate hal->hal_kstats->selfid_buffer_error++;
773*0Sstevel@tonic-gate
774*0Sstevel@tonic-gate if (s1394_ignore_invalid_gap_cnt == 1) {
775*0Sstevel@tonic-gate /* Lock the topology tree again */
776*0Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
777*0Sstevel@tonic-gate hal->gap_count = 0x3F;
778*0Sstevel@tonic-gate } else {
779*0Sstevel@tonic-gate return; /* Invalid gap counts in SelfID buffer */
780*0Sstevel@tonic-gate }
781*0Sstevel@tonic-gate }
782*0Sstevel@tonic-gate
783*0Sstevel@tonic-gate TNF_PROBE_1_DEBUG(h1394_self_ids_get_gap_count, S1394_TNF_SL_BR_STACK,
784*0Sstevel@tonic-gate "", tnf_uint, gap_count, hal->gap_count);
785*0Sstevel@tonic-gate
786*0Sstevel@tonic-gate /* Determine the Isoch Resource Manager */
787*0Sstevel@tonic-gate hal->IRM_node = s1394_get_isoch_rsrc_mgr(hal);
788*0Sstevel@tonic-gate
789*0Sstevel@tonic-gate TNF_PROBE_1_DEBUG(h1394_self_ids_IRM_node, S1394_TNF_SL_BR_STACK, "",
790*0Sstevel@tonic-gate tnf_int, IRM_node, hal->IRM_node);
791*0Sstevel@tonic-gate
792*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_build_topology_tree,
793*0Sstevel@tonic-gate S1394_TNF_SL_BR_STACK, "");
794*0Sstevel@tonic-gate
795*0Sstevel@tonic-gate /* Build the topology tree */
796*0Sstevel@tonic-gate if (s1394_topology_tree_build(hal) != DDI_SUCCESS) {
797*0Sstevel@tonic-gate /* Unlock the topology tree */
798*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
799*0Sstevel@tonic-gate TNF_PROBE_1(h1394_self_ids_error, S1394_TNF_SL_BR_ERROR, "",
800*0Sstevel@tonic-gate tnf_string, msg, "Error building the topology tree");
801*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_exit, S1394_TNF_SL_BR_STACK,
802*0Sstevel@tonic-gate "");
803*0Sstevel@tonic-gate
804*0Sstevel@tonic-gate /* kstats - SelfID buffer error (Invalid topology tree) */
805*0Sstevel@tonic-gate hal->hal_kstats->selfid_buffer_error++;
806*0Sstevel@tonic-gate return; /* Error building topology tree from SelfIDs */
807*0Sstevel@tonic-gate }
808*0Sstevel@tonic-gate
809*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_topology_CSRs, S1394_TNF_SL_BR_STACK,
810*0Sstevel@tonic-gate "");
811*0Sstevel@tonic-gate
812*0Sstevel@tonic-gate /* Update the CSR topology_map */
813*0Sstevel@tonic-gate s1394_CSR_topology_map_update(hal);
814*0Sstevel@tonic-gate
815*0Sstevel@tonic-gate /* Calculate the diameter */
816*0Sstevel@tonic-gate diameter = s1394_topology_tree_calculate_diameter(hal);
817*0Sstevel@tonic-gate
818*0Sstevel@tonic-gate /* Determine the optimum gap count */
819*0Sstevel@tonic-gate hal->optimum_gap_count = s1394_gap_count_optimize(diameter);
820*0Sstevel@tonic-gate
821*0Sstevel@tonic-gate TNF_PROBE_1_DEBUG(h1394_self_ids_diameter_and_gap_count,
822*0Sstevel@tonic-gate S1394_TNF_SL_BR_STACK, "",
823*0Sstevel@tonic-gate tnf_uint, optimum_gap, hal->optimum_gap_count);
824*0Sstevel@tonic-gate
825*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_speed_map, S1394_TNF_SL_BR_STACK, "");
826*0Sstevel@tonic-gate
827*0Sstevel@tonic-gate /* Fill in the speed map */
828*0Sstevel@tonic-gate s1394_speed_map_fill(hal);
829*0Sstevel@tonic-gate
830*0Sstevel@tonic-gate /* Initialize the two trees (for tree walking) */
831*0Sstevel@tonic-gate s1394_topology_tree_mark_all_unvisited(hal);
832*0Sstevel@tonic-gate s1394_old_tree_mark_all_unvisited(hal);
833*0Sstevel@tonic-gate s1394_old_tree_mark_all_unmatched(hal);
834*0Sstevel@tonic-gate
835*0Sstevel@tonic-gate /* Are both trees (old and new) valid? */
836*0Sstevel@tonic-gate if ((hal->old_tree_valid == B_TRUE) &&
837*0Sstevel@tonic-gate (hal->topology_tree_valid == B_TRUE)) {
838*0Sstevel@tonic-gate /* If HAL was in a suspended state, then do no matching */
839*0Sstevel@tonic-gate if (hal->hal_was_suspended == B_TRUE) {
840*0Sstevel@tonic-gate hal->hal_was_suspended = B_FALSE;
841*0Sstevel@tonic-gate } else {
842*0Sstevel@tonic-gate gen_rollover = hal->halinfo.max_generation + 1;
843*0Sstevel@tonic-gate /* If only one bus reset occurred, match the trees */
844*0Sstevel@tonic-gate if (((hal->old_generation_count + 1) % gen_rollover) ==
845*0Sstevel@tonic-gate generation_count) {
846*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_tree_matching,
847*0Sstevel@tonic-gate S1394_TNF_SL_BR_STACK, "");
848*0Sstevel@tonic-gate s1394_match_tree_nodes(hal);
849*0Sstevel@tonic-gate }
850*0Sstevel@tonic-gate }
851*0Sstevel@tonic-gate }
852*0Sstevel@tonic-gate
853*0Sstevel@tonic-gate /* Unlock the topology tree */
854*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
855*0Sstevel@tonic-gate
856*0Sstevel@tonic-gate /* Wake up the bus reset processing thread */
857*0Sstevel@tonic-gate s1394_tickle_bus_reset_thread(hal);
858*0Sstevel@tonic-gate
859*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_self_ids_exit,
860*0Sstevel@tonic-gate S1394_TNF_SL_BR_STACK, "");
861*0Sstevel@tonic-gate }
862*0Sstevel@tonic-gate
863*0Sstevel@tonic-gate /*
864*0Sstevel@tonic-gate * Function: h1394_read_request()
865*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
866*0Sstevel@tonic-gate * h1394_attach()
867*0Sstevel@tonic-gate * req The incoming AR request
868*0Sstevel@tonic-gate *
869*0Sstevel@tonic-gate * Output(s): None
870*0Sstevel@tonic-gate *
871*0Sstevel@tonic-gate * Description: h1394_read_request() receives incoming AR requests. These
872*0Sstevel@tonic-gate * asynchronous read requests are dispatched to the appropriate
873*0Sstevel@tonic-gate * target (if one has registered) or are handled by the 1394
874*0Sstevel@tonic-gate * Software Framework, which will send out an appropriate
875*0Sstevel@tonic-gate * response.
876*0Sstevel@tonic-gate */
877*0Sstevel@tonic-gate void
h1394_read_request(void * sl_private,cmd1394_cmd_t * req)878*0Sstevel@tonic-gate h1394_read_request(void *sl_private, cmd1394_cmd_t *req)
879*0Sstevel@tonic-gate {
880*0Sstevel@tonic-gate s1394_hal_t *hal;
881*0Sstevel@tonic-gate s1394_cmd_priv_t *s_priv;
882*0Sstevel@tonic-gate s1394_addr_space_blk_t *addr_blk;
883*0Sstevel@tonic-gate dev_info_t *dip;
884*0Sstevel@tonic-gate uint64_t end_of_request;
885*0Sstevel@tonic-gate uint32_t offset;
886*0Sstevel@tonic-gate size_t cmd_length;
887*0Sstevel@tonic-gate uchar_t *bufp_addr;
888*0Sstevel@tonic-gate uchar_t *begin_ptr;
889*0Sstevel@tonic-gate uchar_t *end_ptr;
890*0Sstevel@tonic-gate uchar_t *tmp_ptr;
891*0Sstevel@tonic-gate void (*recv_read_req)(cmd1394_cmd_t *);
892*0Sstevel@tonic-gate
893*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_enter, S1394_TNF_SL_ARREQ_STACK,
894*0Sstevel@tonic-gate "");
895*0Sstevel@tonic-gate
896*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
897*0Sstevel@tonic-gate
898*0Sstevel@tonic-gate /* Get the Services Layer private area */
899*0Sstevel@tonic-gate s_priv = S1394_GET_CMD_PRIV(req);
900*0Sstevel@tonic-gate
901*0Sstevel@tonic-gate s_priv->cmd_priv_xfer_type = S1394_CMD_READ;
902*0Sstevel@tonic-gate
903*0Sstevel@tonic-gate switch (req->cmd_type) {
904*0Sstevel@tonic-gate case CMD1394_ASYNCH_RD_QUAD:
905*0Sstevel@tonic-gate cmd_length = IEEE1394_QUADLET;
906*0Sstevel@tonic-gate hal->hal_kstats->arreq_quad_rd++;
907*0Sstevel@tonic-gate break;
908*0Sstevel@tonic-gate
909*0Sstevel@tonic-gate case CMD1394_ASYNCH_RD_BLOCK:
910*0Sstevel@tonic-gate cmd_length = req->cmd_u.b.blk_length;
911*0Sstevel@tonic-gate hal->hal_kstats->arreq_blk_rd++;
912*0Sstevel@tonic-gate break;
913*0Sstevel@tonic-gate
914*0Sstevel@tonic-gate default:
915*0Sstevel@tonic-gate dip = hal->halinfo.dip;
916*0Sstevel@tonic-gate
917*0Sstevel@tonic-gate /* An unexpected error in the HAL */
918*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
919*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
920*0Sstevel@tonic-gate
921*0Sstevel@tonic-gate /* Disable the HAL */
922*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
923*0Sstevel@tonic-gate
924*0Sstevel@tonic-gate TNF_PROBE_1(h1394_read_request_error,
925*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "",
926*0Sstevel@tonic-gate tnf_string, msg, "Invalid command type specified");
927*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
928*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
929*0Sstevel@tonic-gate return;
930*0Sstevel@tonic-gate }
931*0Sstevel@tonic-gate
932*0Sstevel@tonic-gate /* Lock the "used" tree */
933*0Sstevel@tonic-gate mutex_enter(&hal->addr_space_used_mutex);
934*0Sstevel@tonic-gate
935*0Sstevel@tonic-gate /* Has the 1394 address been allocated? */
936*0Sstevel@tonic-gate addr_blk = s1394_used_tree_search(hal, req->cmd_addr);
937*0Sstevel@tonic-gate
938*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_addr_search,
939*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
940*0Sstevel@tonic-gate
941*0Sstevel@tonic-gate /* If it wasn't found, it isn't owned... */
942*0Sstevel@tonic-gate if (addr_blk == NULL) {
943*0Sstevel@tonic-gate /* Unlock the "used" tree */
944*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
945*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
946*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
947*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
948*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
949*0Sstevel@tonic-gate return;
950*0Sstevel@tonic-gate }
951*0Sstevel@tonic-gate
952*0Sstevel@tonic-gate /* Does the WHOLE request fit in the allocated block? */
953*0Sstevel@tonic-gate end_of_request = (req->cmd_addr + cmd_length) - 1;
954*0Sstevel@tonic-gate if (end_of_request > addr_blk->addr_hi) {
955*0Sstevel@tonic-gate /* Unlock the "used" tree */
956*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
957*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
958*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
959*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
960*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
961*0Sstevel@tonic-gate return;
962*0Sstevel@tonic-gate }
963*0Sstevel@tonic-gate
964*0Sstevel@tonic-gate /* Is a read request valid for this address space? */
965*0Sstevel@tonic-gate if (!(addr_blk->addr_enable & T1394_ADDR_RDENBL)) {
966*0Sstevel@tonic-gate /* Unlock the "used" tree */
967*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
968*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
969*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
970*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
971*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
972*0Sstevel@tonic-gate return;
973*0Sstevel@tonic-gate }
974*0Sstevel@tonic-gate
975*0Sstevel@tonic-gate /* Make sure quadlet requests are quadlet-aligned */
976*0Sstevel@tonic-gate offset = req->cmd_addr - addr_blk->addr_lo;
977*0Sstevel@tonic-gate if ((req->cmd_type == CMD1394_ASYNCH_RD_QUAD) &&
978*0Sstevel@tonic-gate ((offset & 0x3) != 0)) {
979*0Sstevel@tonic-gate /* Unlock the "used" tree */
980*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
981*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
982*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
983*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
984*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
985*0Sstevel@tonic-gate return;
986*0Sstevel@tonic-gate }
987*0Sstevel@tonic-gate
988*0Sstevel@tonic-gate /* Fill in the backing store if necessary */
989*0Sstevel@tonic-gate if (addr_blk->kmem_bufp != NULL) {
990*0Sstevel@tonic-gate offset = req->cmd_addr - addr_blk->addr_lo;
991*0Sstevel@tonic-gate bufp_addr = (uchar_t *)addr_blk->kmem_bufp + offset;
992*0Sstevel@tonic-gate
993*0Sstevel@tonic-gate switch (req->cmd_type) {
994*0Sstevel@tonic-gate case CMD1394_ASYNCH_RD_QUAD:
995*0Sstevel@tonic-gate bcopy((void *)bufp_addr,
996*0Sstevel@tonic-gate (void *)&(req->cmd_u.q.quadlet_data), cmd_length);
997*0Sstevel@tonic-gate break;
998*0Sstevel@tonic-gate
999*0Sstevel@tonic-gate case CMD1394_ASYNCH_RD_BLOCK:
1000*0Sstevel@tonic-gate begin_ptr = req->cmd_u.b.data_block->b_wptr;
1001*0Sstevel@tonic-gate end_ptr = begin_ptr + cmd_length;
1002*0Sstevel@tonic-gate tmp_ptr = req->cmd_u.b.data_block->b_datap->db_lim;
1003*0Sstevel@tonic-gate if (end_ptr <= tmp_ptr) {
1004*0Sstevel@tonic-gate bcopy((void *)bufp_addr, (void *)begin_ptr,
1005*0Sstevel@tonic-gate cmd_length);
1006*0Sstevel@tonic-gate /* Update b_wptr to refelect the new data */
1007*0Sstevel@tonic-gate req->cmd_u.b.data_block->b_wptr = end_ptr;
1008*0Sstevel@tonic-gate } else {
1009*0Sstevel@tonic-gate dip = hal->halinfo.dip;
1010*0Sstevel@tonic-gate
1011*0Sstevel@tonic-gate /* An unexpected error in the HAL */
1012*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
1013*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
1014*0Sstevel@tonic-gate
1015*0Sstevel@tonic-gate /* Unlock the "used" tree */
1016*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1017*0Sstevel@tonic-gate
1018*0Sstevel@tonic-gate /* Disable the HAL */
1019*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
1020*0Sstevel@tonic-gate
1021*0Sstevel@tonic-gate TNF_PROBE_1(h1394_read_request_error,
1022*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string,
1023*0Sstevel@tonic-gate msg, "Error - mblk too small for request");
1024*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
1025*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1026*0Sstevel@tonic-gate return;
1027*0Sstevel@tonic-gate }
1028*0Sstevel@tonic-gate break;
1029*0Sstevel@tonic-gate
1030*0Sstevel@tonic-gate default:
1031*0Sstevel@tonic-gate dip = hal->halinfo.dip;
1032*0Sstevel@tonic-gate
1033*0Sstevel@tonic-gate /* An unexpected error in the HAL */
1034*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
1035*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
1036*0Sstevel@tonic-gate
1037*0Sstevel@tonic-gate /* Unlock the "used" tree */
1038*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1039*0Sstevel@tonic-gate
1040*0Sstevel@tonic-gate /* Disable the HAL */
1041*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
1042*0Sstevel@tonic-gate
1043*0Sstevel@tonic-gate TNF_PROBE_1(h1394_read_request_error,
1044*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string, msg,
1045*0Sstevel@tonic-gate "Invalid command type specified");
1046*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
1047*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1048*0Sstevel@tonic-gate return;
1049*0Sstevel@tonic-gate }
1050*0Sstevel@tonic-gate }
1051*0Sstevel@tonic-gate
1052*0Sstevel@tonic-gate /* Fill in the rest of the info in the request */
1053*0Sstevel@tonic-gate s_priv->arreq_valid_addr = B_TRUE;
1054*0Sstevel@tonic-gate req->cmd_callback_arg = addr_blk->addr_arg;
1055*0Sstevel@tonic-gate recv_read_req = addr_blk->addr_events.recv_read_request;
1056*0Sstevel@tonic-gate
1057*0Sstevel@tonic-gate /* Unlock the "used" tree */
1058*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1059*0Sstevel@tonic-gate
1060*0Sstevel@tonic-gate /*
1061*0Sstevel@tonic-gate * Add no code that modifies the command after the target
1062*0Sstevel@tonic-gate * callback is called or after the response is sent to the
1063*0Sstevel@tonic-gate * HAL.
1064*0Sstevel@tonic-gate */
1065*0Sstevel@tonic-gate if (recv_read_req != NULL) {
1066*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_do_callback,
1067*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1068*0Sstevel@tonic-gate recv_read_req(req);
1069*0Sstevel@tonic-gate } else {
1070*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
1071*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1072*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit,
1073*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1074*0Sstevel@tonic-gate return;
1075*0Sstevel@tonic-gate }
1076*0Sstevel@tonic-gate
1077*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_read_request_exit, S1394_TNF_SL_ARREQ_STACK,
1078*0Sstevel@tonic-gate "");
1079*0Sstevel@tonic-gate }
1080*0Sstevel@tonic-gate
1081*0Sstevel@tonic-gate /*
1082*0Sstevel@tonic-gate * Function: h1394_write_request()
1083*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
1084*0Sstevel@tonic-gate * h1394_attach()
1085*0Sstevel@tonic-gate * req The incoming AR request
1086*0Sstevel@tonic-gate *
1087*0Sstevel@tonic-gate * Output(s): None
1088*0Sstevel@tonic-gate *
1089*0Sstevel@tonic-gate * Description: h1394_write_request() receives incoming AR requests. These
1090*0Sstevel@tonic-gate * asynchronous write requests are dispatched to the appropriate
1091*0Sstevel@tonic-gate * target (if one has registered) or are handled by the 1394
1092*0Sstevel@tonic-gate * Software Framework, which will send out an appropriate
1093*0Sstevel@tonic-gate * response.
1094*0Sstevel@tonic-gate */
1095*0Sstevel@tonic-gate void
h1394_write_request(void * sl_private,cmd1394_cmd_t * req)1096*0Sstevel@tonic-gate h1394_write_request(void *sl_private, cmd1394_cmd_t *req)
1097*0Sstevel@tonic-gate {
1098*0Sstevel@tonic-gate s1394_hal_t *hal;
1099*0Sstevel@tonic-gate s1394_cmd_priv_t *s_priv;
1100*0Sstevel@tonic-gate h1394_cmd_priv_t *h_priv;
1101*0Sstevel@tonic-gate s1394_addr_space_blk_t *addr_blk;
1102*0Sstevel@tonic-gate dev_info_t *dip;
1103*0Sstevel@tonic-gate uint32_t offset;
1104*0Sstevel@tonic-gate size_t cmd_length;
1105*0Sstevel@tonic-gate uchar_t *bufp_addr;
1106*0Sstevel@tonic-gate uchar_t *begin_ptr;
1107*0Sstevel@tonic-gate uchar_t *end_ptr;
1108*0Sstevel@tonic-gate uchar_t *tmp_ptr;
1109*0Sstevel@tonic-gate uint64_t end_of_request;
1110*0Sstevel@tonic-gate boolean_t posted_write = B_FALSE;
1111*0Sstevel@tonic-gate boolean_t write_error = B_FALSE;
1112*0Sstevel@tonic-gate void (*recv_write_req)(cmd1394_cmd_t *);
1113*0Sstevel@tonic-gate
1114*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_enter, S1394_TNF_SL_ARREQ_STACK,
1115*0Sstevel@tonic-gate "");
1116*0Sstevel@tonic-gate
1117*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
1118*0Sstevel@tonic-gate
1119*0Sstevel@tonic-gate /* Get the Services Layer private area */
1120*0Sstevel@tonic-gate s_priv = S1394_GET_CMD_PRIV(req);
1121*0Sstevel@tonic-gate
1122*0Sstevel@tonic-gate s_priv->cmd_priv_xfer_type = S1394_CMD_WRITE;
1123*0Sstevel@tonic-gate
1124*0Sstevel@tonic-gate switch (req->cmd_type) {
1125*0Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
1126*0Sstevel@tonic-gate cmd_length = IEEE1394_QUADLET;
1127*0Sstevel@tonic-gate hal->hal_kstats->arreq_quad_wr++;
1128*0Sstevel@tonic-gate break;
1129*0Sstevel@tonic-gate
1130*0Sstevel@tonic-gate case CMD1394_ASYNCH_WR_BLOCK:
1131*0Sstevel@tonic-gate cmd_length = req->cmd_u.b.blk_length;
1132*0Sstevel@tonic-gate hal->hal_kstats->arreq_blk_wr++;
1133*0Sstevel@tonic-gate hal->hal_kstats->arreq_blk_wr_size += cmd_length;
1134*0Sstevel@tonic-gate break;
1135*0Sstevel@tonic-gate
1136*0Sstevel@tonic-gate default:
1137*0Sstevel@tonic-gate dip = hal->halinfo.dip;
1138*0Sstevel@tonic-gate
1139*0Sstevel@tonic-gate /* An unexpected error in the HAL */
1140*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
1141*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
1142*0Sstevel@tonic-gate
1143*0Sstevel@tonic-gate /* Disable the HAL */
1144*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
1145*0Sstevel@tonic-gate
1146*0Sstevel@tonic-gate TNF_PROBE_1(h1394_write_request_error,
1147*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string, msg,
1148*0Sstevel@tonic-gate "Invalid command type specified");
1149*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_exit,
1150*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1151*0Sstevel@tonic-gate return;
1152*0Sstevel@tonic-gate }
1153*0Sstevel@tonic-gate
1154*0Sstevel@tonic-gate /* Lock the "used" tree */
1155*0Sstevel@tonic-gate mutex_enter(&hal->addr_space_used_mutex);
1156*0Sstevel@tonic-gate
1157*0Sstevel@tonic-gate /* Has the 1394 address been allocated? */
1158*0Sstevel@tonic-gate addr_blk = s1394_used_tree_search(hal, req->cmd_addr);
1159*0Sstevel@tonic-gate
1160*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_addr_search,
1161*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1162*0Sstevel@tonic-gate
1163*0Sstevel@tonic-gate /* Is this a posted write request? */
1164*0Sstevel@tonic-gate posted_write = s1394_is_posted_write(hal, req->cmd_addr);
1165*0Sstevel@tonic-gate
1166*0Sstevel@tonic-gate /* If it wasn't found, it isn't owned... */
1167*0Sstevel@tonic-gate if (addr_blk == NULL) {
1168*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
1169*0Sstevel@tonic-gate write_error = B_TRUE;
1170*0Sstevel@tonic-gate goto write_error_check;
1171*0Sstevel@tonic-gate }
1172*0Sstevel@tonic-gate
1173*0Sstevel@tonic-gate /* Does the WHOLE request fit in the allocated block? */
1174*0Sstevel@tonic-gate end_of_request = (req->cmd_addr + cmd_length) - 1;
1175*0Sstevel@tonic-gate if (end_of_request > addr_blk->addr_hi) {
1176*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
1177*0Sstevel@tonic-gate write_error = B_TRUE;
1178*0Sstevel@tonic-gate goto write_error_check;
1179*0Sstevel@tonic-gate }
1180*0Sstevel@tonic-gate
1181*0Sstevel@tonic-gate /* Is a write request valid for this address space? */
1182*0Sstevel@tonic-gate if (!(addr_blk->addr_enable & T1394_ADDR_WRENBL)) {
1183*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
1184*0Sstevel@tonic-gate write_error = B_TRUE;
1185*0Sstevel@tonic-gate goto write_error_check;
1186*0Sstevel@tonic-gate }
1187*0Sstevel@tonic-gate
1188*0Sstevel@tonic-gate /* Make sure quadlet request is quadlet aligned */
1189*0Sstevel@tonic-gate offset = req->cmd_addr - addr_blk->addr_lo;
1190*0Sstevel@tonic-gate if ((req->cmd_type == CMD1394_ASYNCH_WR_QUAD) &&
1191*0Sstevel@tonic-gate ((offset & 0x3) != 0)) {
1192*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
1193*0Sstevel@tonic-gate write_error = B_TRUE;
1194*0Sstevel@tonic-gate goto write_error_check;
1195*0Sstevel@tonic-gate }
1196*0Sstevel@tonic-gate
1197*0Sstevel@tonic-gate write_error_check:
1198*0Sstevel@tonic-gate /* Check if posted-write when sending error responses */
1199*0Sstevel@tonic-gate if (write_error == B_TRUE) {
1200*0Sstevel@tonic-gate /* Unlock the "used" tree */
1201*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1202*0Sstevel@tonic-gate
1203*0Sstevel@tonic-gate if (posted_write == B_TRUE) {
1204*0Sstevel@tonic-gate /* Get a pointer to the HAL private struct */
1205*0Sstevel@tonic-gate h_priv = (h1394_cmd_priv_t *)&s_priv->hal_cmd_private;
1206*0Sstevel@tonic-gate hal->hal_kstats->arreq_posted_write_error++;
1207*0Sstevel@tonic-gate /* Free the command - Pass it back to the HAL */
1208*0Sstevel@tonic-gate HAL_CALL(hal).response_complete(
1209*0Sstevel@tonic-gate hal->halinfo.hal_private, req, h_priv);
1210*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_exit,
1211*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1212*0Sstevel@tonic-gate return;
1213*0Sstevel@tonic-gate } else {
1214*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1215*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_exit,
1216*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1217*0Sstevel@tonic-gate return;
1218*0Sstevel@tonic-gate }
1219*0Sstevel@tonic-gate }
1220*0Sstevel@tonic-gate
1221*0Sstevel@tonic-gate /* Fill in the backing store if necessary */
1222*0Sstevel@tonic-gate if (addr_blk->kmem_bufp != NULL) {
1223*0Sstevel@tonic-gate offset = req->cmd_addr - addr_blk->addr_lo;
1224*0Sstevel@tonic-gate bufp_addr = (uchar_t *)addr_blk->kmem_bufp + offset;
1225*0Sstevel@tonic-gate switch (req->cmd_type) {
1226*0Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
1227*0Sstevel@tonic-gate bcopy((void *)&(req->cmd_u.q.quadlet_data),
1228*0Sstevel@tonic-gate (void *)bufp_addr, cmd_length);
1229*0Sstevel@tonic-gate break;
1230*0Sstevel@tonic-gate
1231*0Sstevel@tonic-gate case CMD1394_ASYNCH_WR_BLOCK:
1232*0Sstevel@tonic-gate begin_ptr = req->cmd_u.b.data_block->b_rptr;
1233*0Sstevel@tonic-gate end_ptr = begin_ptr + cmd_length;
1234*0Sstevel@tonic-gate tmp_ptr = req->cmd_u.b.data_block->b_wptr;
1235*0Sstevel@tonic-gate if (end_ptr <= tmp_ptr) {
1236*0Sstevel@tonic-gate bcopy((void *)begin_ptr, (void *)bufp_addr,
1237*0Sstevel@tonic-gate cmd_length);
1238*0Sstevel@tonic-gate } else {
1239*0Sstevel@tonic-gate dip = hal->halinfo.dip;
1240*0Sstevel@tonic-gate
1241*0Sstevel@tonic-gate /* An unexpected error in the HAL */
1242*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
1243*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
1244*0Sstevel@tonic-gate
1245*0Sstevel@tonic-gate /* Unlock the "used" tree */
1246*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1247*0Sstevel@tonic-gate
1248*0Sstevel@tonic-gate /* Disable the HAL */
1249*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
1250*0Sstevel@tonic-gate
1251*0Sstevel@tonic-gate TNF_PROBE_1(h1394_write_request_error,
1252*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string,
1253*0Sstevel@tonic-gate msg, "Error - mblk too small for request");
1254*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_exit,
1255*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1256*0Sstevel@tonic-gate return;
1257*0Sstevel@tonic-gate }
1258*0Sstevel@tonic-gate break;
1259*0Sstevel@tonic-gate
1260*0Sstevel@tonic-gate default:
1261*0Sstevel@tonic-gate dip = hal->halinfo.dip;
1262*0Sstevel@tonic-gate
1263*0Sstevel@tonic-gate /* An unexpected error in the HAL */
1264*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
1265*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
1266*0Sstevel@tonic-gate
1267*0Sstevel@tonic-gate /* Unlock the "used" tree */
1268*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1269*0Sstevel@tonic-gate
1270*0Sstevel@tonic-gate /* Disable the HAL */
1271*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
1272*0Sstevel@tonic-gate
1273*0Sstevel@tonic-gate TNF_PROBE_1(h1394_write_request_error,
1274*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string, msg,
1275*0Sstevel@tonic-gate "Invalid command type specified");
1276*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_exit,
1277*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1278*0Sstevel@tonic-gate return;
1279*0Sstevel@tonic-gate }
1280*0Sstevel@tonic-gate }
1281*0Sstevel@tonic-gate
1282*0Sstevel@tonic-gate /* Fill in the rest of the info in the request */
1283*0Sstevel@tonic-gate if (addr_blk->addr_type == T1394_ADDR_POSTED_WRITE)
1284*0Sstevel@tonic-gate s_priv->posted_write = B_TRUE;
1285*0Sstevel@tonic-gate
1286*0Sstevel@tonic-gate s_priv->arreq_valid_addr = B_TRUE;
1287*0Sstevel@tonic-gate req->cmd_callback_arg = addr_blk->addr_arg;
1288*0Sstevel@tonic-gate recv_write_req = addr_blk->addr_events.recv_write_request;
1289*0Sstevel@tonic-gate
1290*0Sstevel@tonic-gate /* Unlock the "used" tree */
1291*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1292*0Sstevel@tonic-gate
1293*0Sstevel@tonic-gate /*
1294*0Sstevel@tonic-gate * Add no code that modifies the command after the target
1295*0Sstevel@tonic-gate * callback is called or after the response is sent to the
1296*0Sstevel@tonic-gate * HAL.
1297*0Sstevel@tonic-gate */
1298*0Sstevel@tonic-gate if (recv_write_req != NULL) {
1299*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_do_callback,
1300*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1301*0Sstevel@tonic-gate recv_write_req(req);
1302*0Sstevel@tonic-gate } else {
1303*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
1304*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1305*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_exit,
1306*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1307*0Sstevel@tonic-gate return;
1308*0Sstevel@tonic-gate }
1309*0Sstevel@tonic-gate
1310*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_write_request_exit,
1311*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1312*0Sstevel@tonic-gate }
1313*0Sstevel@tonic-gate
1314*0Sstevel@tonic-gate /*
1315*0Sstevel@tonic-gate * Function: h1394_lock_request()
1316*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
1317*0Sstevel@tonic-gate * h1394_attach()
1318*0Sstevel@tonic-gate * req The incoming AR request
1319*0Sstevel@tonic-gate *
1320*0Sstevel@tonic-gate * Output(s): None
1321*0Sstevel@tonic-gate *
1322*0Sstevel@tonic-gate * Description: h1394_lock_request() receives incoming AR requests. These
1323*0Sstevel@tonic-gate * asynchronous lock requests are dispatched to the appropriate
1324*0Sstevel@tonic-gate * target (if one has registered) or are handled by the 1394
1325*0Sstevel@tonic-gate * Software Framework, which will send out an appropriate
1326*0Sstevel@tonic-gate * response.
1327*0Sstevel@tonic-gate */
1328*0Sstevel@tonic-gate void
h1394_lock_request(void * sl_private,cmd1394_cmd_t * req)1329*0Sstevel@tonic-gate h1394_lock_request(void *sl_private, cmd1394_cmd_t *req)
1330*0Sstevel@tonic-gate {
1331*0Sstevel@tonic-gate s1394_hal_t *hal;
1332*0Sstevel@tonic-gate s1394_cmd_priv_t *s_priv;
1333*0Sstevel@tonic-gate s1394_addr_space_blk_t *addr_blk;
1334*0Sstevel@tonic-gate dev_info_t *dip;
1335*0Sstevel@tonic-gate uint64_t end_of_request;
1336*0Sstevel@tonic-gate uint32_t offset;
1337*0Sstevel@tonic-gate uchar_t *bufp_addr;
1338*0Sstevel@tonic-gate cmd1394_lock_type_t lock_type;
1339*0Sstevel@tonic-gate void (*recv_lock_req)(cmd1394_cmd_t *);
1340*0Sstevel@tonic-gate
1341*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_enter,
1342*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1343*0Sstevel@tonic-gate
1344*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
1345*0Sstevel@tonic-gate
1346*0Sstevel@tonic-gate /* Get the Services Layer private area */
1347*0Sstevel@tonic-gate s_priv = S1394_GET_CMD_PRIV(req);
1348*0Sstevel@tonic-gate
1349*0Sstevel@tonic-gate s_priv->cmd_priv_xfer_type = S1394_CMD_LOCK;
1350*0Sstevel@tonic-gate
1351*0Sstevel@tonic-gate /* Lock the "used" tree */
1352*0Sstevel@tonic-gate mutex_enter(&hal->addr_space_used_mutex);
1353*0Sstevel@tonic-gate
1354*0Sstevel@tonic-gate /* Has the 1394 address been allocated? */
1355*0Sstevel@tonic-gate addr_blk = s1394_used_tree_search(hal, req->cmd_addr);
1356*0Sstevel@tonic-gate
1357*0Sstevel@tonic-gate /* If it wasn't found, it isn't owned... */
1358*0Sstevel@tonic-gate if (addr_blk == NULL) {
1359*0Sstevel@tonic-gate /* Unlock the "used" tree */
1360*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1361*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
1362*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1363*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1364*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1365*0Sstevel@tonic-gate return;
1366*0Sstevel@tonic-gate }
1367*0Sstevel@tonic-gate
1368*0Sstevel@tonic-gate /* Does the WHOLE request fit in the allocated block? */
1369*0Sstevel@tonic-gate switch (req->cmd_type) {
1370*0Sstevel@tonic-gate case CMD1394_ASYNCH_LOCK_32:
1371*0Sstevel@tonic-gate end_of_request = (req->cmd_addr + IEEE1394_QUADLET) - 1;
1372*0Sstevel@tonic-gate /* kstats - 32-bit lock request */
1373*0Sstevel@tonic-gate hal->hal_kstats->arreq_lock32++;
1374*0Sstevel@tonic-gate break;
1375*0Sstevel@tonic-gate
1376*0Sstevel@tonic-gate case CMD1394_ASYNCH_LOCK_64:
1377*0Sstevel@tonic-gate end_of_request = (req->cmd_addr + IEEE1394_OCTLET) - 1;
1378*0Sstevel@tonic-gate /* kstats - 64-bit lock request */
1379*0Sstevel@tonic-gate hal->hal_kstats->arreq_lock64++;
1380*0Sstevel@tonic-gate break;
1381*0Sstevel@tonic-gate
1382*0Sstevel@tonic-gate default:
1383*0Sstevel@tonic-gate /* Unlock the "used" tree */
1384*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1385*0Sstevel@tonic-gate
1386*0Sstevel@tonic-gate dip = hal->halinfo.dip;
1387*0Sstevel@tonic-gate
1388*0Sstevel@tonic-gate /* An unexpected error in the HAL */
1389*0Sstevel@tonic-gate cmn_err(CE_WARN, HALT_ERROR_MESSAGE,
1390*0Sstevel@tonic-gate ddi_node_name(dip), ddi_get_instance(dip));
1391*0Sstevel@tonic-gate
1392*0Sstevel@tonic-gate /* Disable the HAL */
1393*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_TRUE);
1394*0Sstevel@tonic-gate
1395*0Sstevel@tonic-gate TNF_PROBE_1(h1394_lock_request_error,
1396*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string, msg,
1397*0Sstevel@tonic-gate "Invalid command type specified");
1398*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1399*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1400*0Sstevel@tonic-gate return;
1401*0Sstevel@tonic-gate }
1402*0Sstevel@tonic-gate
1403*0Sstevel@tonic-gate if (end_of_request > addr_blk->addr_hi) {
1404*0Sstevel@tonic-gate /* Unlock the "used" tree */
1405*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1406*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
1407*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1408*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1409*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1410*0Sstevel@tonic-gate return;
1411*0Sstevel@tonic-gate }
1412*0Sstevel@tonic-gate
1413*0Sstevel@tonic-gate /* Is a lock request valid for this address space? */
1414*0Sstevel@tonic-gate if (!(addr_blk->addr_enable & T1394_ADDR_LKENBL)) {
1415*0Sstevel@tonic-gate /* Unlock the "used" tree */
1416*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1417*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
1418*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1419*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1420*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1421*0Sstevel@tonic-gate return;
1422*0Sstevel@tonic-gate }
1423*0Sstevel@tonic-gate
1424*0Sstevel@tonic-gate /* Fill in the backing store if necessary */
1425*0Sstevel@tonic-gate if (addr_blk->kmem_bufp != NULL) {
1426*0Sstevel@tonic-gate offset = req->cmd_addr - addr_blk->addr_lo;
1427*0Sstevel@tonic-gate bufp_addr = (uchar_t *)addr_blk->kmem_bufp + offset;
1428*0Sstevel@tonic-gate
1429*0Sstevel@tonic-gate if (req->cmd_type == CMD1394_ASYNCH_LOCK_32) {
1430*0Sstevel@tonic-gate uint32_t old_value;
1431*0Sstevel@tonic-gate uint32_t arg_value;
1432*0Sstevel@tonic-gate uint32_t data_value;
1433*0Sstevel@tonic-gate uint32_t new_value;
1434*0Sstevel@tonic-gate
1435*0Sstevel@tonic-gate arg_value = req->cmd_u.l32.arg_value;
1436*0Sstevel@tonic-gate data_value = req->cmd_u.l32.data_value;
1437*0Sstevel@tonic-gate lock_type = req->cmd_u.l32.lock_type;
1438*0Sstevel@tonic-gate bcopy((void *)bufp_addr, (void *)&old_value,
1439*0Sstevel@tonic-gate IEEE1394_QUADLET);
1440*0Sstevel@tonic-gate
1441*0Sstevel@tonic-gate switch (lock_type) {
1442*0Sstevel@tonic-gate case CMD1394_LOCK_MASK_SWAP:
1443*0Sstevel@tonic-gate /* Mask-Swap (see P1394A - Table 1.7) */
1444*0Sstevel@tonic-gate new_value = (data_value & arg_value) |
1445*0Sstevel@tonic-gate (old_value & ~arg_value);
1446*0Sstevel@tonic-gate /* Copy new_value into backing store */
1447*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1448*0Sstevel@tonic-gate IEEE1394_QUADLET);
1449*0Sstevel@tonic-gate req->cmd_u.l32.old_value = old_value;
1450*0Sstevel@tonic-gate break;
1451*0Sstevel@tonic-gate
1452*0Sstevel@tonic-gate case CMD1394_LOCK_COMPARE_SWAP:
1453*0Sstevel@tonic-gate /* Compare-Swap */
1454*0Sstevel@tonic-gate if (old_value == arg_value) {
1455*0Sstevel@tonic-gate new_value = data_value;
1456*0Sstevel@tonic-gate /* Copy new_value into backing store */
1457*0Sstevel@tonic-gate bcopy((void *)&new_value,
1458*0Sstevel@tonic-gate (void *)bufp_addr,
1459*0Sstevel@tonic-gate IEEE1394_QUADLET);
1460*0Sstevel@tonic-gate }
1461*0Sstevel@tonic-gate req->cmd_u.l32.old_value = old_value;
1462*0Sstevel@tonic-gate break;
1463*0Sstevel@tonic-gate
1464*0Sstevel@tonic-gate case CMD1394_LOCK_FETCH_ADD:
1465*0Sstevel@tonic-gate /* Fetch-Add (see P1394A - Table 1.7) */
1466*0Sstevel@tonic-gate old_value = T1394_DATA32(old_value);
1467*0Sstevel@tonic-gate new_value = old_value + data_value;
1468*0Sstevel@tonic-gate new_value = T1394_DATA32(new_value);
1469*0Sstevel@tonic-gate /* Copy new_value into backing store */
1470*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1471*0Sstevel@tonic-gate IEEE1394_QUADLET);
1472*0Sstevel@tonic-gate req->cmd_u.l32.old_value = old_value;
1473*0Sstevel@tonic-gate break;
1474*0Sstevel@tonic-gate
1475*0Sstevel@tonic-gate case CMD1394_LOCK_LITTLE_ADD:
1476*0Sstevel@tonic-gate /* Little-Add (see P1394A - Table 1.7) */
1477*0Sstevel@tonic-gate old_value = T1394_DATA32(old_value);
1478*0Sstevel@tonic-gate new_value = old_value + data_value;
1479*0Sstevel@tonic-gate new_value = T1394_DATA32(new_value);
1480*0Sstevel@tonic-gate /* Copy new_value into backing store */
1481*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1482*0Sstevel@tonic-gate IEEE1394_QUADLET);
1483*0Sstevel@tonic-gate req->cmd_u.l32.old_value = old_value;
1484*0Sstevel@tonic-gate break;
1485*0Sstevel@tonic-gate
1486*0Sstevel@tonic-gate case CMD1394_LOCK_BOUNDED_ADD:
1487*0Sstevel@tonic-gate /* Bounded-Add (see P1394A - Table 1.7) */
1488*0Sstevel@tonic-gate old_value = T1394_DATA32(old_value);
1489*0Sstevel@tonic-gate if (old_value != arg_value) {
1490*0Sstevel@tonic-gate new_value = old_value + data_value;
1491*0Sstevel@tonic-gate new_value = T1394_DATA32(new_value);
1492*0Sstevel@tonic-gate /* Copy new_value into backing store */
1493*0Sstevel@tonic-gate bcopy((void *)&new_value,
1494*0Sstevel@tonic-gate (void *)bufp_addr,
1495*0Sstevel@tonic-gate IEEE1394_QUADLET);
1496*0Sstevel@tonic-gate }
1497*0Sstevel@tonic-gate req->cmd_u.l32.old_value = old_value;
1498*0Sstevel@tonic-gate break;
1499*0Sstevel@tonic-gate
1500*0Sstevel@tonic-gate case CMD1394_LOCK_WRAP_ADD:
1501*0Sstevel@tonic-gate /* Wrap-Add (see P1394A - Table 1.7) */
1502*0Sstevel@tonic-gate old_value = T1394_DATA32(old_value);
1503*0Sstevel@tonic-gate if (old_value != arg_value) {
1504*0Sstevel@tonic-gate new_value = old_value + data_value;
1505*0Sstevel@tonic-gate } else {
1506*0Sstevel@tonic-gate new_value = data_value;
1507*0Sstevel@tonic-gate }
1508*0Sstevel@tonic-gate new_value = T1394_DATA32(new_value);
1509*0Sstevel@tonic-gate /* Copy new_value into backing store */
1510*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1511*0Sstevel@tonic-gate IEEE1394_QUADLET);
1512*0Sstevel@tonic-gate req->cmd_u.l32.old_value = old_value;
1513*0Sstevel@tonic-gate break;
1514*0Sstevel@tonic-gate
1515*0Sstevel@tonic-gate default:
1516*0Sstevel@tonic-gate /* Unlock the "used" tree */
1517*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1518*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
1519*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1520*0Sstevel@tonic-gate TNF_PROBE_1(h1394_lock_request_error,
1521*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string,
1522*0Sstevel@tonic-gate msg, "Invalid lock_type");
1523*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1524*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1525*0Sstevel@tonic-gate return;
1526*0Sstevel@tonic-gate }
1527*0Sstevel@tonic-gate } else {
1528*0Sstevel@tonic-gate /* Handling for the 8-byte (64-bit) lock requests */
1529*0Sstevel@tonic-gate uint64_t old_value;
1530*0Sstevel@tonic-gate uint64_t arg_value;
1531*0Sstevel@tonic-gate uint64_t data_value;
1532*0Sstevel@tonic-gate uint64_t new_value;
1533*0Sstevel@tonic-gate
1534*0Sstevel@tonic-gate arg_value = req->cmd_u.l64.arg_value;
1535*0Sstevel@tonic-gate data_value = req->cmd_u.l64.data_value;
1536*0Sstevel@tonic-gate lock_type = req->cmd_u.l64.lock_type;
1537*0Sstevel@tonic-gate bcopy((void *)bufp_addr, (void *)&old_value,
1538*0Sstevel@tonic-gate IEEE1394_OCTLET);
1539*0Sstevel@tonic-gate
1540*0Sstevel@tonic-gate switch (lock_type) {
1541*0Sstevel@tonic-gate case CMD1394_LOCK_MASK_SWAP:
1542*0Sstevel@tonic-gate /* Mask-Swap (see P1394A - Table 1.7) */
1543*0Sstevel@tonic-gate new_value = (data_value & arg_value) |
1544*0Sstevel@tonic-gate (old_value & ~arg_value);
1545*0Sstevel@tonic-gate /* Copy new_value into backing store */
1546*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1547*0Sstevel@tonic-gate IEEE1394_OCTLET);
1548*0Sstevel@tonic-gate req->cmd_u.l64.old_value = old_value;
1549*0Sstevel@tonic-gate break;
1550*0Sstevel@tonic-gate
1551*0Sstevel@tonic-gate case CMD1394_LOCK_COMPARE_SWAP:
1552*0Sstevel@tonic-gate /* Compare-Swap */
1553*0Sstevel@tonic-gate if (old_value == arg_value) {
1554*0Sstevel@tonic-gate new_value = data_value;
1555*0Sstevel@tonic-gate /* Copy new_value into backing store */
1556*0Sstevel@tonic-gate bcopy((void *)&new_value,
1557*0Sstevel@tonic-gate (void *)bufp_addr,
1558*0Sstevel@tonic-gate IEEE1394_OCTLET);
1559*0Sstevel@tonic-gate }
1560*0Sstevel@tonic-gate req->cmd_u.l64.old_value = old_value;
1561*0Sstevel@tonic-gate break;
1562*0Sstevel@tonic-gate
1563*0Sstevel@tonic-gate case CMD1394_LOCK_FETCH_ADD:
1564*0Sstevel@tonic-gate /* Fetch-Add (see P1394A - Table 1.7) */
1565*0Sstevel@tonic-gate old_value = T1394_DATA64(old_value);
1566*0Sstevel@tonic-gate new_value = old_value + data_value;
1567*0Sstevel@tonic-gate new_value = T1394_DATA64(new_value);
1568*0Sstevel@tonic-gate /* Copy new_value into backing store */
1569*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1570*0Sstevel@tonic-gate IEEE1394_OCTLET);
1571*0Sstevel@tonic-gate req->cmd_u.l64.old_value = old_value;
1572*0Sstevel@tonic-gate break;
1573*0Sstevel@tonic-gate
1574*0Sstevel@tonic-gate case CMD1394_LOCK_LITTLE_ADD:
1575*0Sstevel@tonic-gate /* Little-Add (see P1394A - Table 1.7) */
1576*0Sstevel@tonic-gate old_value = T1394_DATA64(old_value);
1577*0Sstevel@tonic-gate new_value = old_value + data_value;
1578*0Sstevel@tonic-gate new_value = T1394_DATA64(new_value);
1579*0Sstevel@tonic-gate /* Copy new_value into backing store */
1580*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1581*0Sstevel@tonic-gate IEEE1394_OCTLET);
1582*0Sstevel@tonic-gate req->cmd_u.l64.old_value = old_value;
1583*0Sstevel@tonic-gate break;
1584*0Sstevel@tonic-gate
1585*0Sstevel@tonic-gate case CMD1394_LOCK_BOUNDED_ADD:
1586*0Sstevel@tonic-gate /* Bounded-Add (see P1394A - Table 1.7) */
1587*0Sstevel@tonic-gate old_value = T1394_DATA64(old_value);
1588*0Sstevel@tonic-gate if (old_value != arg_value) {
1589*0Sstevel@tonic-gate new_value = old_value + data_value;
1590*0Sstevel@tonic-gate new_value = T1394_DATA64(new_value);
1591*0Sstevel@tonic-gate /* Copy new_value into backing store */
1592*0Sstevel@tonic-gate bcopy((void *)&new_value,
1593*0Sstevel@tonic-gate (void *)bufp_addr,
1594*0Sstevel@tonic-gate IEEE1394_OCTLET);
1595*0Sstevel@tonic-gate }
1596*0Sstevel@tonic-gate req->cmd_u.l64.old_value = old_value;
1597*0Sstevel@tonic-gate break;
1598*0Sstevel@tonic-gate
1599*0Sstevel@tonic-gate case CMD1394_LOCK_WRAP_ADD:
1600*0Sstevel@tonic-gate /* Wrap-Add (see P1394A - Table 1.7) */
1601*0Sstevel@tonic-gate old_value = T1394_DATA64(old_value);
1602*0Sstevel@tonic-gate if (old_value != arg_value) {
1603*0Sstevel@tonic-gate new_value = old_value + data_value;
1604*0Sstevel@tonic-gate } else {
1605*0Sstevel@tonic-gate new_value = data_value;
1606*0Sstevel@tonic-gate }
1607*0Sstevel@tonic-gate new_value = T1394_DATA64(new_value);
1608*0Sstevel@tonic-gate /* Copy new_value into backing store */
1609*0Sstevel@tonic-gate bcopy((void *)&new_value, (void *)bufp_addr,
1610*0Sstevel@tonic-gate IEEE1394_OCTLET);
1611*0Sstevel@tonic-gate req->cmd_u.l64.old_value = old_value;
1612*0Sstevel@tonic-gate break;
1613*0Sstevel@tonic-gate
1614*0Sstevel@tonic-gate default:
1615*0Sstevel@tonic-gate /* Unlock the "used" tree */
1616*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1617*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
1618*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1619*0Sstevel@tonic-gate TNF_PROBE_1(h1394_lock_request_error,
1620*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_ERROR, "", tnf_string,
1621*0Sstevel@tonic-gate msg, "Invalid lock_type");
1622*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1623*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1624*0Sstevel@tonic-gate return;
1625*0Sstevel@tonic-gate }
1626*0Sstevel@tonic-gate }
1627*0Sstevel@tonic-gate }
1628*0Sstevel@tonic-gate
1629*0Sstevel@tonic-gate /* Fill in the rest of the info in the request */
1630*0Sstevel@tonic-gate s_priv->arreq_valid_addr = B_TRUE;
1631*0Sstevel@tonic-gate req->cmd_callback_arg = addr_blk->addr_arg;
1632*0Sstevel@tonic-gate recv_lock_req = addr_blk->addr_events.recv_lock_request;
1633*0Sstevel@tonic-gate
1634*0Sstevel@tonic-gate /* Unlock the "used" tree */
1635*0Sstevel@tonic-gate mutex_exit(&hal->addr_space_used_mutex);
1636*0Sstevel@tonic-gate
1637*0Sstevel@tonic-gate /*
1638*0Sstevel@tonic-gate * Add no code that modifies the command after the target
1639*0Sstevel@tonic-gate * callback is called or after the response is sent to the
1640*0Sstevel@tonic-gate * HAL.
1641*0Sstevel@tonic-gate */
1642*0Sstevel@tonic-gate if (recv_lock_req != NULL) {
1643*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_do_callback,
1644*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1645*0Sstevel@tonic-gate recv_lock_req(req);
1646*0Sstevel@tonic-gate } else {
1647*0Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
1648*0Sstevel@tonic-gate (void) s1394_send_response(hal, req);
1649*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1650*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1651*0Sstevel@tonic-gate return;
1652*0Sstevel@tonic-gate }
1653*0Sstevel@tonic-gate
1654*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_lock_request_exit,
1655*0Sstevel@tonic-gate S1394_TNF_SL_ARREQ_STACK, "");
1656*0Sstevel@tonic-gate }
1657*0Sstevel@tonic-gate
1658*0Sstevel@tonic-gate /*
1659*0Sstevel@tonic-gate * Function: h1394_ioctl()
1660*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
1661*0Sstevel@tonic-gate * h1394_attach()
1662*0Sstevel@tonic-gate * cmd ioctl cmd
1663*0Sstevel@tonic-gate * arg argument for the ioctl cmd
1664*0Sstevel@tonic-gate * mode mode bits (see ioctl(9e))
1665*0Sstevel@tonic-gate * cred_p cred structure pointer
1666*0Sstevel@tonic-gate * rval_p pointer to return value (see ioctl(9e))
1667*0Sstevel@tonic-gate *
1668*0Sstevel@tonic-gate * Output(s): EINVAL if not a DEVCTL ioctl, else return value from s1394_ioctl
1669*0Sstevel@tonic-gate *
1670*0Sstevel@tonic-gate * Description: h1394_ioctl() implements non-HAL specific ioctls. Currently,
1671*0Sstevel@tonic-gate * DEVCTL ioctls are the only generic ioctls supported.
1672*0Sstevel@tonic-gate */
1673*0Sstevel@tonic-gate int
h1394_ioctl(void * sl_private,int cmd,intptr_t arg,int mode,cred_t * cred_p,int * rval_p)1674*0Sstevel@tonic-gate h1394_ioctl(void *sl_private, int cmd, intptr_t arg, int mode, cred_t *cred_p,
1675*0Sstevel@tonic-gate int *rval_p)
1676*0Sstevel@tonic-gate {
1677*0Sstevel@tonic-gate int status;
1678*0Sstevel@tonic-gate
1679*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_ioctl_enter, S1394_TNF_SL_IOCTL_STACK, "");
1680*0Sstevel@tonic-gate
1681*0Sstevel@tonic-gate if ((cmd & DEVCTL_IOC) != DEVCTL_IOC)
1682*0Sstevel@tonic-gate return (EINVAL);
1683*0Sstevel@tonic-gate
1684*0Sstevel@tonic-gate status = s1394_ioctl((s1394_hal_t *)sl_private, cmd, arg, mode,
1685*0Sstevel@tonic-gate cred_p, rval_p);
1686*0Sstevel@tonic-gate
1687*0Sstevel@tonic-gate TNF_PROBE_1_DEBUG(h1394_ioctl_exit, S1394_TNF_SL_IOCTL_STACK, "",
1688*0Sstevel@tonic-gate tnf_int, status, status);
1689*0Sstevel@tonic-gate return (status);
1690*0Sstevel@tonic-gate }
1691*0Sstevel@tonic-gate
1692*0Sstevel@tonic-gate /*
1693*0Sstevel@tonic-gate * Function: h1394_phy_packet()
1694*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
1695*0Sstevel@tonic-gate * h1394_attach()
1696*0Sstevel@tonic-gate * packet_data Pointer to a buffer of packet data
1697*0Sstevel@tonic-gate * quadlet_count Length of the buffer
1698*0Sstevel@tonic-gate * timestamp Timestamp indicating time of arrival
1699*0Sstevel@tonic-gate *
1700*0Sstevel@tonic-gate * Output(s): None
1701*0Sstevel@tonic-gate *
1702*0Sstevel@tonic-gate * Description: h1394_phy_packet() is not implemented currently, but would
1703*0Sstevel@tonic-gate * be used to process the responses to PHY ping packets in P1394A
1704*0Sstevel@tonic-gate * When one is sent out, a timestamp is given indicating its time
1705*0Sstevel@tonic-gate * of departure. Comparing that old timestamp with this new
1706*0Sstevel@tonic-gate * timestamp, we can determine the time of flight and can use
1707*0Sstevel@tonic-gate * those times to optimize the gap count.
1708*0Sstevel@tonic-gate */
1709*0Sstevel@tonic-gate /* ARGSUSED */
1710*0Sstevel@tonic-gate void
h1394_phy_packet(void * sl_private,uint32_t * packet_data,uint_t quadlet_count,uint_t timestamp)1711*0Sstevel@tonic-gate h1394_phy_packet(void *sl_private, uint32_t *packet_data, uint_t quadlet_count,
1712*0Sstevel@tonic-gate uint_t timestamp)
1713*0Sstevel@tonic-gate {
1714*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_phy_packet_enter, S1394_TNF_SL_STACK, "");
1715*0Sstevel@tonic-gate
1716*0Sstevel@tonic-gate /* This interface is not yet implemented */
1717*0Sstevel@tonic-gate TNF_PROBE_1_DEBUG(h1394_phy_packet, S1394_TNF_SL_STACK, "",
1718*0Sstevel@tonic-gate tnf_string, msg, "h1394_phy_packet: Received");
1719*0Sstevel@tonic-gate
1720*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_phy_packet_exit, S1394_TNF_SL_STACK, "");
1721*0Sstevel@tonic-gate }
1722*0Sstevel@tonic-gate
1723*0Sstevel@tonic-gate /*
1724*0Sstevel@tonic-gate * Function: h1394_error_detected()
1725*0Sstevel@tonic-gate * Input(s): sl_private The HAL "handle" returned by
1726*0Sstevel@tonic-gate * h1394_attach()
1727*0Sstevel@tonic-gate * type The type of error the HAL detected
1728*0Sstevel@tonic-gate * arg Pointer to any extra information
1729*0Sstevel@tonic-gate *
1730*0Sstevel@tonic-gate * Output(s): None
1731*0Sstevel@tonic-gate *
1732*0Sstevel@tonic-gate * Description: h1394_error_detected() is used by the HAL to report errors
1733*0Sstevel@tonic-gate * to the 1394 Software Framework.
1734*0Sstevel@tonic-gate */
1735*0Sstevel@tonic-gate void
h1394_error_detected(void * sl_private,h1394_error_t type,void * arg)1736*0Sstevel@tonic-gate h1394_error_detected(void *sl_private, h1394_error_t type, void *arg)
1737*0Sstevel@tonic-gate {
1738*0Sstevel@tonic-gate s1394_hal_t *hal;
1739*0Sstevel@tonic-gate uint_t hal_node_num;
1740*0Sstevel@tonic-gate uint_t IRM_node_num;
1741*0Sstevel@tonic-gate
1742*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_error_detected_enter, S1394_TNF_SL_STACK, "");
1743*0Sstevel@tonic-gate
1744*0Sstevel@tonic-gate hal = (s1394_hal_t *)sl_private;
1745*0Sstevel@tonic-gate
1746*0Sstevel@tonic-gate switch (type) {
1747*0Sstevel@tonic-gate case H1394_LOCK_RESP_ERR:
1748*0Sstevel@tonic-gate TNF_PROBE_1(h1394_error_detected, S1394_TNF_SL_ERROR, "",
1749*0Sstevel@tonic-gate tnf_string, msg, "Lock response error");
1750*0Sstevel@tonic-gate /* If we are the IRM, then initiate a bus reset */
1751*0Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
1752*0Sstevel@tonic-gate hal_node_num = IEEE1394_NODE_NUM(hal->node_id);
1753*0Sstevel@tonic-gate IRM_node_num = hal->IRM_node;
1754*0Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
1755*0Sstevel@tonic-gate if (IRM_node_num == hal_node_num)
1756*0Sstevel@tonic-gate s1394_initiate_hal_reset(hal, NON_CRITICAL);
1757*0Sstevel@tonic-gate break;
1758*0Sstevel@tonic-gate
1759*0Sstevel@tonic-gate case H1394_POSTED_WR_ERR:
1760*0Sstevel@tonic-gate TNF_PROBE_2(h1394_error_detected, S1394_TNF_SL_ERROR, "",
1761*0Sstevel@tonic-gate tnf_string, msg, "Posted write error detected",
1762*0Sstevel@tonic-gate tnf_opaque, addr, ((h1394_posted_wr_err_t *)arg)->addr);
1763*0Sstevel@tonic-gate break;
1764*0Sstevel@tonic-gate
1765*0Sstevel@tonic-gate case H1394_SELF_INITIATED_SHUTDOWN:
1766*0Sstevel@tonic-gate TNF_PROBE_1(h1394_error_detected, S1394_TNF_SL_ERROR, "",
1767*0Sstevel@tonic-gate tnf_string, msg, "HAL self-initiated shutdown");
1768*0Sstevel@tonic-gate s1394_hal_shutdown(hal, B_FALSE);
1769*0Sstevel@tonic-gate break;
1770*0Sstevel@tonic-gate
1771*0Sstevel@tonic-gate case H1394_CYCLE_TOO_LONG:
1772*0Sstevel@tonic-gate /* Set a timer to become cycle master after 1 second */
1773*0Sstevel@tonic-gate mutex_enter(&hal->cm_timer_mutex);
1774*0Sstevel@tonic-gate hal->cm_timer_set = B_TRUE;
1775*0Sstevel@tonic-gate mutex_exit(&hal->cm_timer_mutex);
1776*0Sstevel@tonic-gate hal->cm_timer = timeout(s1394_cycle_too_long_callback, hal,
1777*0Sstevel@tonic-gate drv_usectohz(CYCLE_MASTER_TIMER * 1000));
1778*0Sstevel@tonic-gate
1779*0Sstevel@tonic-gate TNF_PROBE_1(h1394_error_detected, S1394_TNF_SL_ERROR, "",
1780*0Sstevel@tonic-gate tnf_string, msg, "Isochronous cycle too long error");
1781*0Sstevel@tonic-gate break;
1782*0Sstevel@tonic-gate
1783*0Sstevel@tonic-gate default:
1784*0Sstevel@tonic-gate TNF_PROBE_2(h1394_error_detected, S1394_TNF_SL_ERROR, "",
1785*0Sstevel@tonic-gate tnf_string, msg, "Unknown error type received",
1786*0Sstevel@tonic-gate tnf_uint, type, type);
1787*0Sstevel@tonic-gate break;
1788*0Sstevel@tonic-gate }
1789*0Sstevel@tonic-gate
1790*0Sstevel@tonic-gate TNF_PROBE_0_DEBUG(h1394_error_detected_exit, S1394_TNF_SL_STACK, "");
1791*0Sstevel@tonic-gate }
1792