Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / 1394 / adapters / hci1394_csr.c
blob95e859cbc8c93ad304a682f79b3d28f16e4ab914
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * hci1394_csr.c
31 * This code contains the code for the CSR registers handled by the HAL in
32 * SW. The HW implemented CSR registers are in hci1394_ohci.c
34 * For more information on CSR registers, see
35 * IEEE 1212
36 * IEEE 1394-1995
37 * section 8.3.2
38 * IEEE P1394A Draft 3.0
39 * sections 10.32,10.33
41 * NOTE: A read/write to a CSR SW based register will first go to the Services
42 * Layer which will do some filtering and then come through the s1394if. Look
43 * in hci1394_s1394if.c to see which registers are implemented in HW and
44 * which are implemented in SW.
47 #include <sys/conf.h>
48 #include <sys/ddi.h>
49 #include <sys/modctl.h>
50 #include <sys/stat.h>
51 #include <sys/sunddi.h>
52 #include <sys/cmn_err.h>
53 #include <sys/kmem.h>
54 #include <sys/types.h>
56 #include <sys/1394/adapters/hci1394.h>
57 #include <sys/1394/adapters/hci1394_extern.h>
61 * The split_timeout_lo register cannot be set below 800 and above 7999. The
62 * split_timeout_hi register cannot be set above 7.
64 #define CSR_MIN_SPLIT_TIMEOUT_LO 800
65 #define CSR_MAX_SPLIT_TIMEOUT_LO 7999
66 #define CSR_MAX_SPLIT_TIMEOUT_HI 7
69 * We will convert the split_timeout_lo to return the data in most significant
70 * 13 bits on the fly.
72 #define CSR_SPLIT_TIMEOUT_LO_SHIFT 19
75 * This is what we report to the services layer as our node capabilities.
76 * See IEEE 1212_1994, section 8.4.11
78 * Split Timeout Registers are implemented (bit 15)
79 * This node uses 64-bit addressing (bit 9)
80 * This node uses fixed addressing scheme (bit 8)
81 * STATE_BITS.lost is implemented
82 * STATE_BITS.dreq is implemented
84 #define CSR_INITIAL_NODE_CAPABILITIES 0x000083C0
87 * macro to calculate split_timeout based on split_timeout_lo and
88 * split_timeout_hi
90 #define CSR_SPLIT_TIMEOUT(split_hi, split_lo) \
91 ((split_hi * IEEE1394_BUS_CYCLES_PER_SEC) + split_lo)
94 static void hci1394_csr_state_init(hci1394_csr_t *csr);
98 * hci1394_csr_init()
99 * Initialize CSR state and CSR SW based registers.
101 void
102 hci1394_csr_init(hci1394_drvinfo_t *drvinfo, hci1394_ohci_handle_t ohci,
103 hci1394_csr_handle_t *csr_handle)
105 hci1394_csr_t *csr;
108 ASSERT(drvinfo != NULL);
109 ASSERT(ohci != NULL);
110 ASSERT(csr_handle != NULL);
112 /* alloc the space to keep track of the csr registers */
113 csr = kmem_alloc(sizeof (hci1394_csr_t), KM_SLEEP);
115 /* setup the return parameter */
116 *csr_handle = csr;
118 /* Initialize the csr structure */
119 csr->csr_drvinfo = drvinfo;
120 csr->csr_ohci = ohci;
121 mutex_init(&csr->csr_mutex, NULL, MUTEX_DRIVER,
122 drvinfo->di_iblock_cookie);
123 hci1394_csr_state_init(csr);
128 * hci1394_csr_fini()
129 * Free up any space allocated and any mutexes used.
131 void
132 hci1394_csr_fini(hci1394_csr_handle_t *csr_handle)
134 hci1394_csr_t *csr;
137 ASSERT(csr_handle != NULL);
139 csr = (hci1394_csr_t *)*csr_handle;
140 mutex_destroy(&csr->csr_mutex);
141 kmem_free(csr, sizeof (hci1394_csr_t));
142 *csr_handle = NULL;
147 * hci1394_csr_resume()
148 * When resuming power on a workstation, re-setup our CSR registers.
150 void
151 hci1394_csr_resume(hci1394_csr_handle_t csr_handle)
153 ASSERT(csr_handle != NULL);
154 hci1394_csr_state_init(csr_handle);
159 * hci1394_csr_node_capabilities()
160 * Return the CSR node capabilities.
162 void
163 hci1394_csr_node_capabilities(hci1394_csr_handle_t csr_handle,
164 uint32_t *capabilities)
166 ASSERT(csr_handle != NULL);
167 ASSERT(capabilities != NULL);
169 mutex_enter(&csr_handle->csr_mutex);
170 *capabilities = csr_handle->csr_capabilities;
171 mutex_exit(&csr_handle->csr_mutex);
176 * hci1394_csr_state_get()
177 * Read the CSR state register. Currently we only support the dreq, cmstr,
178 * and abdicate bits in the CSR state register. See the specs mentioned
179 * above for the behavior of these bits.
181 void
182 hci1394_csr_state_get(hci1394_csr_handle_t csr_handle, uint32_t *state)
184 ASSERT(csr_handle != NULL);
185 ASSERT(state != NULL);
187 mutex_enter(&csr_handle->csr_mutex);
188 *state = csr_handle->csr_state;
189 mutex_exit(&csr_handle->csr_mutex);
194 * hci1394_csr_state_bset()
195 * Perform a bit set on the CSR state register. The value of state will be
196 * or'd with the CSR state register. Currently we only support the dreq,
197 * cmstr, and abdicate bits in the CSR state register. See the specs
198 * mentioned above for the behavior of these bits.
200 void
201 hci1394_csr_state_bset(hci1394_csr_handle_t csr_handle, uint32_t state)
203 uint32_t supported_state;
206 ASSERT(csr_handle != NULL);
208 mutex_enter(&csr_handle->csr_mutex);
210 /* only support dreq, cmstr, and abdicate bits */
211 supported_state = state & (IEEE1394_CSR_STATE_ABDICATE |
212 IEEE1394_CSR_STATE_CMSTR | IEEE1394_CSR_STATE_DREQ);
215 * If we are setting the Cycle Master bit and we are the root node,
216 * enable Cycle Start Packets.
218 if ((supported_state & IEEE1394_CSR_STATE_CMSTR) &&
219 (hci1394_ohci_root_check(csr_handle->csr_ohci))) {
220 hci1394_ohci_cycle_master_enable(csr_handle->csr_ohci);
223 /* set the supported bits in csr_state */
224 csr_handle->csr_state |= supported_state;
226 mutex_exit(&csr_handle->csr_mutex);
231 * hci1394_csr_state_bclr()
232 * Perform a bit clear on the CSR state register. The inverted value of
233 * state will be and'd with CSR state register. Currently we only support
234 * the dreq, cmstr, and abdicate bits in the CSR state register. See the
235 * specs mentioned above for the behavior of these bits.
237 void
238 hci1394_csr_state_bclr(hci1394_csr_handle_t csr_handle, uint32_t state)
240 uint32_t supported_state;
243 ASSERT(csr_handle != NULL);
245 mutex_enter(&csr_handle->csr_mutex);
247 /* only support dreq, cmstr, and abdicate bits */
248 supported_state = state & (IEEE1394_CSR_STATE_ABDICATE |
249 IEEE1394_CSR_STATE_CMSTR | IEEE1394_CSR_STATE_DREQ);
252 * If we are clearing the Cycle Master bit and we are the root node,
253 * disable Cycle Start Packets.
255 if ((supported_state & IEEE1394_CSR_STATE_CMSTR) &&
256 (hci1394_ohci_root_check(csr_handle->csr_ohci))) {
257 hci1394_ohci_cycle_master_disable(csr_handle->csr_ohci);
260 /* Clear the supported bits in csr_state */
261 csr_handle->csr_state &= ~state;
263 mutex_exit(&csr_handle->csr_mutex);
268 * hci1394_csr_split_timeout_hi_get()
269 * Read the CSR split_timeout_hi register.
271 void
272 hci1394_csr_split_timeout_hi_get(hci1394_csr_handle_t csr_handle,
273 uint32_t *split_timeout_hi)
275 ASSERT(csr_handle != NULL);
276 ASSERT(split_timeout_hi != NULL);
278 mutex_enter(&csr_handle->csr_mutex);
279 *split_timeout_hi = csr_handle->csr_split_timeout_hi;
280 mutex_exit(&csr_handle->csr_mutex);
286 * hci1394_csr_split_timeout_lo_get()
287 * Read the CSR split_timeout_lo register.
289 void
290 hci1394_csr_split_timeout_lo_get(hci1394_csr_handle_t csr_handle,
291 uint32_t *split_timeout_lo)
293 ASSERT(csr_handle != NULL);
294 ASSERT(split_timeout_lo != NULL);
296 mutex_enter(&csr_handle->csr_mutex);
299 * Read the split_timeout_lo CSR register. Convert split_timeout_lo to
300 * use the data in most significant 13 bits on the fly.
302 *split_timeout_lo = csr_handle->csr_split_timeout_lo <<
303 CSR_SPLIT_TIMEOUT_LO_SHIFT;
305 mutex_exit(&csr_handle->csr_mutex);
311 * hci1394_csr_split_timeout_hi_set()
312 * Write the CSR split_timeout_hi register. This routine will also
313 * re-calculate the "split_timeout" which is used internally in the HAL
314 * driver. The only accesses to split_timeout_hi and split_timeout_lo
315 * should be over the 1394 bus. Only the least significant 3 bits are
316 * relevant in the split_timeout_hi register.
318 void
319 hci1394_csr_split_timeout_hi_set(hci1394_csr_handle_t csr_handle,
320 uint32_t split_timeout_hi)
322 ASSERT(csr_handle != NULL);
324 mutex_enter(&csr_handle->csr_mutex);
327 * update the split_timeout_hi CSR register. Only look at the 3 LSBits.
328 * Update our internal split_timeout value.
330 csr_handle->csr_split_timeout_hi = split_timeout_hi &
331 CSR_MAX_SPLIT_TIMEOUT_HI;
332 csr_handle->csr_split_timeout = CSR_SPLIT_TIMEOUT(
333 csr_handle->csr_split_timeout_hi, csr_handle->csr_split_timeout_lo);
335 mutex_exit(&csr_handle->csr_mutex);
340 * hci1394_csr_split_timeout_lo_set()
341 * Write the CSR split_timeout_lo register. This routine will also
342 * re-calculate the "split_timeout" which is used internally in the HAL
343 * driver. The only accesses to split_timeout_hi and split_timeout_lo
344 * should be over the 1394 bus. Only the most significant 13 bits are
345 * relevant in the split_timeout_lo register.
347 void
348 hci1394_csr_split_timeout_lo_set(hci1394_csr_handle_t csr_handle,
349 uint32_t split_timeout_lo)
351 ASSERT(csr_handle != NULL);
353 mutex_enter(&csr_handle->csr_mutex);
356 * Update the split_timeout_lo CSR register. Only look at the 3 LSBits.
357 * Convert the split_timeout_lo to use the data in most significant 13
358 * bits on the fly.
360 csr_handle->csr_split_timeout_lo = split_timeout_lo >>
361 CSR_SPLIT_TIMEOUT_LO_SHIFT;
363 /* threshold the split_timeout_lo value */
364 if (csr_handle->csr_split_timeout_lo < CSR_MIN_SPLIT_TIMEOUT_LO) {
365 csr_handle->csr_split_timeout_lo = CSR_MIN_SPLIT_TIMEOUT_LO;
366 } else if (csr_handle->csr_split_timeout_lo >
367 CSR_MAX_SPLIT_TIMEOUT_LO) {
368 csr_handle->csr_split_timeout_lo = CSR_MAX_SPLIT_TIMEOUT_LO;
371 /* Update our internal split_timeout value */
372 csr_handle->csr_split_timeout = CSR_SPLIT_TIMEOUT(
373 csr_handle->csr_split_timeout_hi, csr_handle->csr_split_timeout_lo);
375 mutex_exit(&csr_handle->csr_mutex);
380 * hci1394_csr_split_timeout_get()
381 * Return the current value of split_timeout. This is the only routine
382 * which should be used to get the split timeout for use in a calculation
383 * (e.g. for calculating ACK pending timeout).
385 uint_t
386 hci1394_csr_split_timeout_get(hci1394_csr_handle_t csr_handle)
388 uint_t split_timeout;
391 ASSERT(csr_handle != NULL);
393 mutex_enter(&csr_handle->csr_mutex);
395 /* read our internal split_timeout value */
396 split_timeout = csr_handle->csr_split_timeout;
398 mutex_exit(&csr_handle->csr_mutex);
400 return (split_timeout);
405 * hci1394_csr_bus_reset()
406 * Perform required bus reset processing on CSR registers. This includes
407 * clearing the abdicate bit, and setting/clearing the Cycle Master bit.
408 * See sections 10.32 and 10.33 in the IEEE P1394A Draft 3.0 spec. See
409 * section 8.3.2.2.1 in the IEEE 1394-1995 spec. This routine should be
410 * called every bus reset.
412 void
413 hci1394_csr_bus_reset(hci1394_csr_handle_t csr_handle)
415 ASSERT(csr_handle != NULL);
417 mutex_enter(&csr_handle->csr_mutex);
419 /* Clear the abdicate bit. Always do this. */
420 csr_handle->csr_state &= ~IEEE1394_CSR_STATE_ABDICATE;
422 /* if we are NOT currently the root node on the bus */
423 if (hci1394_ohci_root_check(csr_handle->csr_ohci) == B_FALSE) {
425 * Set the was_root state. This is needed for the Cycle Master
426 * state machine below.
428 csr_handle->csr_was_root = B_FALSE;
431 * Clear the Cycle Master bit. We do not have to shut off cycle
432 * master in OpenHCI. The HW will automatically stop generating
433 * Cycle Start packets when it is not the root node.
435 csr_handle->csr_state &= ~IEEE1394_CSR_STATE_CMSTR;
438 * if we are currently the root node on the bus and we were NOT
439 * the root before the reset.
441 } else if (csr_handle->csr_was_root == B_FALSE) {
443 /* set the was_root state to TRUE */
444 csr_handle->csr_was_root = B_TRUE;
447 * if we are cycle master capable, set the Cycle Master bit and
448 * start Cycle Start packets. We should always be Cycle Master
449 * capable.
451 if (hci1394_ohci_cmc_check(csr_handle->csr_ohci)) {
452 csr_handle->csr_state |= IEEE1394_CSR_STATE_CMSTR;
453 hci1394_ohci_cycle_master_enable(csr_handle->csr_ohci);
456 * if we are NOT cycle master capable, clear the Cycle Master
457 * bit and stop Cycle Start packets. We should never see this
458 * in OpenHCI. I think? :-)
460 } else {
461 csr_handle->csr_state &= ~IEEE1394_CSR_STATE_CMSTR;
462 hci1394_ohci_cycle_master_disable(csr_handle->csr_ohci);
466 * else {}
467 * else we are root now. We were root before, keep cmstr the same.
468 * Nothing to do.
471 mutex_exit(&csr_handle->csr_mutex);
476 * hci1394_csr_state_init()
477 * set the CSR SW registers and state variables to their initial settings.
479 static void hci1394_csr_state_init(hci1394_csr_t *csr)
481 ASSERT(csr != NULL);
483 mutex_enter(&csr->csr_mutex);
486 * Initialize the split timeout to be 0 seconds (split_timeout_hi) and
487 * use a patchable variable for the initial split_timeout_lo. This
488 * variable must be patched before the driver attaches. It is never
489 * looked at again after this code is run.
491 * Calculate the split_timeout which we will use in the driver based on
492 * split_timeout_lo and split_timeout_hi.
494 csr->csr_split_timeout_hi = 0;
495 csr->csr_split_timeout_lo = hci1394_split_timeout;
496 csr->csr_split_timeout = CSR_SPLIT_TIMEOUT(
497 csr->csr_split_timeout_hi, csr->csr_split_timeout_lo);
499 /* Set the initial CSR State register to 0 */
500 csr->csr_state = 0;
503 * was_root is an internal state variable which tracks if we were root
504 * last bus reset. This is needed for the required state register bus
505 * reset processing.
507 csr->csr_was_root = B_FALSE;
509 /* setup our initial capabilities setting */
510 csr->csr_capabilities = CSR_INITIAL_NODE_CAPABILITIES;
512 mutex_exit(&csr->csr_mutex);