17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate * All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * s1394_csr.c
297c478bd9Sstevel@tonic-gate * 1394 Services Layer CSR and Config ROM Routines
307c478bd9Sstevel@tonic-gate * Contains all of the CSR callback routines for various required
317c478bd9Sstevel@tonic-gate * CSR registers. Also contains routines for their initialization
327c478bd9Sstevel@tonic-gate * and destruction, as well as routines to handle the processing
337c478bd9Sstevel@tonic-gate * of Config ROM update requests.
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #include <sys/conf.h>
377c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
387c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
417c478bd9Sstevel@tonic-gate #include <sys/1394/t1394.h>
427c478bd9Sstevel@tonic-gate #include <sys/1394/s1394.h>
437c478bd9Sstevel@tonic-gate #include <sys/1394/h1394.h>
447c478bd9Sstevel@tonic-gate #include <sys/1394/ieee1394.h>
457c478bd9Sstevel@tonic-gate #include <sys/1394/ieee1212.h>
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate static void s1394_CSR_state_clear(cmd1394_cmd_t *req);
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate static void s1394_CSR_state_set(cmd1394_cmd_t *req);
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate static void s1394_CSR_node_ids(cmd1394_cmd_t *req);
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate static void s1394_CSR_reset_start(cmd1394_cmd_t *req);
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate static void s1394_CSR_split_timeout(cmd1394_cmd_t *req);
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate static void s1394_CSR_argument_regs(cmd1394_cmd_t *req);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate static void s1394_CSR_test_regs(cmd1394_cmd_t *req);
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate static void s1394_CSR_interrupt_regs(cmd1394_cmd_t *req);
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate static void s1394_CSR_clock_regs(cmd1394_cmd_t *req);
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate static void s1394_CSR_message_regs(cmd1394_cmd_t *req);
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate static void s1394_CSR_cycle_time(cmd1394_cmd_t *req);
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate static void s1394_CSR_bus_time(cmd1394_cmd_t *req);
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate static void s1394_CSR_busy_timeout(cmd1394_cmd_t *req);
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate static void s1394_CSR_IRM_regs(cmd1394_cmd_t *req);
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate static void s1394_CSR_topology_map(cmd1394_cmd_t *req);
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate static void s1394_common_CSR_routine(s1394_hal_t *hal, cmd1394_cmd_t *req);
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate static int s1394_init_config_rom_structures(s1394_hal_t *hal);
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate static int s1394_destroy_config_rom_structures(s1394_hal_t *hal);
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate * s1394_setup_CSR_space()
857c478bd9Sstevel@tonic-gate * setups up the local host's CSR registers and callback routines.
867c478bd9Sstevel@tonic-gate */
877c478bd9Sstevel@tonic-gate int
s1394_setup_CSR_space(s1394_hal_t * hal)887c478bd9Sstevel@tonic-gate s1394_setup_CSR_space(s1394_hal_t *hal)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate s1394_addr_space_blk_t *curr_blk;
917c478bd9Sstevel@tonic-gate t1394_alloc_addr_t addr;
927c478bd9Sstevel@tonic-gate t1394_addr_enable_t rw_flags;
937c478bd9Sstevel@tonic-gate int result;
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate * Although they are not freed up in this routine, if
977c478bd9Sstevel@tonic-gate * one of the s1394_claim_addr_blk() routines fails,
987c478bd9Sstevel@tonic-gate * all of the previously successful claims will be
997c478bd9Sstevel@tonic-gate * freed up in s1394_destroy_addr_space() upon returning
1007c478bd9Sstevel@tonic-gate * DDI_FAILURE from this routine.
1017c478bd9Sstevel@tonic-gate */
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate rw_flags = T1394_ADDR_RDENBL | T1394_ADDR_WRENBL;
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate * STATE_CLEAR
1077c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.1 or
1087c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.1
1097c478bd9Sstevel@tonic-gate */
1107c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_STATE_CLEAR;
1117c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
1127c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
1137c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
1147c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_state_clear;
1157c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_state_clear;
1167c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
1177c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
1187c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
1197c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
1207c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
1217c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate * STATE_SET
1267c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.2 or
1277c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.2
1287c478bd9Sstevel@tonic-gate */
1297c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_STATE_SET;
1307c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
1317c478bd9Sstevel@tonic-gate addr.aa_enable = T1394_ADDR_WRENBL;
1327c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
1337c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = NULL;
1347c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_state_set;
1357c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
1367c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
1377c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
1387c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
1397c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
1407c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate * NODE_IDS
1457c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.3 or
1467c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.3
1477c478bd9Sstevel@tonic-gate */
1487c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_NODE_IDS;
1497c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
1507c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
1517c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
1527c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_node_ids;
1537c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_node_ids;
1547c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
1557c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
1567c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
1577c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
1587c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
1597c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate * RESET_START
1647c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.4 or
1657c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.4
1667c478bd9Sstevel@tonic-gate */
1677c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_RESET_START;
1687c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
1697c478bd9Sstevel@tonic-gate addr.aa_enable = T1394_ADDR_WRENBL;
1707c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
1717c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = NULL;
1727c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_reset_start;
1737c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
1747c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
1757c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
1767c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
1777c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
1787c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate * SPLIT_TIMEOUT
1837c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.6 or
1847c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.7
1857c478bd9Sstevel@tonic-gate */
1867c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_SPLIT_TIMEOUT_HI;
1877c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_OCTLET;
1887c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
1897c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
1907c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_split_timeout;
1917c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_split_timeout;
1927c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
1937c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
1947c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
1957c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
1967c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
1977c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate * ARGUMENT_HI and ARGUMENT_LO
2027c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.7 or
2037c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.8
2047c478bd9Sstevel@tonic-gate */
2057c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_ARG_HI;
2067c478bd9Sstevel@tonic-gate addr.aa_length = 2 * (IEEE1394_QUADLET);
2077c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
2087c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
2097c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_argument_regs;
2107c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_argument_regs;
2117c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
2127c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
2137c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
2147c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
2157c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
2167c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate * TEST_START and TEST_STATUS
2217c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.7 or
2227c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.9 - 7.4.10
2237c478bd9Sstevel@tonic-gate */
2247c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_TEST_START;
2257c478bd9Sstevel@tonic-gate addr.aa_length = 2 * (IEEE1394_QUADLET);
2267c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
2277c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
2287c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_test_regs;
2297c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_test_regs;
2307c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
2317c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
2327c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
2337c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
2347c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
2357c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate /*
2397c478bd9Sstevel@tonic-gate * INTERRUPT_TARGET and INTERRUPT_MASK
2407c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.9 or
2417c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.15 - 7.4.16
2427c478bd9Sstevel@tonic-gate */
2437c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_INTERRUPT_TARGET;
2447c478bd9Sstevel@tonic-gate addr.aa_length = 2 * (IEEE1394_QUADLET);
2457c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
2467c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
2477c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_interrupt_regs;
2487c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_interrupt_regs;
2497c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
2507c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
2517c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
2527c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
2537c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
2547c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate * CLOCK_VALUE, CLOCK_TICK_PERIOD, CLOCK_INFO, etc.
2597c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.10 or
2607c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.17 - 7.4.20
2617c478bd9Sstevel@tonic-gate */
2627c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_CLOCK_VALUE;
2637c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_CSR_CLOCK_VALUE_SZ;
2647c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
2657c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
2667c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_clock_regs;
2677c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_clock_regs;
2687c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
2697c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
2707c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
2717c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
2727c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
2737c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate * MESSAGE_REQUEST and MESSAGE_RESPONSE
2787c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.2.11 or
2797c478bd9Sstevel@tonic-gate * IEEE 1212-1994, Section 7.4.21
2807c478bd9Sstevel@tonic-gate */
2817c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CSR_MESSAGE_REQUEST;
2827c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_CSR_MESSAGE_REQUEST_SZ;
2837c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
2847c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
2857c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_message_regs;
2867c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_message_regs;
2877c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
2887c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
2897c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
2907c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
2917c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
2927c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate * CYCLE_TIME
2977c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.3.1
2987c478bd9Sstevel@tonic-gate */
2997c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_SCSR_CYCLE_TIME;
3007c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
3017c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
3027c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
3037c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_cycle_time;
3047c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_cycle_time;
3057c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
3067c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
3077c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
3087c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
3097c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
3107c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate * BUS_TIME
3157c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.3.2
3167c478bd9Sstevel@tonic-gate */
3177c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_SCSR_BUS_TIME;
3187c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
3197c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
3207c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
3217c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_bus_time;
3227c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_bus_time;
3237c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
3247c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
3257c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
3267c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
3277c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
3287c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate /*
3327c478bd9Sstevel@tonic-gate * BUSY_TIMEOUT
3337c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.3.5
3347c478bd9Sstevel@tonic-gate */
3357c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_SCSR_BUSY_TIMEOUT;
3367c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
3377c478bd9Sstevel@tonic-gate addr.aa_enable = rw_flags;
3387c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
3397c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_busy_timeout;
3407c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = s1394_CSR_busy_timeout;
3417c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
3427c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
3437c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
3447c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
3457c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
3467c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate * BUS_MANAGER_ID
3517c478bd9Sstevel@tonic-gate * BANDWIDTH_AVAILABLE
3527c478bd9Sstevel@tonic-gate * CHANNELS_AVAILABLE
3537c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.3.6 - 8.3.2.3.8
3547c478bd9Sstevel@tonic-gate */
3557c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_SCSR_BUSMGR_ID;
3567c478bd9Sstevel@tonic-gate addr.aa_length = 3 * (IEEE1394_QUADLET);
3577c478bd9Sstevel@tonic-gate addr.aa_enable = T1394_ADDR_RDENBL | T1394_ADDR_LKENBL;
3587c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
3597c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_IRM_regs;
3607c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = NULL;
3617c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = s1394_CSR_IRM_regs;
3627c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = NULL;
3637c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
3647c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
3657c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
3667c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate * Reserved for Configuration ROM
3717c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.5.3
3727c478bd9Sstevel@tonic-gate */
3737c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_CONFIG_ROM_ADDR;
3747c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_CONFIG_ROM_SZ;
3757c478bd9Sstevel@tonic-gate result = s1394_reserve_addr_blk(hal, &addr);
3767c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
3777c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate /*
3817c478bd9Sstevel@tonic-gate * TOPOLOGY_MAP
3827c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.4.1
3837c478bd9Sstevel@tonic-gate */
3847c478bd9Sstevel@tonic-gate hal->CSR_topology_map = kmem_zalloc(IEEE1394_UCSR_TOPOLOGY_MAP_SZ,
3857c478bd9Sstevel@tonic-gate KM_SLEEP);
3867c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_UCSR_TOPOLOGY_MAP;
3877c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_UCSR_TOPOLOGY_MAP_SZ;
3887c478bd9Sstevel@tonic-gate addr.aa_enable = T1394_ADDR_RDENBL;
3897c478bd9Sstevel@tonic-gate addr.aa_type = T1394_ADDR_FIXED;
3907c478bd9Sstevel@tonic-gate addr.aa_evts.recv_read_request = s1394_CSR_topology_map;
3917c478bd9Sstevel@tonic-gate addr.aa_evts.recv_write_request = NULL;
3927c478bd9Sstevel@tonic-gate addr.aa_evts.recv_lock_request = NULL;
3937c478bd9Sstevel@tonic-gate addr.aa_kmem_bufp = (caddr_t)hal->CSR_topology_map;
3947c478bd9Sstevel@tonic-gate addr.aa_arg = hal;
3957c478bd9Sstevel@tonic-gate result = s1394_claim_addr_blk(hal, &addr);
3967c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
3977c478bd9Sstevel@tonic-gate kmem_free((void *)hal->CSR_topology_map,
3987c478bd9Sstevel@tonic-gate IEEE1394_UCSR_TOPOLOGY_MAP_SZ);
3997c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate curr_blk = (s1394_addr_space_blk_t *)(addr.aa_hdl);
4027c478bd9Sstevel@tonic-gate /* Set up the block so that we free kmem_bufp at detach */
4037c478bd9Sstevel@tonic-gate curr_blk->free_kmem_bufp = B_TRUE;
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate /*
4067c478bd9Sstevel@tonic-gate * Reserve the SPEED_MAP
4077c478bd9Sstevel@tonic-gate * see IEEE 1394-1995, Section 8.3.2.4.1
4087c478bd9Sstevel@tonic-gate * (obsoleted in P1394A)
4097c478bd9Sstevel@tonic-gate */
4107c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_UCSR_SPEED_MAP;
4117c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_UCSR_SPEED_MAP_SZ;
4127c478bd9Sstevel@tonic-gate result = s1394_reserve_addr_blk(hal, &addr);
4137c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
4147c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate * Reserved - Boundary between reserved Serial Bus
4197c478bd9Sstevel@tonic-gate * dependent registers and other CSR register space.
4207c478bd9Sstevel@tonic-gate * See IEEE 1394-1995, Table 8-4 for this address.
4217c478bd9Sstevel@tonic-gate *
4227c478bd9Sstevel@tonic-gate * This quadlet is reserved as a way of preventing
4237c478bd9Sstevel@tonic-gate * the inadvertant allocation of a part of CSR space
4247c478bd9Sstevel@tonic-gate * that will likely be used by future specifications
4257c478bd9Sstevel@tonic-gate */
4267c478bd9Sstevel@tonic-gate addr.aa_address = IEEE1394_UCSR_RESERVED_BOUNDARY;
4277c478bd9Sstevel@tonic-gate addr.aa_length = IEEE1394_QUADLET;
4287c478bd9Sstevel@tonic-gate result = s1394_reserve_addr_blk(hal, &addr);
4297c478bd9Sstevel@tonic-gate if (result != DDI_SUCCESS) {
4307c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate /*
4377c478bd9Sstevel@tonic-gate * s1394_CSR_state_clear()
4387c478bd9Sstevel@tonic-gate * handles all requests to the STATE_CLEAR CSR register. It enforces
4397c478bd9Sstevel@tonic-gate * that certain bits that can be twiddled only by a given node (IRM or
4407c478bd9Sstevel@tonic-gate * Bus Manager).
4417c478bd9Sstevel@tonic-gate */
4427c478bd9Sstevel@tonic-gate static void
s1394_CSR_state_clear(cmd1394_cmd_t * req)4437c478bd9Sstevel@tonic-gate s1394_CSR_state_clear(cmd1394_cmd_t *req)
4447c478bd9Sstevel@tonic-gate {
4457c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
4467c478bd9Sstevel@tonic-gate uint32_t data;
4477c478bd9Sstevel@tonic-gate uint_t offset;
4487c478bd9Sstevel@tonic-gate uint_t is_from;
4497c478bd9Sstevel@tonic-gate uint_t should_be_from;
4507c478bd9Sstevel@tonic-gate int result;
4517c478bd9Sstevel@tonic-gate
4527c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate /* Register offset */
4557c478bd9Sstevel@tonic-gate offset = req->cmd_addr & IEEE1394_CSR_OFFSET_MASK;
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate /* Verify that request is quadlet aligned */
4587c478bd9Sstevel@tonic-gate if ((offset & 0x3) != 0) {
4597c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
4607c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
4617c478bd9Sstevel@tonic-gate return;
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate /* Only writes from IRM or Bus Mgr allowed (in some cases) */
4657c478bd9Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
4667c478bd9Sstevel@tonic-gate is_from = IEEE1394_NODE_NUM(req->nodeID);
4677c478bd9Sstevel@tonic-gate if (hal->bus_mgr_node != -1)
4687c478bd9Sstevel@tonic-gate should_be_from = IEEE1394_NODE_NUM(hal->bus_mgr_node);
4697c478bd9Sstevel@tonic-gate else if (hal->IRM_node != -1)
4707c478bd9Sstevel@tonic-gate should_be_from = IEEE1394_NODE_NUM(hal->IRM_node);
4717c478bd9Sstevel@tonic-gate else
4727c478bd9Sstevel@tonic-gate should_be_from = S1394_INVALID_NODE_NUM;
4737c478bd9Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate switch (req->cmd_type) {
4767c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_RD_QUAD:
4777c478bd9Sstevel@tonic-gate /*
4787c478bd9Sstevel@tonic-gate * The csr_read() call can return DDI_FAILURE if the HAL
4797c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
4807c478bd9Sstevel@tonic-gate * unimplemented. But although the STATE_CLEAR register
4817c478bd9Sstevel@tonic-gate * is required to be implemented and readable, we will
4827c478bd9Sstevel@tonic-gate * return IEEE1394_RESP_ADDRESS_ERROR in the response if
4837c478bd9Sstevel@tonic-gate * we ever see this error.
4847c478bd9Sstevel@tonic-gate */
4857c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_read(hal->halinfo.hal_private,
4867c478bd9Sstevel@tonic-gate offset, &data);
4877c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
4887c478bd9Sstevel@tonic-gate req->cmd_u.q.quadlet_data = data;
4897c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
4907c478bd9Sstevel@tonic-gate } else {
4917c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate break;
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
4967c478bd9Sstevel@tonic-gate data = req->cmd_u.q.quadlet_data;
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate /* CMSTR bit - request must be from bus_mgr/IRM */
4997c478bd9Sstevel@tonic-gate if (is_from != should_be_from) {
5007c478bd9Sstevel@tonic-gate data = data & ~IEEE1394_CSR_STATE_CMSTR;
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
5047c478bd9Sstevel@tonic-gate /* DREQ bit - disabling DREQ can come from anyone */
5057c478bd9Sstevel@tonic-gate if (data & IEEE1394_CSR_STATE_DREQ) {
5067c478bd9Sstevel@tonic-gate hal->disable_requests_bit = 0;
5077c478bd9Sstevel@tonic-gate if (hal->hal_state == S1394_HAL_DREQ)
5087c478bd9Sstevel@tonic-gate hal->hal_state = S1394_HAL_NORMAL;
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate
5117c478bd9Sstevel@tonic-gate /* ABDICATE bit */
5127c478bd9Sstevel@tonic-gate if (data & IEEE1394_CSR_STATE_ABDICATE) {
5137c478bd9Sstevel@tonic-gate hal->abdicate_bus_mgr_bit = 0;
5147c478bd9Sstevel@tonic-gate }
5157c478bd9Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
5167c478bd9Sstevel@tonic-gate /*
5177c478bd9Sstevel@tonic-gate * The csr_write() call can return DDI_FAILURE if the HAL
5187c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
5197c478bd9Sstevel@tonic-gate * unimplemented. But although the STATE_CLEAR register
5207c478bd9Sstevel@tonic-gate * is required to be implemented and writeable, we will
5217c478bd9Sstevel@tonic-gate * return IEEE1394_RESP_ADDRESS_ERROR in the response if
5227c478bd9Sstevel@tonic-gate * we ever see this error.
5237c478bd9Sstevel@tonic-gate */
5247c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_write(hal->halinfo.hal_private,
5257c478bd9Sstevel@tonic-gate offset, data);
5267c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
5277c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
5287c478bd9Sstevel@tonic-gate } else {
5297c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate break;
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate default:
5347c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate
5407c478bd9Sstevel@tonic-gate /*
5417c478bd9Sstevel@tonic-gate * s1394_CSR_state_set()
5427c478bd9Sstevel@tonic-gate * handles all requests to the STATE_SET CSR register. It enforces that
5437c478bd9Sstevel@tonic-gate * certain bits that can be twiddled only by a given node (IRM or Bus
5447c478bd9Sstevel@tonic-gate * Manager).
5457c478bd9Sstevel@tonic-gate */
5467c478bd9Sstevel@tonic-gate static void
s1394_CSR_state_set(cmd1394_cmd_t * req)5477c478bd9Sstevel@tonic-gate s1394_CSR_state_set(cmd1394_cmd_t *req)
5487c478bd9Sstevel@tonic-gate {
5497c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
5507c478bd9Sstevel@tonic-gate uint32_t data;
5517c478bd9Sstevel@tonic-gate uint_t offset;
5527c478bd9Sstevel@tonic-gate uint_t is_from;
5537c478bd9Sstevel@tonic-gate uint_t should_be_from;
5547c478bd9Sstevel@tonic-gate uint_t hal_node_num;
5557c478bd9Sstevel@tonic-gate uint_t hal_number_of_nodes;
5567c478bd9Sstevel@tonic-gate int result;
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate /* Register offset */
5617c478bd9Sstevel@tonic-gate offset = req->cmd_addr & IEEE1394_CSR_OFFSET_MASK;
5627c478bd9Sstevel@tonic-gate
5637c478bd9Sstevel@tonic-gate /* Verify that request is quadlet aligned */
5647c478bd9Sstevel@tonic-gate if ((offset & 0x3) != 0) {
5657c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
5667c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
5677c478bd9Sstevel@tonic-gate return;
5687c478bd9Sstevel@tonic-gate }
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate /* Only writes from IRM or Bus Mgr allowed (in some cases) */
5717c478bd9Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
5727c478bd9Sstevel@tonic-gate is_from = IEEE1394_NODE_NUM(req->nodeID);
5737c478bd9Sstevel@tonic-gate if (hal->bus_mgr_node != -1)
5747c478bd9Sstevel@tonic-gate should_be_from = IEEE1394_NODE_NUM(hal->bus_mgr_node);
5757c478bd9Sstevel@tonic-gate else if (hal->IRM_node != -1)
5767c478bd9Sstevel@tonic-gate should_be_from = IEEE1394_NODE_NUM(hal->IRM_node);
5777c478bd9Sstevel@tonic-gate else
5787c478bd9Sstevel@tonic-gate should_be_from = S1394_INVALID_NODE_NUM;
5797c478bd9Sstevel@tonic-gate hal_node_num = IEEE1394_NODE_NUM(hal->node_id);
5807c478bd9Sstevel@tonic-gate hal_number_of_nodes = hal->number_of_nodes;
5817c478bd9Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate switch (req->cmd_type) {
5847c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
5857c478bd9Sstevel@tonic-gate data = req->cmd_u.q.quadlet_data;
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate /* CMSTR bit - request must be from bus_mgr/IRM */
5887c478bd9Sstevel@tonic-gate /* & must be root to have bit set */
5897c478bd9Sstevel@tonic-gate if ((is_from != should_be_from) ||
5907c478bd9Sstevel@tonic-gate (hal_node_num != (hal_number_of_nodes - 1))) {
5917c478bd9Sstevel@tonic-gate data = data & ~IEEE1394_CSR_STATE_CMSTR;
5927c478bd9Sstevel@tonic-gate }
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
5957c478bd9Sstevel@tonic-gate /* DREQ bit - only bus_mgr/IRM can set this bit */
5967c478bd9Sstevel@tonic-gate if (is_from != should_be_from) {
5977c478bd9Sstevel@tonic-gate data = data & ~IEEE1394_CSR_STATE_DREQ;
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate } else if (data & IEEE1394_CSR_STATE_DREQ) {
6007c478bd9Sstevel@tonic-gate hal->disable_requests_bit = 1;
6017c478bd9Sstevel@tonic-gate if (hal->hal_state == S1394_HAL_NORMAL)
6027c478bd9Sstevel@tonic-gate hal->hal_state = S1394_HAL_DREQ;
6037c478bd9Sstevel@tonic-gate }
6047c478bd9Sstevel@tonic-gate /* ABDICATE bit */
6057c478bd9Sstevel@tonic-gate if (data & IEEE1394_CSR_STATE_ABDICATE) {
6067c478bd9Sstevel@tonic-gate hal->abdicate_bus_mgr_bit = 1;
6077c478bd9Sstevel@tonic-gate }
6087c478bd9Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
6097c478bd9Sstevel@tonic-gate /*
6107c478bd9Sstevel@tonic-gate * The csr_write() call can return DDI_FAILURE if the HAL
6117c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
6127c478bd9Sstevel@tonic-gate * unimplemented. But although the STATE_SET register
6137c478bd9Sstevel@tonic-gate * is required to be implemented and writeable, we will
6147c478bd9Sstevel@tonic-gate * return IEEE1394_RESP_ADDRESS_ERROR in the response if
6157c478bd9Sstevel@tonic-gate * we ever see this error.
6167c478bd9Sstevel@tonic-gate */
6177c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_write(hal->halinfo.hal_private,
6187c478bd9Sstevel@tonic-gate offset, data);
6197c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
6207c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
6217c478bd9Sstevel@tonic-gate } else {
6227c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate break;
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate default:
6277c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate /*
6347c478bd9Sstevel@tonic-gate * s1394_CSR_node_ids()
6357c478bd9Sstevel@tonic-gate * handles all requests to the NODE_IDS CSR register. It passes all
6367c478bd9Sstevel@tonic-gate * requests to the common routine - s1394_common_CSR_routine().
6377c478bd9Sstevel@tonic-gate */
6387c478bd9Sstevel@tonic-gate static void
s1394_CSR_node_ids(cmd1394_cmd_t * req)6397c478bd9Sstevel@tonic-gate s1394_CSR_node_ids(cmd1394_cmd_t *req)
6407c478bd9Sstevel@tonic-gate {
6417c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
6447c478bd9Sstevel@tonic-gate
6457c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
6467c478bd9Sstevel@tonic-gate }
6477c478bd9Sstevel@tonic-gate
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate * s1394_CSR_reset_start()
6507c478bd9Sstevel@tonic-gate * handles all requests to the RESET_START CSR register. Only write
6517c478bd9Sstevel@tonic-gate * requests are legal, everything else gets a type_error response.
6527c478bd9Sstevel@tonic-gate */
6537c478bd9Sstevel@tonic-gate static void
s1394_CSR_reset_start(cmd1394_cmd_t * req)6547c478bd9Sstevel@tonic-gate s1394_CSR_reset_start(cmd1394_cmd_t *req)
6557c478bd9Sstevel@tonic-gate {
6567c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
6577c478bd9Sstevel@tonic-gate uint32_t data;
6587c478bd9Sstevel@tonic-gate uint_t offset;
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate /* RESET_START register offset */
6637c478bd9Sstevel@tonic-gate offset = req->cmd_addr & IEEE1394_CSR_OFFSET_MASK;
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate /* Verify that request is quadlet aligned */
6667c478bd9Sstevel@tonic-gate if ((offset & 0x3) != 0) {
6677c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
6687c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
6697c478bd9Sstevel@tonic-gate return;
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate
6727c478bd9Sstevel@tonic-gate switch (req->cmd_type) {
6737c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
6747c478bd9Sstevel@tonic-gate data = req->cmd_u.q.quadlet_data;
6757c478bd9Sstevel@tonic-gate /*
6767c478bd9Sstevel@tonic-gate * The csr_write() call can return DDI_FAILURE if the HAL
6777c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
6787c478bd9Sstevel@tonic-gate * unimplemented. Because we don't do any thing with
6797c478bd9Sstevel@tonic-gate * the RESET_START register we will ignore failures and
6807c478bd9Sstevel@tonic-gate * return IEEE1394_RESP_COMPLETE regardless.
6817c478bd9Sstevel@tonic-gate */
6827c478bd9Sstevel@tonic-gate (void) HAL_CALL(hal).csr_write(hal->halinfo.hal_private,
6837c478bd9Sstevel@tonic-gate offset, data);
6847c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
6857c478bd9Sstevel@tonic-gate break;
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate default:
6887c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate
6947c478bd9Sstevel@tonic-gate /*
6957c478bd9Sstevel@tonic-gate * s1394_CSR_split_timeout()
6967c478bd9Sstevel@tonic-gate * handles all requests to the SPLIT_TIMEOUT CSR register. It passes all
6977c478bd9Sstevel@tonic-gate * requests to the common routine - s1394_common_CSR_routine().
6987c478bd9Sstevel@tonic-gate */
6997c478bd9Sstevel@tonic-gate static void
s1394_CSR_split_timeout(cmd1394_cmd_t * req)7007c478bd9Sstevel@tonic-gate s1394_CSR_split_timeout(cmd1394_cmd_t *req)
7017c478bd9Sstevel@tonic-gate {
7027c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
7077c478bd9Sstevel@tonic-gate }
7087c478bd9Sstevel@tonic-gate
7097c478bd9Sstevel@tonic-gate /*
7107c478bd9Sstevel@tonic-gate * s1394_CSR_argument_regs()
7117c478bd9Sstevel@tonic-gate * handles all requests to the ARGUMENT CSR registers. It passes all
7127c478bd9Sstevel@tonic-gate * requests to the common routine - s1394_common_CSR_routine().
7137c478bd9Sstevel@tonic-gate */
7147c478bd9Sstevel@tonic-gate static void
s1394_CSR_argument_regs(cmd1394_cmd_t * req)7157c478bd9Sstevel@tonic-gate s1394_CSR_argument_regs(cmd1394_cmd_t *req)
7167c478bd9Sstevel@tonic-gate {
7177c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
7227c478bd9Sstevel@tonic-gate }
7237c478bd9Sstevel@tonic-gate
7247c478bd9Sstevel@tonic-gate /*
7257c478bd9Sstevel@tonic-gate * s1394_CSR_test_regs()
7267c478bd9Sstevel@tonic-gate * handles all requests to the TEST CSR registers. It passes all requests
7277c478bd9Sstevel@tonic-gate * to the common routine - s1394_common_CSR_routine().
7287c478bd9Sstevel@tonic-gate */
7297c478bd9Sstevel@tonic-gate static void
s1394_CSR_test_regs(cmd1394_cmd_t * req)7307c478bd9Sstevel@tonic-gate s1394_CSR_test_regs(cmd1394_cmd_t *req)
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
7337c478bd9Sstevel@tonic-gate uint_t offset;
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate /* TEST register offset */
7387c478bd9Sstevel@tonic-gate offset = req->cmd_addr & IEEE1394_CSR_OFFSET_MASK;
7397c478bd9Sstevel@tonic-gate
7407c478bd9Sstevel@tonic-gate /* TEST_STATUS is Read-Only */
7417c478bd9Sstevel@tonic-gate if ((offset == (IEEE1394_CSR_TEST_STATUS & IEEE1394_CSR_OFFSET_MASK)) &&
7427c478bd9Sstevel@tonic-gate (req->cmd_type == CMD1394_ASYNCH_WR_QUAD)) {
7437c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
7447c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
7457c478bd9Sstevel@tonic-gate } else {
7467c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
7477c478bd9Sstevel@tonic-gate }
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate
7507c478bd9Sstevel@tonic-gate /*
7517c478bd9Sstevel@tonic-gate * s1394_CSR_interrupt_regs()
7527c478bd9Sstevel@tonic-gate * handles all requests to the INTERRUPT CSR registers. It passes all
7537c478bd9Sstevel@tonic-gate * requests to the common routine - s1394_common_CSR_routine().
7547c478bd9Sstevel@tonic-gate */
7557c478bd9Sstevel@tonic-gate static void
s1394_CSR_interrupt_regs(cmd1394_cmd_t * req)7567c478bd9Sstevel@tonic-gate s1394_CSR_interrupt_regs(cmd1394_cmd_t *req)
7577c478bd9Sstevel@tonic-gate {
7587c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
7597c478bd9Sstevel@tonic-gate
7607c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
7637c478bd9Sstevel@tonic-gate }
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate /*
7667c478bd9Sstevel@tonic-gate * s1394_CSR_clock_regs()
7677c478bd9Sstevel@tonic-gate * handles all requests to the CLOCK CSR registers. It passes all
7687c478bd9Sstevel@tonic-gate * requests to the common routine - s1394_common_CSR_routine().
7697c478bd9Sstevel@tonic-gate */
7707c478bd9Sstevel@tonic-gate static void
s1394_CSR_clock_regs(cmd1394_cmd_t * req)7717c478bd9Sstevel@tonic-gate s1394_CSR_clock_regs(cmd1394_cmd_t *req)
7727c478bd9Sstevel@tonic-gate {
7737c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate /*
7817c478bd9Sstevel@tonic-gate * s1394_CSR_message_regs()
7827c478bd9Sstevel@tonic-gate * handles all requests to the MESSAGE CSR registers. It passes all
7837c478bd9Sstevel@tonic-gate * requests to the common routine - s1394_common_CSR_routine().
7847c478bd9Sstevel@tonic-gate */
7857c478bd9Sstevel@tonic-gate static void
s1394_CSR_message_regs(cmd1394_cmd_t * req)7867c478bd9Sstevel@tonic-gate s1394_CSR_message_regs(cmd1394_cmd_t *req)
7877c478bd9Sstevel@tonic-gate {
7887c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
7937c478bd9Sstevel@tonic-gate }
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate /*
7967c478bd9Sstevel@tonic-gate * s1394_CSR_cycle_time()
7977c478bd9Sstevel@tonic-gate * handles all requests to the CYCLE_TIME CSR register.
7987c478bd9Sstevel@tonic-gate */
7997c478bd9Sstevel@tonic-gate static void
s1394_CSR_cycle_time(cmd1394_cmd_t * req)8007c478bd9Sstevel@tonic-gate s1394_CSR_cycle_time(cmd1394_cmd_t *req)
8017c478bd9Sstevel@tonic-gate {
8027c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
8037c478bd9Sstevel@tonic-gate uint32_t data;
8047c478bd9Sstevel@tonic-gate uint_t offset;
8057c478bd9Sstevel@tonic-gate int result;
8067c478bd9Sstevel@tonic-gate
8077c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate /* CYCLE_TIME register offset */
8107c478bd9Sstevel@tonic-gate offset = req->cmd_addr & IEEE1394_CSR_OFFSET_MASK;
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate /* Verify that request is quadlet aligned */
8137c478bd9Sstevel@tonic-gate if ((offset & 0x3) != 0) {
8147c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
8157c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
8167c478bd9Sstevel@tonic-gate return;
8177c478bd9Sstevel@tonic-gate }
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate switch (req->cmd_type) {
8207c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_RD_QUAD:
8217c478bd9Sstevel@tonic-gate /*
8227c478bd9Sstevel@tonic-gate * The csr_read() call can return DDI_FAILURE if the HAL
8237c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
8247c478bd9Sstevel@tonic-gate * unimplemented. But although the CYCLE_TIME register
8257c478bd9Sstevel@tonic-gate * is required to be implemented on devices capable of
8267c478bd9Sstevel@tonic-gate * providing isochronous services (like us), we will
8277c478bd9Sstevel@tonic-gate * return IEEE1394_RESP_ADDRESS_ERROR in the response
8287c478bd9Sstevel@tonic-gate * if we ever see this error.
8297c478bd9Sstevel@tonic-gate */
8307c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_read(hal->halinfo.hal_private,
8317c478bd9Sstevel@tonic-gate offset, &data);
8327c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
8337c478bd9Sstevel@tonic-gate req->cmd_u.q.quadlet_data = data;
8347c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
8357c478bd9Sstevel@tonic-gate } else {
8367c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
8377c478bd9Sstevel@tonic-gate }
8387c478bd9Sstevel@tonic-gate break;
8397c478bd9Sstevel@tonic-gate
8407c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
8417c478bd9Sstevel@tonic-gate data = req->cmd_u.q.quadlet_data;
8427c478bd9Sstevel@tonic-gate /*
8437c478bd9Sstevel@tonic-gate * The csr_write() call can return DDI_FAILURE if the HAL
8447c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
8457c478bd9Sstevel@tonic-gate * unimplemented. But although the CYCLE_TIME register
8467c478bd9Sstevel@tonic-gate * is required to be implemented on devices capable of
8477c478bd9Sstevel@tonic-gate * providing isochronous services (like us), the effects
8487c478bd9Sstevel@tonic-gate * of a write are "node-dependent" so we will return
8497c478bd9Sstevel@tonic-gate * IEEE1394_RESP_ADDRESS_ERROR in the response if we
8507c478bd9Sstevel@tonic-gate * ever see this error.
8517c478bd9Sstevel@tonic-gate */
8527c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_write(hal->halinfo.hal_private,
8537c478bd9Sstevel@tonic-gate offset, data);
8547c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
8557c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
8567c478bd9Sstevel@tonic-gate } else {
8577c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
8587c478bd9Sstevel@tonic-gate }
8597c478bd9Sstevel@tonic-gate break;
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate default:
8627c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
8637c478bd9Sstevel@tonic-gate }
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
8667c478bd9Sstevel@tonic-gate }
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate /*
8697c478bd9Sstevel@tonic-gate * s1394_CSR_bus_time()
8707c478bd9Sstevel@tonic-gate * handles all requests to the BUS_TIME CSR register. It enforces that
8717c478bd9Sstevel@tonic-gate * only a broadcast write request from the IRM or Bus Manager can change
8727c478bd9Sstevel@tonic-gate * its value.
8737c478bd9Sstevel@tonic-gate */
8747c478bd9Sstevel@tonic-gate static void
s1394_CSR_bus_time(cmd1394_cmd_t * req)8757c478bd9Sstevel@tonic-gate s1394_CSR_bus_time(cmd1394_cmd_t *req)
8767c478bd9Sstevel@tonic-gate {
8777c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
8787c478bd9Sstevel@tonic-gate uint32_t data;
8797c478bd9Sstevel@tonic-gate uint_t offset;
8807c478bd9Sstevel@tonic-gate uint_t is_from;
8817c478bd9Sstevel@tonic-gate uint_t should_be_from;
8827c478bd9Sstevel@tonic-gate int result;
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate /* BUS_TIME register offset */
8877c478bd9Sstevel@tonic-gate offset = req->cmd_addr & IEEE1394_CSR_OFFSET_MASK;
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate /* Verify that request is quadlet aligned */
8907c478bd9Sstevel@tonic-gate if ((offset & 0x3) != 0) {
8917c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
8927c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
8937c478bd9Sstevel@tonic-gate return;
8947c478bd9Sstevel@tonic-gate }
8957c478bd9Sstevel@tonic-gate
8967c478bd9Sstevel@tonic-gate switch (req->cmd_type) {
8977c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_RD_QUAD:
8987c478bd9Sstevel@tonic-gate /*
8997c478bd9Sstevel@tonic-gate * The csr_read() call can return DDI_FAILURE if the HAL
9007c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
9017c478bd9Sstevel@tonic-gate * unimplemented. But although the BUS_TIME register
9027c478bd9Sstevel@tonic-gate * is required to be implemented by devices capable of
9037c478bd9Sstevel@tonic-gate * being cycle master (like us), we will return
9047c478bd9Sstevel@tonic-gate * IEEE1394_RESP_ADDRESS_ERROR in the response if we
9057c478bd9Sstevel@tonic-gate * ever see this error.
9067c478bd9Sstevel@tonic-gate */
9077c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_read(hal->halinfo.hal_private,
9087c478bd9Sstevel@tonic-gate offset, &data);
9097c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
9107c478bd9Sstevel@tonic-gate req->cmd_u.q.quadlet_data = data;
9117c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
9127c478bd9Sstevel@tonic-gate } else {
9137c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
9147c478bd9Sstevel@tonic-gate }
9157c478bd9Sstevel@tonic-gate break;
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
9187c478bd9Sstevel@tonic-gate /* Only broadcast writes from IRM or Bus Mgr allowed */
9197c478bd9Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
9207c478bd9Sstevel@tonic-gate is_from = IEEE1394_NODE_NUM(req->nodeID);
9217c478bd9Sstevel@tonic-gate if (hal->bus_mgr_node != -1)
9227c478bd9Sstevel@tonic-gate should_be_from = IEEE1394_NODE_NUM(hal->bus_mgr_node);
9237c478bd9Sstevel@tonic-gate else if (hal->IRM_node != -1)
9247c478bd9Sstevel@tonic-gate should_be_from = IEEE1394_NODE_NUM(hal->IRM_node);
9257c478bd9Sstevel@tonic-gate else
9267c478bd9Sstevel@tonic-gate should_be_from = S1394_INVALID_NODE_NUM;
9277c478bd9Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate if ((req->broadcast != 1) || (is_from != should_be_from)) {
9307c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
9317c478bd9Sstevel@tonic-gate break;
9327c478bd9Sstevel@tonic-gate }
9337c478bd9Sstevel@tonic-gate
9347c478bd9Sstevel@tonic-gate data = req->cmd_u.q.quadlet_data;
9357c478bd9Sstevel@tonic-gate /*
9367c478bd9Sstevel@tonic-gate * The csr_write() call can return DDI_FAILURE if the HAL
9377c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
9387c478bd9Sstevel@tonic-gate * unimplemented. But although the BUS_TIME register
9397c478bd9Sstevel@tonic-gate * is required to be implemented on devices capable of
9407c478bd9Sstevel@tonic-gate * being cycle master (like us), we will return
9417c478bd9Sstevel@tonic-gate * IEEE1394_RESP_ADDRESS_ERROR in the response if we
9427c478bd9Sstevel@tonic-gate * ever see this error.
9437c478bd9Sstevel@tonic-gate */
9447c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_write(hal->halinfo.hal_private,
9457c478bd9Sstevel@tonic-gate offset, data);
9467c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
9477c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
9487c478bd9Sstevel@tonic-gate } else {
9497c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
9507c478bd9Sstevel@tonic-gate }
9517c478bd9Sstevel@tonic-gate break;
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate default:
9547c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
9557c478bd9Sstevel@tonic-gate }
9567c478bd9Sstevel@tonic-gate
9577c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
9587c478bd9Sstevel@tonic-gate }
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gate /*
9617c478bd9Sstevel@tonic-gate * s1394_CSR_busy_timeout()
9627c478bd9Sstevel@tonic-gate * handles all requests to the BUSY_TIMEOUT CSR register. It passes all
9637c478bd9Sstevel@tonic-gate * requests to the common routine - s1394_common_CSR_routine().
9647c478bd9Sstevel@tonic-gate */
9657c478bd9Sstevel@tonic-gate static void
s1394_CSR_busy_timeout(cmd1394_cmd_t * req)9667c478bd9Sstevel@tonic-gate s1394_CSR_busy_timeout(cmd1394_cmd_t *req)
9677c478bd9Sstevel@tonic-gate {
9687c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
9697c478bd9Sstevel@tonic-gate
9707c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
9717c478bd9Sstevel@tonic-gate
9727c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(hal, req);
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate /*
9767c478bd9Sstevel@tonic-gate * s1394_CSR_IRM_regs()
9777c478bd9Sstevel@tonic-gate * handles all requests to the IRM registers, including BANDWIDTH_AVAILABLE,
9787c478bd9Sstevel@tonic-gate * CHANNELS_AVAILABLE, and the BUS_MANAGER_ID. Only quadlet read and lock
9797c478bd9Sstevel@tonic-gate * requests are allowed.
9807c478bd9Sstevel@tonic-gate */
9817c478bd9Sstevel@tonic-gate static void
s1394_CSR_IRM_regs(cmd1394_cmd_t * req)9827c478bd9Sstevel@tonic-gate s1394_CSR_IRM_regs(cmd1394_cmd_t *req)
9837c478bd9Sstevel@tonic-gate {
9847c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
9857c478bd9Sstevel@tonic-gate uint32_t generation;
9867c478bd9Sstevel@tonic-gate uint32_t data;
9877c478bd9Sstevel@tonic-gate uint32_t compare;
9887c478bd9Sstevel@tonic-gate uint32_t swap;
9897c478bd9Sstevel@tonic-gate uint32_t old;
9907c478bd9Sstevel@tonic-gate uint_t offset;
9917c478bd9Sstevel@tonic-gate int result;
9927c478bd9Sstevel@tonic-gate
9937c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate /* IRM register offset */
9967c478bd9Sstevel@tonic-gate offset = (req->cmd_addr & IEEE1394_CSR_OFFSET_MASK);
9977c478bd9Sstevel@tonic-gate
9987c478bd9Sstevel@tonic-gate /* Verify that request is quadlet aligned */
9997c478bd9Sstevel@tonic-gate if ((offset & 0x3) != 0) {
10007c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
10017c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
10027c478bd9Sstevel@tonic-gate return;
10037c478bd9Sstevel@tonic-gate }
10047c478bd9Sstevel@tonic-gate
10057c478bd9Sstevel@tonic-gate switch (req->cmd_type) {
10067c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_RD_QUAD:
10077c478bd9Sstevel@tonic-gate /*
10087c478bd9Sstevel@tonic-gate * The csr_read() call can return DDI_FAILURE if the HAL
10097c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
10107c478bd9Sstevel@tonic-gate * unimplemented. In many cases these registers will
10117c478bd9Sstevel@tonic-gate * have been implemented in HW. We are not likely to ever
10127c478bd9Sstevel@tonic-gate * receive this callback. If we do, though, we will
10137c478bd9Sstevel@tonic-gate * return IEEE1394_RESP_ADDRESS_ERROR when we get an error
10147c478bd9Sstevel@tonic-gate * and IEEE1394_RESP_COMPLETE for success.
10157c478bd9Sstevel@tonic-gate */
10167c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_read(hal->halinfo.hal_private,
10177c478bd9Sstevel@tonic-gate offset, &data);
10187c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
10197c478bd9Sstevel@tonic-gate req->cmd_u.q.quadlet_data = data;
10207c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
10217c478bd9Sstevel@tonic-gate } else {
10227c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
10237c478bd9Sstevel@tonic-gate }
10247c478bd9Sstevel@tonic-gate break;
10257c478bd9Sstevel@tonic-gate
10267c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_LOCK_32:
10277c478bd9Sstevel@tonic-gate mutex_enter(&hal->topology_tree_mutex);
10287c478bd9Sstevel@tonic-gate generation = hal->generation_count;
10297c478bd9Sstevel@tonic-gate mutex_exit(&hal->topology_tree_mutex);
10307c478bd9Sstevel@tonic-gate if (req->cmd_u.l32.lock_type == CMD1394_LOCK_COMPARE_SWAP) {
10317c478bd9Sstevel@tonic-gate compare = req->cmd_u.l32.arg_value;
10327c478bd9Sstevel@tonic-gate swap = req->cmd_u.l32.data_value;
10337c478bd9Sstevel@tonic-gate /*
10347c478bd9Sstevel@tonic-gate * The csr_cswap32() call can return DDI_FAILURE if
10357c478bd9Sstevel@tonic-gate * the HAL is shutdown, if the register at "offset"
10367c478bd9Sstevel@tonic-gate * is unimplemented, or if the generation has changed.
10377c478bd9Sstevel@tonic-gate * In the last case, it shouldn't matter because the
10387c478bd9Sstevel@tonic-gate * call to s1394_send_response will fail on a bad
10397c478bd9Sstevel@tonic-gate * generation and the command will be freed.
10407c478bd9Sstevel@tonic-gate */
10417c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_cswap32(
10427c478bd9Sstevel@tonic-gate hal->halinfo.hal_private, generation,
10437c478bd9Sstevel@tonic-gate offset, compare, swap, &old);
10447c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
10457c478bd9Sstevel@tonic-gate req->cmd_u.l32.old_value = old;
10467c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
10477c478bd9Sstevel@tonic-gate } else {
10487c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
10497c478bd9Sstevel@tonic-gate }
10507c478bd9Sstevel@tonic-gate break;
10517c478bd9Sstevel@tonic-gate } else {
10527c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
10537c478bd9Sstevel@tonic-gate }
10547c478bd9Sstevel@tonic-gate
10557c478bd9Sstevel@tonic-gate break;
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate default:
10587c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
10597c478bd9Sstevel@tonic-gate }
10607c478bd9Sstevel@tonic-gate
10617c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
10627c478bd9Sstevel@tonic-gate }
10637c478bd9Sstevel@tonic-gate
10647c478bd9Sstevel@tonic-gate /*
10657c478bd9Sstevel@tonic-gate * s1394_CSR_topology_map()
10667c478bd9Sstevel@tonic-gate * handles all request for the TOPOLOGY_MAP[]. Since it is implemented
10677c478bd9Sstevel@tonic-gate * with backing store, there isn't much to do besides return success or
10687c478bd9Sstevel@tonic-gate * failure.
10697c478bd9Sstevel@tonic-gate */
10707c478bd9Sstevel@tonic-gate static void
s1394_CSR_topology_map(cmd1394_cmd_t * req)10717c478bd9Sstevel@tonic-gate s1394_CSR_topology_map(cmd1394_cmd_t *req)
10727c478bd9Sstevel@tonic-gate {
10737c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)req->cmd_callback_arg;
10767c478bd9Sstevel@tonic-gate
10777c478bd9Sstevel@tonic-gate /* Make sure it's a quadlet read request */
10787c478bd9Sstevel@tonic-gate if (req->cmd_type == CMD1394_ASYNCH_RD_QUAD)
10797c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
10807c478bd9Sstevel@tonic-gate else
10817c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
10827c478bd9Sstevel@tonic-gate
10837c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
10847c478bd9Sstevel@tonic-gate }
10857c478bd9Sstevel@tonic-gate
10867c478bd9Sstevel@tonic-gate /*
10877c478bd9Sstevel@tonic-gate * s1394_CSR_topology_map_update()
10887c478bd9Sstevel@tonic-gate * is used to update the local host's TOPOLOGY_MAP[] buffer. It copies in
10897c478bd9Sstevel@tonic-gate * the SelfID packets, updates the generation and other fields, and
10907c478bd9Sstevel@tonic-gate * computes the necessary CRC values before returning.
10917c478bd9Sstevel@tonic-gate * Callers must be holding the topology_tree_mutex.
10927c478bd9Sstevel@tonic-gate */
10937c478bd9Sstevel@tonic-gate void
s1394_CSR_topology_map_update(s1394_hal_t * hal)10947c478bd9Sstevel@tonic-gate s1394_CSR_topology_map_update(s1394_hal_t *hal)
10957c478bd9Sstevel@tonic-gate {
10967c478bd9Sstevel@tonic-gate s1394_selfid_pkt_t *selfid_packet;
10977c478bd9Sstevel@tonic-gate uint32_t *tm_ptr;
10987c478bd9Sstevel@tonic-gate uint32_t *data_ptr;
10997c478bd9Sstevel@tonic-gate uint32_t node_count;
11007c478bd9Sstevel@tonic-gate uint32_t self_id_count;
11017c478bd9Sstevel@tonic-gate uint_t CRC;
11027c478bd9Sstevel@tonic-gate uint32_t length;
11037c478bd9Sstevel@tonic-gate int i, j, c;
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&hal->topology_tree_mutex));
11067c478bd9Sstevel@tonic-gate
11077c478bd9Sstevel@tonic-gate tm_ptr = (uint32_t *)hal->CSR_topology_map;
11087c478bd9Sstevel@tonic-gate data_ptr = (uint32_t *)&(tm_ptr[3]);
11097c478bd9Sstevel@tonic-gate
11107c478bd9Sstevel@tonic-gate c = 0;
11117c478bd9Sstevel@tonic-gate for (i = 0; i < hal->number_of_nodes; i++) {
11127c478bd9Sstevel@tonic-gate j = -1;
11137c478bd9Sstevel@tonic-gate selfid_packet = hal->selfid_ptrs[i];
11147c478bd9Sstevel@tonic-gate
11157c478bd9Sstevel@tonic-gate do {
11167c478bd9Sstevel@tonic-gate j++;
11177c478bd9Sstevel@tonic-gate data_ptr[c++] = selfid_packet[j].spkt_data;
11187c478bd9Sstevel@tonic-gate }
11197c478bd9Sstevel@tonic-gate while (IEEE1394_SELFID_ISMORE(&selfid_packet[j]));
11207c478bd9Sstevel@tonic-gate }
11217c478bd9Sstevel@tonic-gate
11227c478bd9Sstevel@tonic-gate /* Update Topology Map Generation */
11237c478bd9Sstevel@tonic-gate tm_ptr[1] = tm_ptr[1] + 1;
11247c478bd9Sstevel@tonic-gate
11257c478bd9Sstevel@tonic-gate /* Update Node_Count and Self_Id_Count */
11267c478bd9Sstevel@tonic-gate node_count = (i & IEEE1394_TOP_MAP_LEN_MASK);
11277c478bd9Sstevel@tonic-gate self_id_count = (c & IEEE1394_TOP_MAP_LEN_MASK);
11287c478bd9Sstevel@tonic-gate tm_ptr[2] = (node_count << IEEE1394_TOP_MAP_LEN_SHIFT) |
11297c478bd9Sstevel@tonic-gate (self_id_count);
11307c478bd9Sstevel@tonic-gate
11317c478bd9Sstevel@tonic-gate /* Calculate CRC-16 */
11327c478bd9Sstevel@tonic-gate length = self_id_count + 2;
11337c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&(tm_ptr[1]), length);
11347c478bd9Sstevel@tonic-gate tm_ptr[0] = (length << IEEE1394_TOP_MAP_LEN_SHIFT) | CRC;
11357c478bd9Sstevel@tonic-gate }
11367c478bd9Sstevel@tonic-gate
11377c478bd9Sstevel@tonic-gate /*
11387c478bd9Sstevel@tonic-gate * s1394_CSR_topology_map_disable()
11397c478bd9Sstevel@tonic-gate * is used to disable the local host's TOPOLOGY_MAP[] buffer (during bus
11407c478bd9Sstevel@tonic-gate * reset processing). It sets the topology map's length to zero to
11417c478bd9Sstevel@tonic-gate * indicate that it is invalid.
11427c478bd9Sstevel@tonic-gate */
11437c478bd9Sstevel@tonic-gate void
s1394_CSR_topology_map_disable(s1394_hal_t * hal)11447c478bd9Sstevel@tonic-gate s1394_CSR_topology_map_disable(s1394_hal_t *hal)
11457c478bd9Sstevel@tonic-gate {
11467c478bd9Sstevel@tonic-gate uint32_t *tm_ptr;
11477c478bd9Sstevel@tonic-gate
11487c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&hal->topology_tree_mutex));
11497c478bd9Sstevel@tonic-gate
11507c478bd9Sstevel@tonic-gate tm_ptr = (uint32_t *)hal->CSR_topology_map;
11517c478bd9Sstevel@tonic-gate
11527c478bd9Sstevel@tonic-gate /* Set length = 0 */
11537c478bd9Sstevel@tonic-gate tm_ptr[0] = tm_ptr[0] & IEEE1394_TOP_MAP_LEN_MASK;
11547c478bd9Sstevel@tonic-gate }
11557c478bd9Sstevel@tonic-gate
11567c478bd9Sstevel@tonic-gate /*
11577c478bd9Sstevel@tonic-gate * s1394_common_CSR_routine()
11587c478bd9Sstevel@tonic-gate * is used to handle most of the CSR register requests. They are passed
11597c478bd9Sstevel@tonic-gate * to the appropriate HAL entry point for further processing. Then they
11607c478bd9Sstevel@tonic-gate * are filled in with an appropriate response code, and the response is sent.
11617c478bd9Sstevel@tonic-gate */
11627c478bd9Sstevel@tonic-gate static void
s1394_common_CSR_routine(s1394_hal_t * hal,cmd1394_cmd_t * req)11637c478bd9Sstevel@tonic-gate s1394_common_CSR_routine(s1394_hal_t *hal, cmd1394_cmd_t *req)
11647c478bd9Sstevel@tonic-gate {
11657c478bd9Sstevel@tonic-gate uint32_t data;
11667c478bd9Sstevel@tonic-gate uint_t offset;
11677c478bd9Sstevel@tonic-gate int result;
11687c478bd9Sstevel@tonic-gate
11697c478bd9Sstevel@tonic-gate /* Register offset */
11707c478bd9Sstevel@tonic-gate offset = (req->cmd_addr & IEEE1394_CSR_OFFSET_MASK);
11717c478bd9Sstevel@tonic-gate
11727c478bd9Sstevel@tonic-gate /* Verify that request is quadlet aligned */
11737c478bd9Sstevel@tonic-gate if ((offset & 0x3) != 0) {
11747c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
11757c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
11767c478bd9Sstevel@tonic-gate }
11777c478bd9Sstevel@tonic-gate
11787c478bd9Sstevel@tonic-gate switch (req->cmd_type) {
11797c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_RD_QUAD:
11807c478bd9Sstevel@tonic-gate /*
11817c478bd9Sstevel@tonic-gate * The csr_read() call can return DDI_FAILURE if the HAL
11827c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
11837c478bd9Sstevel@tonic-gate * unimplemented. We will return IEEE1394_RESP_ADDRESS_ERROR
11847c478bd9Sstevel@tonic-gate * in the response if we see this error.
11857c478bd9Sstevel@tonic-gate */
11867c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_read(hal->halinfo.hal_private,
11877c478bd9Sstevel@tonic-gate offset, &data);
11887c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
11897c478bd9Sstevel@tonic-gate req->cmd_u.q.quadlet_data = data;
11907c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
11917c478bd9Sstevel@tonic-gate } else {
11927c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
11937c478bd9Sstevel@tonic-gate }
11947c478bd9Sstevel@tonic-gate break;
11957c478bd9Sstevel@tonic-gate
11967c478bd9Sstevel@tonic-gate case CMD1394_ASYNCH_WR_QUAD:
11977c478bd9Sstevel@tonic-gate data = req->cmd_u.q.quadlet_data;
11987c478bd9Sstevel@tonic-gate /*
11997c478bd9Sstevel@tonic-gate * The csr_read() call can return DDI_FAILURE if the HAL
12007c478bd9Sstevel@tonic-gate * is shutdown or if the register at "offset" is
12017c478bd9Sstevel@tonic-gate * unimplemented. We will return IEEE1394_RESP_ADDRESS_ERROR
12027c478bd9Sstevel@tonic-gate * in the response if we see this error.
12037c478bd9Sstevel@tonic-gate */
12047c478bd9Sstevel@tonic-gate result = HAL_CALL(hal).csr_write(hal->halinfo.hal_private,
12057c478bd9Sstevel@tonic-gate offset, data);
12067c478bd9Sstevel@tonic-gate if (result == DDI_SUCCESS) {
12077c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_COMPLETE;
12087c478bd9Sstevel@tonic-gate } else {
12097c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_ADDRESS_ERROR;
12107c478bd9Sstevel@tonic-gate }
12117c478bd9Sstevel@tonic-gate break;
12127c478bd9Sstevel@tonic-gate
12137c478bd9Sstevel@tonic-gate default:
12147c478bd9Sstevel@tonic-gate req->cmd_result = IEEE1394_RESP_TYPE_ERROR;
12157c478bd9Sstevel@tonic-gate }
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gate (void) s1394_send_response(hal, req);
12187c478bd9Sstevel@tonic-gate }
12197c478bd9Sstevel@tonic-gate
12207c478bd9Sstevel@tonic-gate /*
12217c478bd9Sstevel@tonic-gate * s1394_init_local_config_rom()
12227c478bd9Sstevel@tonic-gate * is called in the HAL attach routine - h1394_attach() - to setup the
12237c478bd9Sstevel@tonic-gate * initial Config ROM entries on the local host, including the
12247c478bd9Sstevel@tonic-gate * bus_info_block and the root and unit directories.
12257c478bd9Sstevel@tonic-gate */
12267c478bd9Sstevel@tonic-gate int
s1394_init_local_config_rom(s1394_hal_t * hal)12277c478bd9Sstevel@tonic-gate s1394_init_local_config_rom(s1394_hal_t *hal)
12287c478bd9Sstevel@tonic-gate {
12297c478bd9Sstevel@tonic-gate uint32_t *config_rom;
12307c478bd9Sstevel@tonic-gate uint32_t *node_unique_id_leaf;
12317c478bd9Sstevel@tonic-gate uint32_t *unit_dir;
12327c478bd9Sstevel@tonic-gate uint32_t *text_leaf;
12337c478bd9Sstevel@tonic-gate void *n_handle;
12347c478bd9Sstevel@tonic-gate uint64_t guid;
12357c478bd9Sstevel@tonic-gate uint32_t guid_hi, guid_lo;
12367c478bd9Sstevel@tonic-gate uint32_t bus_capabilities;
12377c478bd9Sstevel@tonic-gate uint32_t irmc, g;
12387c478bd9Sstevel@tonic-gate uint32_t module_vendor_id;
12397c478bd9Sstevel@tonic-gate uint32_t node_capabilities;
12407c478bd9Sstevel@tonic-gate uint32_t root_dir_len;
12417c478bd9Sstevel@tonic-gate uint32_t CRC;
12427c478bd9Sstevel@tonic-gate int status, i, ret;
12437c478bd9Sstevel@tonic-gate
12447c478bd9Sstevel@tonic-gate /* Setup Config ROM mutex */
12457c478bd9Sstevel@tonic-gate mutex_init(&hal->local_config_rom_mutex,
12467c478bd9Sstevel@tonic-gate NULL, MUTEX_DRIVER, hal->halinfo.hw_interrupt);
12477c478bd9Sstevel@tonic-gate
12487c478bd9Sstevel@tonic-gate /* Allocate 1K for the Config ROM buffer */
12497c478bd9Sstevel@tonic-gate hal->local_config_rom = (uint32_t *)kmem_zalloc(IEEE1394_CONFIG_ROM_SZ,
12507c478bd9Sstevel@tonic-gate KM_SLEEP);
12517c478bd9Sstevel@tonic-gate
12527c478bd9Sstevel@tonic-gate /* Allocate 1K for the temporary buffer */
12537c478bd9Sstevel@tonic-gate hal->temp_config_rom_buf = (uint32_t *)kmem_zalloc(
12547c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ, KM_SLEEP);
12557c478bd9Sstevel@tonic-gate
12567c478bd9Sstevel@tonic-gate config_rom = hal->local_config_rom;
12577c478bd9Sstevel@tonic-gate
12587c478bd9Sstevel@tonic-gate /* Lock the Config ROM buffer */
12597c478bd9Sstevel@tonic-gate mutex_enter(&hal->local_config_rom_mutex);
12607c478bd9Sstevel@tonic-gate
12617c478bd9Sstevel@tonic-gate /* Build the config ROM structures */
12627c478bd9Sstevel@tonic-gate ret = s1394_init_config_rom_structures(hal);
12637c478bd9Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
12647c478bd9Sstevel@tonic-gate /* Unlock the Config ROM buffer */
12657c478bd9Sstevel@tonic-gate mutex_exit(&hal->local_config_rom_mutex);
12667c478bd9Sstevel@tonic-gate kmem_free((void *)hal->temp_config_rom_buf,
12677c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
12687c478bd9Sstevel@tonic-gate kmem_free((void *)hal->local_config_rom,
12697c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
12707c478bd9Sstevel@tonic-gate mutex_destroy(&hal->local_config_rom_mutex);
12717c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
12727c478bd9Sstevel@tonic-gate }
12737c478bd9Sstevel@tonic-gate /* Build the Bus_Info_Block - see IEEE 1394-1995, Section 8.3.2.5.4 */
12747c478bd9Sstevel@tonic-gate bus_capabilities = hal->halinfo.bus_capabilities;
12757c478bd9Sstevel@tonic-gate
12767c478bd9Sstevel@tonic-gate /*
12777c478bd9Sstevel@tonic-gate * If we are Isoch Resource Manager capable then we are
12787c478bd9Sstevel@tonic-gate * Bus Manager capable too.
12797c478bd9Sstevel@tonic-gate */
12807c478bd9Sstevel@tonic-gate irmc = (bus_capabilities & IEEE1394_BIB_IRMC_MASK) >>
12817c478bd9Sstevel@tonic-gate IEEE1394_BIB_IRMC_SHIFT;
12827c478bd9Sstevel@tonic-gate if (irmc)
12837c478bd9Sstevel@tonic-gate bus_capabilities = bus_capabilities | IEEE1394_BIB_BMC_MASK;
12847c478bd9Sstevel@tonic-gate
12857c478bd9Sstevel@tonic-gate /*
12867c478bd9Sstevel@tonic-gate * Set generation to P1394a valid (but changeable)
12877c478bd9Sstevel@tonic-gate * Even if we have a 1995 PHY, we will still provide
12887c478bd9Sstevel@tonic-gate * certain P1394A functionality (especially with respect
12897c478bd9Sstevel@tonic-gate * to Config ROM updates). So we must publish this
12907c478bd9Sstevel@tonic-gate * information.
12917c478bd9Sstevel@tonic-gate */
12927c478bd9Sstevel@tonic-gate g = 2 << IEEE1394_BIB_GEN_SHIFT;
12937c478bd9Sstevel@tonic-gate bus_capabilities = bus_capabilities | g;
12947c478bd9Sstevel@tonic-gate
12957c478bd9Sstevel@tonic-gate /* Get the GUID */
12967c478bd9Sstevel@tonic-gate guid = hal->halinfo.guid;
12977c478bd9Sstevel@tonic-gate guid_hi = (uint32_t)(guid >> 32);
12987c478bd9Sstevel@tonic-gate guid_lo = (uint32_t)(guid & 0x00000000FFFFFFFF);
12997c478bd9Sstevel@tonic-gate
13007c478bd9Sstevel@tonic-gate config_rom[1] = 0x31333934; /* "1394" */
13017c478bd9Sstevel@tonic-gate config_rom[2] = bus_capabilities;
13027c478bd9Sstevel@tonic-gate config_rom[3] = guid_hi;
13037c478bd9Sstevel@tonic-gate config_rom[4] = guid_lo;
13047c478bd9Sstevel@tonic-gate
13057c478bd9Sstevel@tonic-gate /* The CRC covers only our Bus_Info_Block */
13067c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&config_rom[1], 4);
13077c478bd9Sstevel@tonic-gate config_rom[0] = (0x04040000) | CRC;
13087c478bd9Sstevel@tonic-gate
13097c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
13107c478bd9Sstevel@tonic-gate for (i = 0; i < IEEE1394_BIB_QUAD_SZ; i++)
13117c478bd9Sstevel@tonic-gate config_rom[i] = T1394_DATA32(config_rom[i]);
13127c478bd9Sstevel@tonic-gate
13137c478bd9Sstevel@tonic-gate /* Build the Root_Directory - see IEEE 1394-1995, Section 8.3.2.5.5 */
13147c478bd9Sstevel@tonic-gate
13157c478bd9Sstevel@tonic-gate /* MODULE_VENDOR_ID - see IEEE 1394-1995, Section 8.3.2.5.5.1 */
13167c478bd9Sstevel@tonic-gate module_vendor_id = S1394_SUNW_OUI;
13177c478bd9Sstevel@tonic-gate
13187c478bd9Sstevel@tonic-gate /* NODE_CAPABILITIES - see IEEE 1394-1995, Section 8.3.2.5.5.2 */
13197c478bd9Sstevel@tonic-gate node_capabilities = hal->halinfo.node_capabilities &
13207c478bd9Sstevel@tonic-gate IEEE1212_NODE_CAPABILITIES_MASK;
13217c478bd9Sstevel@tonic-gate root_dir_len = 2;
13227c478bd9Sstevel@tonic-gate
13237c478bd9Sstevel@tonic-gate config_rom[6] = (IEEE1212_MODULE_VENDOR_ID <<
13247c478bd9Sstevel@tonic-gate IEEE1212_KEY_VALUE_SHIFT) | module_vendor_id;
13257c478bd9Sstevel@tonic-gate config_rom[7] = (IEEE1212_NODE_CAPABILITIES <<
13267c478bd9Sstevel@tonic-gate IEEE1212_KEY_VALUE_SHIFT) | node_capabilities;
13277c478bd9Sstevel@tonic-gate
13287c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&config_rom[6], root_dir_len);
13297c478bd9Sstevel@tonic-gate config_rom[IEEE1394_BIB_QUAD_SZ] =
13307c478bd9Sstevel@tonic-gate (root_dir_len << IEEE1394_CFG_ROM_LEN_SHIFT) | CRC;
13317c478bd9Sstevel@tonic-gate
13327c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
13337c478bd9Sstevel@tonic-gate for (i = IEEE1394_BIB_QUAD_SZ; i < 8; i++)
13347c478bd9Sstevel@tonic-gate config_rom[i] = T1394_DATA32(config_rom[i]);
13357c478bd9Sstevel@tonic-gate
13367c478bd9Sstevel@tonic-gate /* Build the Root Text leaf - see IEEE 1394-1995, Section 8.3.2.5.7 */
13377c478bd9Sstevel@tonic-gate text_leaf = (uint32_t *)kmem_zalloc(S1394_ROOT_TEXT_LEAF_SZ, KM_SLEEP);
13387c478bd9Sstevel@tonic-gate text_leaf[1] = 0x00000000;
13397c478bd9Sstevel@tonic-gate text_leaf[2] = 0x00000000;
13407c478bd9Sstevel@tonic-gate text_leaf[3] = 0x53756e20; /* "Sun " */
13417c478bd9Sstevel@tonic-gate text_leaf[4] = 0x4d696372; /* "Micr" */
13427c478bd9Sstevel@tonic-gate text_leaf[5] = 0x6f737973; /* "osys" */
13437c478bd9Sstevel@tonic-gate text_leaf[6] = 0x74656d73; /* "tems" */
13447c478bd9Sstevel@tonic-gate text_leaf[7] = 0x2c20496e; /* ", In" */
13457c478bd9Sstevel@tonic-gate text_leaf[8] = 0x632e0000; /* "c." */
13467c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&text_leaf[1], S1394_ROOT_TEXT_LEAF_QUAD_SZ - 1);
13477c478bd9Sstevel@tonic-gate text_leaf[0] = (0x00080000) | CRC;
13487c478bd9Sstevel@tonic-gate
13497c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
13507c478bd9Sstevel@tonic-gate for (i = 0; i < 9; i++)
13517c478bd9Sstevel@tonic-gate text_leaf[i] = T1394_DATA32(text_leaf[i]);
13527c478bd9Sstevel@tonic-gate
13537c478bd9Sstevel@tonic-gate ret = s1394_add_config_rom_entry(hal, S1394_ROOT_TEXT_KEY, text_leaf,
13547c478bd9Sstevel@tonic-gate S1394_ROOT_TEXT_LEAF_QUAD_SZ, &n_handle, &status);
13557c478bd9Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
13567c478bd9Sstevel@tonic-gate kmem_free((void *)text_leaf, S1394_ROOT_TEXT_LEAF_SZ);
13577c478bd9Sstevel@tonic-gate /* Destroy the config_rom structures */
13587c478bd9Sstevel@tonic-gate (void) s1394_destroy_config_rom_structures(hal);
13597c478bd9Sstevel@tonic-gate /* Unlock the Config ROM buffer */
13607c478bd9Sstevel@tonic-gate mutex_exit(&hal->local_config_rom_mutex);
13617c478bd9Sstevel@tonic-gate kmem_free((void *)hal->temp_config_rom_buf,
13627c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
13637c478bd9Sstevel@tonic-gate kmem_free((void *)hal->local_config_rom,
13647c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
13657c478bd9Sstevel@tonic-gate mutex_destroy(&hal->local_config_rom_mutex);
13667c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
13677c478bd9Sstevel@tonic-gate }
13687c478bd9Sstevel@tonic-gate kmem_free((void *)text_leaf, S1394_ROOT_TEXT_LEAF_SZ);
13697c478bd9Sstevel@tonic-gate
13707c478bd9Sstevel@tonic-gate /* Build the Node_Unique_Id leaf - IEEE 1394-1995, Sect. 8.3.2.5.7.1 */
13717c478bd9Sstevel@tonic-gate node_unique_id_leaf = (uint32_t *)kmem_zalloc(S1394_NODE_UNIQUE_ID_SZ,
13727c478bd9Sstevel@tonic-gate KM_SLEEP);
13737c478bd9Sstevel@tonic-gate node_unique_id_leaf[1] = guid_hi;
13747c478bd9Sstevel@tonic-gate node_unique_id_leaf[2] = guid_lo;
13757c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&node_unique_id_leaf[1],
13767c478bd9Sstevel@tonic-gate S1394_NODE_UNIQUE_ID_QUAD_SZ - 1);
13777c478bd9Sstevel@tonic-gate node_unique_id_leaf[0] = (0x00020000) | CRC;
13787c478bd9Sstevel@tonic-gate
13797c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
13807c478bd9Sstevel@tonic-gate for (i = 0; i < S1394_NODE_UNIQUE_ID_QUAD_SZ; i++)
13817c478bd9Sstevel@tonic-gate node_unique_id_leaf[i] = T1394_DATA32(node_unique_id_leaf[i]);
13827c478bd9Sstevel@tonic-gate
13837c478bd9Sstevel@tonic-gate ret = s1394_add_config_rom_entry(hal, S1394_NODE_UNIQUE_ID_KEY,
13847c478bd9Sstevel@tonic-gate node_unique_id_leaf, S1394_NODE_UNIQUE_ID_QUAD_SZ, &n_handle,
13857c478bd9Sstevel@tonic-gate &status);
13867c478bd9Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
13877c478bd9Sstevel@tonic-gate kmem_free((void *)node_unique_id_leaf,
13887c478bd9Sstevel@tonic-gate S1394_NODE_UNIQUE_ID_SZ);
13897c478bd9Sstevel@tonic-gate /* Destroy the config_rom structures */
13907c478bd9Sstevel@tonic-gate (void) s1394_destroy_config_rom_structures(hal);
13917c478bd9Sstevel@tonic-gate /* Unlock the Config ROM buffer */
13927c478bd9Sstevel@tonic-gate mutex_exit(&hal->local_config_rom_mutex);
13937c478bd9Sstevel@tonic-gate kmem_free((void *)hal->temp_config_rom_buf,
13947c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
13957c478bd9Sstevel@tonic-gate kmem_free((void *)hal->local_config_rom,
13967c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
13977c478bd9Sstevel@tonic-gate mutex_destroy(&hal->local_config_rom_mutex);
13987c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
13997c478bd9Sstevel@tonic-gate }
14007c478bd9Sstevel@tonic-gate kmem_free((void *)node_unique_id_leaf, S1394_NODE_UNIQUE_ID_SZ);
14017c478bd9Sstevel@tonic-gate
14027c478bd9Sstevel@tonic-gate /* Build the Unit_Directory for 1394 Framework */
14037c478bd9Sstevel@tonic-gate unit_dir = (uint32_t *)kmem_zalloc(S1394_UNIT_DIR_SZ, KM_SLEEP);
14047c478bd9Sstevel@tonic-gate unit_dir[1] = 0x12080020; /* Sun Microsystems */
14057c478bd9Sstevel@tonic-gate unit_dir[2] = 0x13000001; /* Version 1 */
14067c478bd9Sstevel@tonic-gate unit_dir[3] = 0x81000001; /* offset to the text leaf */
14077c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&unit_dir[1], 3);
14087c478bd9Sstevel@tonic-gate unit_dir[0] = (0x00030000) | CRC;
14097c478bd9Sstevel@tonic-gate
14107c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
14117c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++)
14127c478bd9Sstevel@tonic-gate unit_dir[i] = T1394_DATA32(unit_dir[i]);
14137c478bd9Sstevel@tonic-gate
14147c478bd9Sstevel@tonic-gate /* Build the Unit Directory text leaf */
14157c478bd9Sstevel@tonic-gate unit_dir[5] = 0x00000000;
14167c478bd9Sstevel@tonic-gate unit_dir[6] = 0x00000000;
14177c478bd9Sstevel@tonic-gate unit_dir[7] = 0x536f6c61; /* "Sola" */
14187c478bd9Sstevel@tonic-gate unit_dir[8] = 0x72697320; /* "ris " */
14197c478bd9Sstevel@tonic-gate unit_dir[9] = 0x31333934; /* "1394" */
14207c478bd9Sstevel@tonic-gate unit_dir[10] = 0x20535720; /* " SW " */
14217c478bd9Sstevel@tonic-gate unit_dir[11] = 0x4672616d; /* "Fram" */
14227c478bd9Sstevel@tonic-gate unit_dir[12] = 0x65576f72; /* "ewor" */
14237c478bd9Sstevel@tonic-gate unit_dir[13] = 0x6b000000; /* "k" */
14247c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&unit_dir[5], 9);
14257c478bd9Sstevel@tonic-gate unit_dir[4] = (0x00090000) | CRC;
14267c478bd9Sstevel@tonic-gate
14277c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
14287c478bd9Sstevel@tonic-gate for (i = 4; i < S1394_UNIT_DIR_QUAD_SZ; i++)
14297c478bd9Sstevel@tonic-gate unit_dir[i] = T1394_DATA32(unit_dir[i]);
14307c478bd9Sstevel@tonic-gate
14317c478bd9Sstevel@tonic-gate ret = s1394_add_config_rom_entry(hal, S1394_UNIT_DIR_KEY, unit_dir,
14327c478bd9Sstevel@tonic-gate S1394_UNIT_DIR_QUAD_SZ, &n_handle, &status);
14337c478bd9Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
14347c478bd9Sstevel@tonic-gate kmem_free((void *)unit_dir, S1394_UNIT_DIR_SZ);
14357c478bd9Sstevel@tonic-gate /* Destroy the config_rom structures */
14367c478bd9Sstevel@tonic-gate (void) s1394_destroy_config_rom_structures(hal);
14377c478bd9Sstevel@tonic-gate /* Unlock the Config ROM buffer */
14387c478bd9Sstevel@tonic-gate mutex_exit(&hal->local_config_rom_mutex);
14397c478bd9Sstevel@tonic-gate kmem_free((void *)hal->temp_config_rom_buf,
14407c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
14417c478bd9Sstevel@tonic-gate /* Free the 1K for the Config ROM buffer */
14427c478bd9Sstevel@tonic-gate kmem_free((void *)hal->local_config_rom,
14437c478bd9Sstevel@tonic-gate IEEE1394_CONFIG_ROM_SZ);
14447c478bd9Sstevel@tonic-gate mutex_destroy(&hal->local_config_rom_mutex);
14457c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
14467c478bd9Sstevel@tonic-gate }
14477c478bd9Sstevel@tonic-gate kmem_free((void *)unit_dir, S1394_UNIT_DIR_SZ);
14487c478bd9Sstevel@tonic-gate
14497c478bd9Sstevel@tonic-gate hal->config_rom_update_amount = (IEEE1394_CONFIG_ROM_QUAD_SZ -
14507c478bd9Sstevel@tonic-gate hal->free_space);
14517c478bd9Sstevel@tonic-gate
14527c478bd9Sstevel@tonic-gate /* Unlock the Config ROM buffer */
14537c478bd9Sstevel@tonic-gate mutex_exit(&hal->local_config_rom_mutex);
14547c478bd9Sstevel@tonic-gate
14557c478bd9Sstevel@tonic-gate /*
14567c478bd9Sstevel@tonic-gate * The update_config_rom() call can return DDI_FAILURE if the
14577c478bd9Sstevel@tonic-gate * HAL is shutdown.
14587c478bd9Sstevel@tonic-gate */
14597c478bd9Sstevel@tonic-gate (void) HAL_CALL(hal).update_config_rom(hal->halinfo.hal_private,
14607c478bd9Sstevel@tonic-gate config_rom, IEEE1394_CONFIG_ROM_QUAD_SZ);
14617c478bd9Sstevel@tonic-gate
14627c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
14637c478bd9Sstevel@tonic-gate }
14647c478bd9Sstevel@tonic-gate
14657c478bd9Sstevel@tonic-gate /*
14667c478bd9Sstevel@tonic-gate * s1394_destroy_local_config_rom()
14677c478bd9Sstevel@tonic-gate * is necessary for h1394_detach(). It undoes all the work that
14687c478bd9Sstevel@tonic-gate * s1394_init_local_config_rom() had setup and more. By pulling
14697c478bd9Sstevel@tonic-gate * everything out of the conig rom structures and freeing them and their
14707c478bd9Sstevel@tonic-gate * associated mutexes, the Config ROM is completely cleaned up.
14717c478bd9Sstevel@tonic-gate */
14727c478bd9Sstevel@tonic-gate void
s1394_destroy_local_config_rom(s1394_hal_t * hal)14737c478bd9Sstevel@tonic-gate s1394_destroy_local_config_rom(s1394_hal_t *hal)
14747c478bd9Sstevel@tonic-gate {
14757c478bd9Sstevel@tonic-gate /* Lock the Config ROM buffer */
14767c478bd9Sstevel@tonic-gate mutex_enter(&hal->local_config_rom_mutex);
14777c478bd9Sstevel@tonic-gate
14787c478bd9Sstevel@tonic-gate /* Destroy the config_rom structures */
14797c478bd9Sstevel@tonic-gate (void) s1394_destroy_config_rom_structures(hal);
14807c478bd9Sstevel@tonic-gate
14817c478bd9Sstevel@tonic-gate /* Unlock the Config ROM buffer */
14827c478bd9Sstevel@tonic-gate mutex_exit(&hal->local_config_rom_mutex);
14837c478bd9Sstevel@tonic-gate
14847c478bd9Sstevel@tonic-gate /* Free the 1K for the temporary buffer */
14857c478bd9Sstevel@tonic-gate kmem_free((void *)hal->temp_config_rom_buf, IEEE1394_CONFIG_ROM_SZ);
14867c478bd9Sstevel@tonic-gate /* Free the 1K for the Config ROM buffer */
14877c478bd9Sstevel@tonic-gate kmem_free((void *)hal->local_config_rom, IEEE1394_CONFIG_ROM_SZ);
14887c478bd9Sstevel@tonic-gate
14897c478bd9Sstevel@tonic-gate /* Setup Config ROM mutex */
14907c478bd9Sstevel@tonic-gate mutex_destroy(&hal->local_config_rom_mutex);
14917c478bd9Sstevel@tonic-gate }
14927c478bd9Sstevel@tonic-gate
14937c478bd9Sstevel@tonic-gate /*
14947c478bd9Sstevel@tonic-gate * s1394_init_config_rom_structures()
14957c478bd9Sstevel@tonic-gate * initializes the structures that are used to maintain the local Config ROM.
14967c478bd9Sstevel@tonic-gate * Callers must be holding the local_config_rom_mutex.
14977c478bd9Sstevel@tonic-gate */
14987c478bd9Sstevel@tonic-gate static int
s1394_init_config_rom_structures(s1394_hal_t * hal)14997c478bd9Sstevel@tonic-gate s1394_init_config_rom_structures(s1394_hal_t *hal)
15007c478bd9Sstevel@tonic-gate {
15017c478bd9Sstevel@tonic-gate s1394_config_rom_t *root_directory;
15027c478bd9Sstevel@tonic-gate s1394_config_rom_t *rest_of_config_rom;
15037c478bd9Sstevel@tonic-gate
15047c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&hal->local_config_rom_mutex));
15057c478bd9Sstevel@tonic-gate
15067c478bd9Sstevel@tonic-gate root_directory = (s1394_config_rom_t *)kmem_zalloc(
15077c478bd9Sstevel@tonic-gate sizeof (s1394_config_rom_t), KM_SLEEP);
15087c478bd9Sstevel@tonic-gate
15097c478bd9Sstevel@tonic-gate root_directory->cfgrom_used = B_TRUE;
15107c478bd9Sstevel@tonic-gate root_directory->cfgrom_addr_lo = IEEE1394_BIB_QUAD_SZ;
15117c478bd9Sstevel@tonic-gate root_directory->cfgrom_addr_hi = IEEE1394_BIB_QUAD_SZ + 2;
15127c478bd9Sstevel@tonic-gate
15137c478bd9Sstevel@tonic-gate rest_of_config_rom = (s1394_config_rom_t *)kmem_zalloc(
15147c478bd9Sstevel@tonic-gate sizeof (s1394_config_rom_t), KM_SLEEP);
15157c478bd9Sstevel@tonic-gate
15167c478bd9Sstevel@tonic-gate rest_of_config_rom->cfgrom_used = B_FALSE;
15177c478bd9Sstevel@tonic-gate rest_of_config_rom->cfgrom_addr_lo = root_directory->cfgrom_addr_hi + 1;
15187c478bd9Sstevel@tonic-gate rest_of_config_rom->cfgrom_addr_hi = IEEE1394_CONFIG_ROM_QUAD_SZ - 1;
15197c478bd9Sstevel@tonic-gate
15207c478bd9Sstevel@tonic-gate root_directory->cfgrom_next = rest_of_config_rom;
15217c478bd9Sstevel@tonic-gate root_directory->cfgrom_prev = NULL;
15227c478bd9Sstevel@tonic-gate rest_of_config_rom->cfgrom_next = NULL;
15237c478bd9Sstevel@tonic-gate rest_of_config_rom->cfgrom_prev = root_directory;
15247c478bd9Sstevel@tonic-gate
15257c478bd9Sstevel@tonic-gate hal->root_directory = root_directory;
15267c478bd9Sstevel@tonic-gate hal->free_space = IEEE1394_CONFIG_ROM_QUAD_SZ -
15277c478bd9Sstevel@tonic-gate (rest_of_config_rom->cfgrom_addr_lo);
15287c478bd9Sstevel@tonic-gate
15297c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
15307c478bd9Sstevel@tonic-gate }
15317c478bd9Sstevel@tonic-gate
15327c478bd9Sstevel@tonic-gate /*
15337c478bd9Sstevel@tonic-gate * s1394_destroy_config_rom_structures()
15347c478bd9Sstevel@tonic-gate * is used to destroy the structures that maintain the local Config ROM.
15357c478bd9Sstevel@tonic-gate * Callers must be holding the local_config_rom_mutex.
15367c478bd9Sstevel@tonic-gate */
15377c478bd9Sstevel@tonic-gate static int
s1394_destroy_config_rom_structures(s1394_hal_t * hal)15387c478bd9Sstevel@tonic-gate s1394_destroy_config_rom_structures(s1394_hal_t *hal)
15397c478bd9Sstevel@tonic-gate {
15407c478bd9Sstevel@tonic-gate s1394_config_rom_t *curr_blk;
15417c478bd9Sstevel@tonic-gate s1394_config_rom_t *next_blk;
15427c478bd9Sstevel@tonic-gate
15437c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&hal->local_config_rom_mutex));
15447c478bd9Sstevel@tonic-gate
15457c478bd9Sstevel@tonic-gate curr_blk = hal->root_directory;
15467c478bd9Sstevel@tonic-gate
15477c478bd9Sstevel@tonic-gate while (curr_blk != NULL) {
15487c478bd9Sstevel@tonic-gate next_blk = curr_blk->cfgrom_next;
15497c478bd9Sstevel@tonic-gate kmem_free(curr_blk, sizeof (s1394_config_rom_t));
15507c478bd9Sstevel@tonic-gate curr_blk = next_blk;
15517c478bd9Sstevel@tonic-gate }
15527c478bd9Sstevel@tonic-gate
15537c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
15547c478bd9Sstevel@tonic-gate }
15557c478bd9Sstevel@tonic-gate
15567c478bd9Sstevel@tonic-gate /*
15577c478bd9Sstevel@tonic-gate * s1394_add_config_rom_entry()
15587c478bd9Sstevel@tonic-gate * is used to add a new entry to the local host's config ROM. By
15597c478bd9Sstevel@tonic-gate * specifying a key and a buffer, it is possible to update the Root
15607c478bd9Sstevel@tonic-gate * Directory to point to the new entry (in buffer). Additionally, all
15617c478bd9Sstevel@tonic-gate * of the relevant CRCs, lengths, and generations are updated as well.
15627c478bd9Sstevel@tonic-gate * By returning a Config ROM "handle", we can allow targets to remove
15637c478bd9Sstevel@tonic-gate * the corresponding entry.
15647c478bd9Sstevel@tonic-gate * Callers must be holding the local_config_rom_mutex.
15657c478bd9Sstevel@tonic-gate */
15667c478bd9Sstevel@tonic-gate int
s1394_add_config_rom_entry(s1394_hal_t * hal,uint8_t key,uint32_t * buffer,uint_t size,void ** handle,int * status)15677c478bd9Sstevel@tonic-gate s1394_add_config_rom_entry(s1394_hal_t *hal, uint8_t key, uint32_t *buffer,
15687c478bd9Sstevel@tonic-gate uint_t size, void **handle, int *status)
15697c478bd9Sstevel@tonic-gate {
15707c478bd9Sstevel@tonic-gate s1394_config_rom_t *curr_blk;
15717c478bd9Sstevel@tonic-gate s1394_config_rom_t *new_blk;
15727c478bd9Sstevel@tonic-gate uint32_t *config_rom;
15737c478bd9Sstevel@tonic-gate uint32_t *temp_buf;
15747c478bd9Sstevel@tonic-gate uint32_t CRC;
15757c478bd9Sstevel@tonic-gate uint_t tmp_offset;
15767c478bd9Sstevel@tonic-gate uint_t tmp_size, temp;
15777c478bd9Sstevel@tonic-gate uint_t last_entry_offset;
15787c478bd9Sstevel@tonic-gate int i;
15797c478bd9Sstevel@tonic-gate
15807c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&hal->local_config_rom_mutex));
15817c478bd9Sstevel@tonic-gate
15827c478bd9Sstevel@tonic-gate if (size > hal->free_space) {
15837c478bd9Sstevel@tonic-gate /* Out of space */
15847c478bd9Sstevel@tonic-gate *status = CMD1394_ERSRC_CONFLICT;
15857c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
15867c478bd9Sstevel@tonic-gate }
15877c478bd9Sstevel@tonic-gate
15887c478bd9Sstevel@tonic-gate config_rom = hal->local_config_rom;
15897c478bd9Sstevel@tonic-gate temp_buf = hal->temp_config_rom_buf;
15907c478bd9Sstevel@tonic-gate
15917c478bd9Sstevel@tonic-gate /* Copy the Bus_Info_Block */
15927c478bd9Sstevel@tonic-gate bcopy(&config_rom[0], &temp_buf[0], IEEE1394_BIB_SZ);
15937c478bd9Sstevel@tonic-gate
15947c478bd9Sstevel@tonic-gate /* Copy and add to the Root_Directory */
15957c478bd9Sstevel@tonic-gate tmp_offset = hal->root_directory->cfgrom_addr_lo;
15967c478bd9Sstevel@tonic-gate tmp_size = (hal->root_directory->cfgrom_addr_hi - tmp_offset) + 1;
15977c478bd9Sstevel@tonic-gate tmp_size = tmp_size + 1; /* For the new entry */
15987c478bd9Sstevel@tonic-gate bcopy(&config_rom[tmp_offset], &temp_buf[tmp_offset], tmp_size << 2);
15997c478bd9Sstevel@tonic-gate last_entry_offset = hal->root_directory->cfgrom_addr_hi + 1;
16007c478bd9Sstevel@tonic-gate
16017c478bd9Sstevel@tonic-gate curr_blk = hal->root_directory;
16027c478bd9Sstevel@tonic-gate curr_blk->cfgrom_addr_hi = curr_blk->cfgrom_addr_hi + 1;
16037c478bd9Sstevel@tonic-gate while (curr_blk->cfgrom_next != NULL) {
16047c478bd9Sstevel@tonic-gate if (curr_blk->cfgrom_next->cfgrom_used == B_TRUE) {
16057c478bd9Sstevel@tonic-gate tmp_offset = curr_blk->cfgrom_next->cfgrom_addr_lo;
16067c478bd9Sstevel@tonic-gate tmp_size = (curr_blk->cfgrom_next->cfgrom_addr_hi -
16077c478bd9Sstevel@tonic-gate tmp_offset) + 1;
16087c478bd9Sstevel@tonic-gate
16097c478bd9Sstevel@tonic-gate bcopy(&config_rom[tmp_offset],
16107c478bd9Sstevel@tonic-gate &temp_buf[tmp_offset + 1], tmp_size << 2);
16117c478bd9Sstevel@tonic-gate curr_blk->cfgrom_next->cfgrom_addr_lo++;
16127c478bd9Sstevel@tonic-gate curr_blk->cfgrom_next->cfgrom_addr_hi++;
16137c478bd9Sstevel@tonic-gate last_entry_offset =
16147c478bd9Sstevel@tonic-gate curr_blk->cfgrom_next->cfgrom_addr_hi;
16157c478bd9Sstevel@tonic-gate
16167c478bd9Sstevel@tonic-gate tmp_offset = curr_blk->cfgrom_next->root_dir_offset;
16177c478bd9Sstevel@tonic-gate
16187c478bd9Sstevel@tonic-gate /* Swap... add one... then unswap */
16197c478bd9Sstevel@tonic-gate temp = T1394_DATA32(temp_buf[tmp_offset]);
16207c478bd9Sstevel@tonic-gate temp++;
16217c478bd9Sstevel@tonic-gate temp_buf[tmp_offset] = T1394_DATA32(temp);
16227c478bd9Sstevel@tonic-gate } else {
16237c478bd9Sstevel@tonic-gate curr_blk->cfgrom_next->cfgrom_addr_lo++;
16247c478bd9Sstevel@tonic-gate hal->free_space--;
16257c478bd9Sstevel@tonic-gate break;
16267c478bd9Sstevel@tonic-gate }
16277c478bd9Sstevel@tonic-gate
16287c478bd9Sstevel@tonic-gate curr_blk = curr_blk->cfgrom_next;
16297c478bd9Sstevel@tonic-gate }
16307c478bd9Sstevel@tonic-gate
16317c478bd9Sstevel@tonic-gate /* Get the pointer to the "free" space */
16327c478bd9Sstevel@tonic-gate curr_blk = curr_blk->cfgrom_next;
16337c478bd9Sstevel@tonic-gate
16347c478bd9Sstevel@tonic-gate /* Is it an exact fit? */
16357c478bd9Sstevel@tonic-gate if (hal->free_space == size) {
16367c478bd9Sstevel@tonic-gate curr_blk->cfgrom_used = B_TRUE;
16377c478bd9Sstevel@tonic-gate
16387c478bd9Sstevel@tonic-gate } else { /* Must break this piece */
16397c478bd9Sstevel@tonic-gate new_blk = (s1394_config_rom_t *)kmem_zalloc(
16407c478bd9Sstevel@tonic-gate sizeof (s1394_config_rom_t), KM_SLEEP);
16417c478bd9Sstevel@tonic-gate if (new_blk == NULL) {
16427c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
16437c478bd9Sstevel@tonic-gate }
16447c478bd9Sstevel@tonic-gate
16457c478bd9Sstevel@tonic-gate new_blk->cfgrom_addr_hi = curr_blk->cfgrom_addr_hi;
16467c478bd9Sstevel@tonic-gate new_blk->cfgrom_addr_lo = curr_blk->cfgrom_addr_lo + size;
16477c478bd9Sstevel@tonic-gate curr_blk->cfgrom_addr_hi = new_blk->cfgrom_addr_lo - 1;
16487c478bd9Sstevel@tonic-gate new_blk->cfgrom_next = curr_blk->cfgrom_next;
16497c478bd9Sstevel@tonic-gate curr_blk->cfgrom_next = new_blk;
16507c478bd9Sstevel@tonic-gate new_blk->cfgrom_prev = curr_blk;
16517c478bd9Sstevel@tonic-gate curr_blk->cfgrom_used = B_TRUE;
16527c478bd9Sstevel@tonic-gate last_entry_offset = curr_blk->cfgrom_addr_hi;
16537c478bd9Sstevel@tonic-gate }
16547c478bd9Sstevel@tonic-gate hal->free_space = hal->free_space - size;
16557c478bd9Sstevel@tonic-gate
16567c478bd9Sstevel@tonic-gate /* Copy in the new entry */
16577c478bd9Sstevel@tonic-gate tmp_offset = curr_blk->cfgrom_addr_lo;
16587c478bd9Sstevel@tonic-gate bcopy(buffer, &temp_buf[tmp_offset], size << 2);
16597c478bd9Sstevel@tonic-gate
16607c478bd9Sstevel@tonic-gate /* Update root directory */
16617c478bd9Sstevel@tonic-gate tmp_offset = hal->root_directory->cfgrom_addr_hi;
16627c478bd9Sstevel@tonic-gate tmp_size = tmp_offset - hal->root_directory->cfgrom_addr_lo;
16637c478bd9Sstevel@tonic-gate curr_blk->root_dir_offset = tmp_offset;
16647c478bd9Sstevel@tonic-gate tmp_offset = curr_blk->cfgrom_addr_lo - tmp_offset;
16657c478bd9Sstevel@tonic-gate
16667c478bd9Sstevel@tonic-gate temp_buf[hal->root_directory->cfgrom_addr_hi] =
16677c478bd9Sstevel@tonic-gate T1394_DATA32((((uint32_t)key) << IEEE1212_KEY_VALUE_SHIFT) |
16687c478bd9Sstevel@tonic-gate tmp_offset);
16697c478bd9Sstevel@tonic-gate tmp_offset = hal->root_directory->cfgrom_addr_lo;
16707c478bd9Sstevel@tonic-gate
16717c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
16727c478bd9Sstevel@tonic-gate for (i = (tmp_offset + 1); i <= hal->root_directory->cfgrom_addr_hi;
16737c478bd9Sstevel@tonic-gate i++)
16747c478bd9Sstevel@tonic-gate temp_buf[i] = T1394_DATA32(temp_buf[i]);
16757c478bd9Sstevel@tonic-gate
16767c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&temp_buf[tmp_offset + 1], tmp_size);
16777c478bd9Sstevel@tonic-gate temp_buf[tmp_offset] = (tmp_size << IEEE1394_CFG_ROM_LEN_SHIFT) | CRC;
16787c478bd9Sstevel@tonic-gate
16797c478bd9Sstevel@tonic-gate /* Redo byte-swapping if necessary (x86) */
16807c478bd9Sstevel@tonic-gate for (i = tmp_offset; i <= hal->root_directory->cfgrom_addr_hi; i++)
16817c478bd9Sstevel@tonic-gate temp_buf[i] = T1394_DATA32(temp_buf[i]);
16827c478bd9Sstevel@tonic-gate
16837c478bd9Sstevel@tonic-gate /* Copy it back to config_rom buffer */
16847c478bd9Sstevel@tonic-gate last_entry_offset++;
16857c478bd9Sstevel@tonic-gate bcopy(&temp_buf[0], &config_rom[0], last_entry_offset << 2);
16867c478bd9Sstevel@tonic-gate
16877c478bd9Sstevel@tonic-gate /* Return a handle to this block */
16887c478bd9Sstevel@tonic-gate *handle = curr_blk;
16897c478bd9Sstevel@tonic-gate
16907c478bd9Sstevel@tonic-gate *status = T1394_NOERROR;
16917c478bd9Sstevel@tonic-gate
16927c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
16937c478bd9Sstevel@tonic-gate }
16947c478bd9Sstevel@tonic-gate
16957c478bd9Sstevel@tonic-gate /*
16967c478bd9Sstevel@tonic-gate * s1394_remove_config_rom_entry()
16977c478bd9Sstevel@tonic-gate * is used to remove an entry from the local host's config ROM. By
16987c478bd9Sstevel@tonic-gate * specifying the Config ROM "handle" that was given in the allocation,
16997c478bd9Sstevel@tonic-gate * it is possible to remove the entry. Subsequently, the Config ROM is
17007c478bd9Sstevel@tonic-gate * updated again.
17017c478bd9Sstevel@tonic-gate * Callers must be holding the local_config_rom_mutex.
17027c478bd9Sstevel@tonic-gate */
17037c478bd9Sstevel@tonic-gate int
s1394_remove_config_rom_entry(s1394_hal_t * hal,void ** handle,int * status)17047c478bd9Sstevel@tonic-gate s1394_remove_config_rom_entry(s1394_hal_t *hal, void **handle, int *status)
17057c478bd9Sstevel@tonic-gate {
17067c478bd9Sstevel@tonic-gate s1394_config_rom_t *del_blk;
17077c478bd9Sstevel@tonic-gate s1394_config_rom_t *curr_blk;
17087c478bd9Sstevel@tonic-gate s1394_config_rom_t *last_blk;
17097c478bd9Sstevel@tonic-gate s1394_config_rom_t *free_blk;
17107c478bd9Sstevel@tonic-gate uint32_t *config_rom;
17117c478bd9Sstevel@tonic-gate uint32_t *temp_buf;
17127c478bd9Sstevel@tonic-gate uint32_t entry;
17137c478bd9Sstevel@tonic-gate uint_t CRC;
17147c478bd9Sstevel@tonic-gate uint_t root_offset;
17157c478bd9Sstevel@tonic-gate uint_t del_offset;
17167c478bd9Sstevel@tonic-gate uint_t tmp_offset;
17177c478bd9Sstevel@tonic-gate uint_t tmp_size;
17187c478bd9Sstevel@tonic-gate int i;
17197c478bd9Sstevel@tonic-gate
17207c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&hal->local_config_rom_mutex));
17217c478bd9Sstevel@tonic-gate
17227c478bd9Sstevel@tonic-gate del_blk = (s1394_config_rom_t *)(*handle);
17237c478bd9Sstevel@tonic-gate
17247c478bd9Sstevel@tonic-gate config_rom = hal->local_config_rom;
17257c478bd9Sstevel@tonic-gate temp_buf = hal->temp_config_rom_buf;
17267c478bd9Sstevel@tonic-gate
17277c478bd9Sstevel@tonic-gate /* Copy the Bus_Info_Block */
17287c478bd9Sstevel@tonic-gate bcopy(&config_rom[0], &temp_buf[0], IEEE1394_BIB_SZ);
17297c478bd9Sstevel@tonic-gate
17307c478bd9Sstevel@tonic-gate root_offset = hal->root_directory->cfgrom_addr_lo;
17317c478bd9Sstevel@tonic-gate del_offset = del_blk->root_dir_offset;
17327c478bd9Sstevel@tonic-gate
17337c478bd9Sstevel@tonic-gate /* Update Root_Directory entries before the deleted one */
17347c478bd9Sstevel@tonic-gate for (i = root_offset; i < del_offset; i++) {
17357c478bd9Sstevel@tonic-gate entry = T1394_DATA32(config_rom[i]);
17367c478bd9Sstevel@tonic-gate
17377c478bd9Sstevel@tonic-gate /* If entry is an offset address - update it */
17387c478bd9Sstevel@tonic-gate if (entry & 0x80000000)
17397c478bd9Sstevel@tonic-gate temp_buf[i] = T1394_DATA32(entry - 1);
17407c478bd9Sstevel@tonic-gate else
17417c478bd9Sstevel@tonic-gate temp_buf[i] = T1394_DATA32(entry);
17427c478bd9Sstevel@tonic-gate }
17437c478bd9Sstevel@tonic-gate
17447c478bd9Sstevel@tonic-gate /* Move all Unit_Directories prior to the deleted one */
17457c478bd9Sstevel@tonic-gate curr_blk = hal->root_directory->cfgrom_next;
17467c478bd9Sstevel@tonic-gate
17477c478bd9Sstevel@tonic-gate while (curr_blk != del_blk) {
17487c478bd9Sstevel@tonic-gate tmp_offset = curr_blk->cfgrom_addr_lo;
17497c478bd9Sstevel@tonic-gate tmp_size = (curr_blk->cfgrom_addr_hi - tmp_offset) + 1;
17507c478bd9Sstevel@tonic-gate
17517c478bd9Sstevel@tonic-gate bcopy(&config_rom[tmp_offset], &temp_buf[tmp_offset - 1],
17527c478bd9Sstevel@tonic-gate tmp_size << 2);
17537c478bd9Sstevel@tonic-gate curr_blk->cfgrom_addr_lo--;
17547c478bd9Sstevel@tonic-gate curr_blk->cfgrom_addr_hi--;
17557c478bd9Sstevel@tonic-gate curr_blk = curr_blk->cfgrom_next;
17567c478bd9Sstevel@tonic-gate }
17577c478bd9Sstevel@tonic-gate
17587c478bd9Sstevel@tonic-gate /* Move all Unit_Directories after the deleted one */
17597c478bd9Sstevel@tonic-gate curr_blk = del_blk->cfgrom_next;
17607c478bd9Sstevel@tonic-gate last_blk = del_blk->cfgrom_prev;
17617c478bd9Sstevel@tonic-gate
17627c478bd9Sstevel@tonic-gate del_offset = (del_blk->cfgrom_addr_hi - del_blk->cfgrom_addr_lo) + 1;
17637c478bd9Sstevel@tonic-gate
17647c478bd9Sstevel@tonic-gate while ((curr_blk != NULL) && (curr_blk->cfgrom_used == B_TRUE)) {
17657c478bd9Sstevel@tonic-gate tmp_offset = curr_blk->cfgrom_addr_lo;
17667c478bd9Sstevel@tonic-gate tmp_size = (curr_blk->cfgrom_addr_hi - tmp_offset) + 1;
17677c478bd9Sstevel@tonic-gate
17687c478bd9Sstevel@tonic-gate bcopy(&config_rom[tmp_offset],
17697c478bd9Sstevel@tonic-gate &temp_buf[tmp_offset - (del_offset + 1)], tmp_size << 2);
17707c478bd9Sstevel@tonic-gate
17717c478bd9Sstevel@tonic-gate root_offset = curr_blk->root_dir_offset;
17727c478bd9Sstevel@tonic-gate temp_buf[root_offset - 1] =
17737c478bd9Sstevel@tonic-gate config_rom[root_offset] - del_offset;
17747c478bd9Sstevel@tonic-gate curr_blk->root_dir_offset--;
17757c478bd9Sstevel@tonic-gate curr_blk->cfgrom_addr_lo = curr_blk->cfgrom_addr_lo -
17767c478bd9Sstevel@tonic-gate (del_offset + 1);
17777c478bd9Sstevel@tonic-gate curr_blk->cfgrom_addr_hi = curr_blk->cfgrom_addr_hi -
17787c478bd9Sstevel@tonic-gate (del_offset + 1);
17797c478bd9Sstevel@tonic-gate
17807c478bd9Sstevel@tonic-gate last_blk = curr_blk;
17817c478bd9Sstevel@tonic-gate curr_blk = curr_blk->cfgrom_next;
17827c478bd9Sstevel@tonic-gate }
17837c478bd9Sstevel@tonic-gate
17847c478bd9Sstevel@tonic-gate /* Remove del_blk from the list */
17857c478bd9Sstevel@tonic-gate if (del_blk->cfgrom_prev != NULL)
17867c478bd9Sstevel@tonic-gate del_blk->cfgrom_prev->cfgrom_next = del_blk->cfgrom_next;
17877c478bd9Sstevel@tonic-gate
17887c478bd9Sstevel@tonic-gate if (del_blk->cfgrom_next != NULL)
17897c478bd9Sstevel@tonic-gate del_blk->cfgrom_next->cfgrom_prev = del_blk->cfgrom_prev;
17907c478bd9Sstevel@tonic-gate
17917c478bd9Sstevel@tonic-gate del_blk->cfgrom_prev = NULL;
17927c478bd9Sstevel@tonic-gate del_blk->cfgrom_next = NULL;
17937c478bd9Sstevel@tonic-gate kmem_free((void *)del_blk, sizeof (s1394_config_rom_t));
17947c478bd9Sstevel@tonic-gate
17957c478bd9Sstevel@tonic-gate /* Update and zero out the "free" block */
17967c478bd9Sstevel@tonic-gate if (curr_blk != NULL) {
17977c478bd9Sstevel@tonic-gate curr_blk->cfgrom_addr_lo = curr_blk->cfgrom_addr_lo -
17987c478bd9Sstevel@tonic-gate (del_offset + 1);
17997c478bd9Sstevel@tonic-gate
18007c478bd9Sstevel@tonic-gate } else {
18017c478bd9Sstevel@tonic-gate free_blk = (s1394_config_rom_t *)kmem_zalloc(
18027c478bd9Sstevel@tonic-gate sizeof (s1394_config_rom_t), KM_SLEEP);
18037c478bd9Sstevel@tonic-gate if (free_blk == NULL) {
18047c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
18057c478bd9Sstevel@tonic-gate }
18067c478bd9Sstevel@tonic-gate
18077c478bd9Sstevel@tonic-gate free_blk->cfgrom_used = B_FALSE;
18087c478bd9Sstevel@tonic-gate free_blk->cfgrom_addr_lo = (IEEE1394_CONFIG_ROM_QUAD_SZ - 1) -
18097c478bd9Sstevel@tonic-gate (del_offset + 1);
18107c478bd9Sstevel@tonic-gate free_blk->cfgrom_addr_hi = (IEEE1394_CONFIG_ROM_QUAD_SZ - 1);
18117c478bd9Sstevel@tonic-gate
18127c478bd9Sstevel@tonic-gate free_blk->cfgrom_prev = last_blk;
18137c478bd9Sstevel@tonic-gate free_blk->cfgrom_next = NULL;
18147c478bd9Sstevel@tonic-gate curr_blk = free_blk;
18157c478bd9Sstevel@tonic-gate }
18167c478bd9Sstevel@tonic-gate hal->free_space = hal->free_space + (del_offset + 1);
18177c478bd9Sstevel@tonic-gate tmp_offset = curr_blk->cfgrom_addr_lo;
18187c478bd9Sstevel@tonic-gate tmp_size = (curr_blk->cfgrom_addr_hi - tmp_offset) + 1;
18197c478bd9Sstevel@tonic-gate bzero(&temp_buf[tmp_offset], tmp_size << 2);
18207c478bd9Sstevel@tonic-gate
18217c478bd9Sstevel@tonic-gate
18227c478bd9Sstevel@tonic-gate /* Update root directory */
18237c478bd9Sstevel@tonic-gate hal->root_directory->cfgrom_addr_hi--;
18247c478bd9Sstevel@tonic-gate tmp_offset = hal->root_directory->cfgrom_addr_lo;
18257c478bd9Sstevel@tonic-gate tmp_size = hal->root_directory->cfgrom_addr_hi - tmp_offset;
18267c478bd9Sstevel@tonic-gate
18277c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
18287c478bd9Sstevel@tonic-gate for (i = (tmp_offset + 1); i <= hal->root_directory->cfgrom_addr_hi;
18297c478bd9Sstevel@tonic-gate i++)
18307c478bd9Sstevel@tonic-gate temp_buf[i] = T1394_DATA32(temp_buf[i]);
18317c478bd9Sstevel@tonic-gate
18327c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&temp_buf[tmp_offset + 1], tmp_size);
18337c478bd9Sstevel@tonic-gate temp_buf[tmp_offset] = (tmp_size << IEEE1394_CFG_ROM_LEN_SHIFT) | CRC;
18347c478bd9Sstevel@tonic-gate
18357c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
18367c478bd9Sstevel@tonic-gate for (i = (tmp_offset + 1); i <= hal->root_directory->cfgrom_addr_hi;
18377c478bd9Sstevel@tonic-gate i++)
18387c478bd9Sstevel@tonic-gate temp_buf[i] = T1394_DATA32(temp_buf[i]);
18397c478bd9Sstevel@tonic-gate
18407c478bd9Sstevel@tonic-gate /* Copy it back to config_rom buffer */
18417c478bd9Sstevel@tonic-gate tmp_size = IEEE1394_CONFIG_ROM_SZ - (hal->free_space << 2);
18427c478bd9Sstevel@tonic-gate bcopy(&temp_buf[0], &config_rom[0], tmp_size);
18437c478bd9Sstevel@tonic-gate
18447c478bd9Sstevel@tonic-gate /* Return a handle to this block */
18457c478bd9Sstevel@tonic-gate *handle = NULL;
18467c478bd9Sstevel@tonic-gate
18477c478bd9Sstevel@tonic-gate *status = T1394_NOERROR;
18487c478bd9Sstevel@tonic-gate
18497c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
18507c478bd9Sstevel@tonic-gate }
18517c478bd9Sstevel@tonic-gate
18527c478bd9Sstevel@tonic-gate /*
18537c478bd9Sstevel@tonic-gate * s1394_update_config_rom_callback()
18547c478bd9Sstevel@tonic-gate * is the callback used by t1394_add_cfgrom_entry() and
18557c478bd9Sstevel@tonic-gate * t1394_rem_cfgrom_entry(). After a target updates the Config ROM, a
18567c478bd9Sstevel@tonic-gate * timer is set with this as its callback function. This is to reduce
18577c478bd9Sstevel@tonic-gate * the number of bus resets that would be necessary if many targets
18587c478bd9Sstevel@tonic-gate * wished to update the Config ROM simultaneously.
18597c478bd9Sstevel@tonic-gate */
18607c478bd9Sstevel@tonic-gate void
s1394_update_config_rom_callback(void * arg)18617c478bd9Sstevel@tonic-gate s1394_update_config_rom_callback(void *arg)
18627c478bd9Sstevel@tonic-gate {
18637c478bd9Sstevel@tonic-gate s1394_hal_t *hal;
18647c478bd9Sstevel@tonic-gate uint32_t *config_rom;
18657c478bd9Sstevel@tonic-gate uint32_t bus_capabilities;
18667c478bd9Sstevel@tonic-gate uint32_t g;
18677c478bd9Sstevel@tonic-gate uint_t CRC;
18687c478bd9Sstevel@tonic-gate uint_t last_entry_offset;
1869*2570281cSToomas Soome int i;
18707c478bd9Sstevel@tonic-gate
18717c478bd9Sstevel@tonic-gate hal = (s1394_hal_t *)arg;
18727c478bd9Sstevel@tonic-gate
18737c478bd9Sstevel@tonic-gate /* Lock the Config ROM buffer */
18747c478bd9Sstevel@tonic-gate mutex_enter(&hal->local_config_rom_mutex);
18757c478bd9Sstevel@tonic-gate
18767c478bd9Sstevel@tonic-gate config_rom = hal->local_config_rom;
18777c478bd9Sstevel@tonic-gate
18787c478bd9Sstevel@tonic-gate /* Update Generation and CRC for Bus_Info_Block */
18797c478bd9Sstevel@tonic-gate
18807c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
18817c478bd9Sstevel@tonic-gate for (i = 0; i < IEEE1394_BIB_QUAD_SZ; i++)
18827c478bd9Sstevel@tonic-gate config_rom[i] = T1394_DATA32(config_rom[i]);
18837c478bd9Sstevel@tonic-gate
18847c478bd9Sstevel@tonic-gate bus_capabilities = config_rom[IEEE1212_NODE_CAP_QUAD];
18857c478bd9Sstevel@tonic-gate g = ((bus_capabilities & IEEE1394_BIB_GEN_MASK) >>
18867c478bd9Sstevel@tonic-gate IEEE1394_BIB_GEN_SHIFT) + 1;
18877c478bd9Sstevel@tonic-gate if (g > 15)
18887c478bd9Sstevel@tonic-gate g = 2;
18897c478bd9Sstevel@tonic-gate g = g << IEEE1394_BIB_GEN_SHIFT;
18907c478bd9Sstevel@tonic-gate
18917c478bd9Sstevel@tonic-gate bus_capabilities = (bus_capabilities & (~IEEE1394_BIB_GEN_MASK)) | g;
18927c478bd9Sstevel@tonic-gate config_rom[IEEE1212_NODE_CAP_QUAD] = bus_capabilities;
18937c478bd9Sstevel@tonic-gate
18947c478bd9Sstevel@tonic-gate CRC = s1394_CRC16(&config_rom[1], IEEE1394_BIB_QUAD_SZ - 1);
18957c478bd9Sstevel@tonic-gate config_rom[0] = (0x04040000) | CRC;
18967c478bd9Sstevel@tonic-gate
18977c478bd9Sstevel@tonic-gate /* Do byte-swapping if necessary (x86) */
18987c478bd9Sstevel@tonic-gate for (i = 0; i < IEEE1394_BIB_QUAD_SZ; i++)
18997c478bd9Sstevel@tonic-gate config_rom[i] = T1394_DATA32(config_rom[i]);
19007c478bd9Sstevel@tonic-gate
19017c478bd9Sstevel@tonic-gate /* Make sure we update only what is necessary */
19027c478bd9Sstevel@tonic-gate last_entry_offset = (IEEE1394_CONFIG_ROM_QUAD_SZ - hal->free_space);
19037c478bd9Sstevel@tonic-gate if (last_entry_offset < hal->config_rom_update_amount)
19047c478bd9Sstevel@tonic-gate last_entry_offset = hal->config_rom_update_amount;
19057c478bd9Sstevel@tonic-gate
19067c478bd9Sstevel@tonic-gate hal->config_rom_update_amount = (IEEE1394_CONFIG_ROM_QUAD_SZ -
19077c478bd9Sstevel@tonic-gate hal->free_space);
19087c478bd9Sstevel@tonic-gate
19097c478bd9Sstevel@tonic-gate /* Clear the timer flag */
19107c478bd9Sstevel@tonic-gate hal->config_rom_timer_set = B_FALSE;
19117c478bd9Sstevel@tonic-gate
19127c478bd9Sstevel@tonic-gate /* Unlock the Config ROM buffer */
19137c478bd9Sstevel@tonic-gate mutex_exit(&hal->local_config_rom_mutex);
19147c478bd9Sstevel@tonic-gate
19157c478bd9Sstevel@tonic-gate /*
19167c478bd9Sstevel@tonic-gate * The update_config_rom() call can return DDI_FAILURE if the
19177c478bd9Sstevel@tonic-gate * HAL is shutdown.
19187c478bd9Sstevel@tonic-gate */
19197c478bd9Sstevel@tonic-gate (void) HAL_CALL(hal).update_config_rom(hal->halinfo.hal_private,\
19207c478bd9Sstevel@tonic-gate config_rom, last_entry_offset);
19217c478bd9Sstevel@tonic-gate
19227c478bd9Sstevel@tonic-gate /* Initiate a bus reset */
1923*2570281cSToomas Soome (void) HAL_CALL(hal).bus_reset(hal->halinfo.hal_private);
19247c478bd9Sstevel@tonic-gate }
1925