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
502acac7eSsl  * Common Development and Distribution License (the "License").
602acac7eSsl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22269552cdSguoqing zhu - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * Open Host Controller Driver (OHCI)
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * The USB Open Host Controller driver is a software driver which interfaces
317c478bd9Sstevel@tonic-gate  * to the Universal Serial Bus layer (USBA) and the USB Open Host Controller.
3229aca3ebSlc  * The interface to USB Open Host Controller is defined by the OpenHCI	Host
337c478bd9Sstevel@tonic-gate  * Controller Interface.
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * NOTE:
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * Currently OHCI driver does not support the following features
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * - Handle request with multiple TDs under short xfer conditions except for
407c478bd9Sstevel@tonic-gate  *   bulk transfers.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #include <sys/usb/hcd/openhci/ohcid.h>
437c478bd9Sstevel@tonic-gate 
4402acac7eSsl #include <sys/disp.h>
45d29f5a71Szhigang lu - Sun Microsystems - Beijing China #include <sys/strsun.h>
4602acac7eSsl 
477c478bd9Sstevel@tonic-gate /* Pointer to the state structure */
487c478bd9Sstevel@tonic-gate static void *ohci_statep;
497c478bd9Sstevel@tonic-gate 
502df1fe9cSrandyf int force_ohci_off = 1;
512df1fe9cSrandyf 
527c478bd9Sstevel@tonic-gate /* Number of instances */
537c478bd9Sstevel@tonic-gate #define	OHCI_INSTS	1
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /* Adjustable variables for the size of the pools */
564610e4a0Sfrits int ohci_ed_pool_size = OHCI_ED_POOL_SIZE;
574610e4a0Sfrits int ohci_td_pool_size = OHCI_TD_POOL_SIZE;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Initialize the values which are used for setting up head pointers for
617c478bd9Sstevel@tonic-gate  * the 32ms scheduling lists which starts from the HCCA.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate static uchar_t ohci_index[NUM_INTR_ED_LISTS / 2] = {0x0, 0x8, 0x4, 0xc,
647c478bd9Sstevel@tonic-gate 						0x2, 0xa, 0x6, 0xe,
657c478bd9Sstevel@tonic-gate 						0x1, 0x9, 0x5, 0xd,
667c478bd9Sstevel@tonic-gate 						0x3, 0xb, 0x7, 0xf};
677c478bd9Sstevel@tonic-gate /* Debugging information */
687c478bd9Sstevel@tonic-gate uint_t ohci_errmask	= (uint_t)PRINT_MASK_ALL;
697c478bd9Sstevel@tonic-gate uint_t ohci_errlevel	= USB_LOG_L2;
707c478bd9Sstevel@tonic-gate uint_t ohci_instance_debug = (uint_t)-1;
717c478bd9Sstevel@tonic-gate 
729c75c6bfSgovinda /*
739c75c6bfSgovinda  * OHCI MSI tunable:
749c75c6bfSgovinda  *
759c75c6bfSgovinda  * By default MSI is enabled on all supported platforms.
769c75c6bfSgovinda  */
779c75c6bfSgovinda boolean_t ohci_enable_msi = B_TRUE;
789c75c6bfSgovinda 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * HCDI entry points
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  * The Host Controller Driver Interfaces (HCDI) are the software interfaces
837c478bd9Sstevel@tonic-gate  * between the Universal Serial Bus Driver (USBA) and the Host	Controller
847c478bd9Sstevel@tonic-gate  * Driver (HCD). The HCDI interfaces or entry points are subject to change.
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_open(
877c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
887c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
897c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_close(
907c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
917c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
927c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_reset(
937c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
947c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
95269552cdSguoqing zhu - Sun Microsystems - Beijing China static void	ohci_hcdi_pipe_reset_data_toggle(
96269552cdSguoqing zhu - Sun Microsystems - Beijing China 				usba_pipe_handle_data_t	*ph);
977c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_ctrl_xfer(
987c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
997c478bd9Sstevel@tonic-gate 				usb_ctrl_req_t		*ctrl_reqp,
1007c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
1017c478bd9Sstevel@tonic-gate static int	ohci_hcdi_bulk_transfer_size(
1027c478bd9Sstevel@tonic-gate 				usba_device_t		*usba_device,
1037c478bd9Sstevel@tonic-gate 				size_t			*size);
1047c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_bulk_xfer(
1057c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
1067c478bd9Sstevel@tonic-gate 				usb_bulk_req_t		*bulk_reqp,
1077c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
1087c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_intr_xfer(
1097c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
1107c478bd9Sstevel@tonic-gate 				usb_intr_req_t		*intr_req,
1117c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
1127c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_stop_intr_polling(
1137c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
1147c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
115fffe0b30Sqz static int	ohci_hcdi_get_current_frame_number(
116fffe0b30Sqz 				usba_device_t		*usba_device,
117fffe0b30Sqz 				usb_frame_number_t	*frame_number);
118fffe0b30Sqz static int	ohci_hcdi_get_max_isoc_pkts(
119fffe0b30Sqz 				usba_device_t		*usba_device,
120fffe0b30Sqz 				uint_t		*max_isoc_pkts_per_request);
1217c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_isoc_xfer(
1227c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
1237c478bd9Sstevel@tonic-gate 				usb_isoc_req_t		*isoc_reqp,
1247c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
1257c478bd9Sstevel@tonic-gate static int	ohci_hcdi_pipe_stop_isoc_polling(
1267c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
1277c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * Internal Function Prototypes
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /* Host Controller Driver (HCD) initialization functions */
1347c478bd9Sstevel@tonic-gate static void	ohci_set_dma_attributes(ohci_state_t	*ohcip);
1357c478bd9Sstevel@tonic-gate static int	ohci_allocate_pools(ohci_state_t	*ohcip);
1367c478bd9Sstevel@tonic-gate static void	ohci_decode_ddi_dma_addr_bind_handle_result(
1377c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
1387c478bd9Sstevel@tonic-gate 				int			result);
1397c478bd9Sstevel@tonic-gate static int	ohci_map_regs(ohci_state_t		*ohcip);
1407c478bd9Sstevel@tonic-gate static int	ohci_register_intrs_and_init_mutex(
1417c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
1429c75c6bfSgovinda static int	ohci_add_intrs(ohci_state_t		*ohcip,
1439c75c6bfSgovinda 				int			intr_type);
1447c478bd9Sstevel@tonic-gate static int	ohci_init_ctlr(ohci_state_t		*ohcip);
1457c478bd9Sstevel@tonic-gate static int	ohci_init_hcca(ohci_state_t		*ohcip);
1467c478bd9Sstevel@tonic-gate static void	ohci_build_interrupt_lattice(
1477c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
1487c478bd9Sstevel@tonic-gate static int	ohci_take_control(ohci_state_t		*ohcip);
1497c478bd9Sstevel@tonic-gate static usba_hcdi_ops_t *ohci_alloc_hcdi_ops(
1507c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /* Host Controller Driver (HCD) deinitialization functions */
1537c478bd9Sstevel@tonic-gate static int	ohci_cleanup(ohci_state_t		*ohcip);
1549c75c6bfSgovinda static void	ohci_rem_intrs(ohci_state_t		*ohcip);
1557c478bd9Sstevel@tonic-gate static int	ohci_cpr_suspend(ohci_state_t		*ohcip);
1567c478bd9Sstevel@tonic-gate static int	ohci_cpr_resume(ohci_state_t		*ohcip);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /* Bandwidth Allocation functions */
1597c478bd9Sstevel@tonic-gate static int	ohci_allocate_bandwidth(ohci_state_t	*ohcip,
1607c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
1617c478bd9Sstevel@tonic-gate 				uint_t			*node);
1627c478bd9Sstevel@tonic-gate static void	ohci_deallocate_bandwidth(ohci_state_t	*ohcip,
1637c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
1647c478bd9Sstevel@tonic-gate static int	ohci_compute_total_bandwidth(
1657c478bd9Sstevel@tonic-gate 				usb_ep_descr_t		*endpoint,
1667c478bd9Sstevel@tonic-gate 				usb_port_status_t	port_status,
1677c478bd9Sstevel@tonic-gate 				uint_t			*bandwidth);
1687c478bd9Sstevel@tonic-gate static int	ohci_adjust_polling_interval(
1697c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
1707c478bd9Sstevel@tonic-gate 				usb_ep_descr_t		*endpoint,
1717c478bd9Sstevel@tonic-gate 				usb_port_status_t	port_status);
1727c478bd9Sstevel@tonic-gate static uint_t	ohci_lattice_height(uint_t		interval);
1737c478bd9Sstevel@tonic-gate static uint_t	ohci_lattice_parent(uint_t		node);
1747c478bd9Sstevel@tonic-gate static uint_t	ohci_leftmost_leaf(uint_t		node,
1757c478bd9Sstevel@tonic-gate 				uint_t			height);
1767c478bd9Sstevel@tonic-gate static uint_t	ohci_hcca_intr_index(
1777c478bd9Sstevel@tonic-gate 				uint_t			node);
1787c478bd9Sstevel@tonic-gate static uint_t	ohci_hcca_leaf_index(
1797c478bd9Sstevel@tonic-gate 				uint_t			leaf);
1807c478bd9Sstevel@tonic-gate static uint_t	ohci_pow_2(uint_t x);
1817c478bd9Sstevel@tonic-gate static uint_t	ohci_log_2(uint_t x);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /* Endpoint Descriptor (ED) related functions */
1847c478bd9Sstevel@tonic-gate static uint_t	ohci_unpack_endpoint(ohci_state_t	*ohcip,
1857c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
1867c478bd9Sstevel@tonic-gate static void	ohci_insert_ed(ohci_state_t		*ohcip,
1877c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
1887c478bd9Sstevel@tonic-gate static void	ohci_insert_ctrl_ed(
1897c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
1907c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
1917c478bd9Sstevel@tonic-gate static void	ohci_insert_bulk_ed(
1927c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
1937c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
1947c478bd9Sstevel@tonic-gate static void	ohci_insert_intr_ed(
1957c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
1967c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
1977c478bd9Sstevel@tonic-gate static void	ohci_insert_isoc_ed(
1987c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
1997c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
2007c478bd9Sstevel@tonic-gate static void	ohci_modify_sKip_bit(ohci_state_t	*ohcip,
2017c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
2027c478bd9Sstevel@tonic-gate 				skip_bit_t		action,
2037c478bd9Sstevel@tonic-gate 				usb_flags_t		flag);
2047c478bd9Sstevel@tonic-gate static void	ohci_remove_ed(ohci_state_t		*ohcip,
2057c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
2067c478bd9Sstevel@tonic-gate static void	ohci_remove_ctrl_ed(
2077c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2087c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
2097c478bd9Sstevel@tonic-gate static void	ohci_remove_bulk_ed(
2107c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2117c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
2127c478bd9Sstevel@tonic-gate static void	ohci_remove_periodic_ed(
2137c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2147c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
2157c478bd9Sstevel@tonic-gate static void	ohci_insert_ed_on_reclaim_list(
2167c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2177c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
2187c478bd9Sstevel@tonic-gate static void	ohci_detach_ed_from_list(
2197c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2207c478bd9Sstevel@tonic-gate 				ohci_ed_t		*ept,
2217c478bd9Sstevel@tonic-gate 				uint_t			ept_type);
2227c478bd9Sstevel@tonic-gate static ohci_ed_t *ohci_ed_iommu_to_cpu(
2237c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2247c478bd9Sstevel@tonic-gate 				uintptr_t		addr);
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate /* Transfer Descriptor (TD) related functions */
2277c478bd9Sstevel@tonic-gate static int	ohci_initialize_dummy(ohci_state_t	*ohcip,
2287c478bd9Sstevel@tonic-gate 				ohci_ed_t		*ept);
2297c478bd9Sstevel@tonic-gate static ohci_trans_wrapper_t *ohci_allocate_ctrl_resources(
2307c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2317c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
2327c478bd9Sstevel@tonic-gate 				usb_ctrl_req_t		*ctrl_reqp,
2337c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
2347c478bd9Sstevel@tonic-gate static void	ohci_insert_ctrl_req(
2357c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2367c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
2377c478bd9Sstevel@tonic-gate 				usb_ctrl_req_t		*ctrl_reqp,
2387c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
2397c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
2407c478bd9Sstevel@tonic-gate static ohci_trans_wrapper_t *ohci_allocate_bulk_resources(
2417c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2427c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
2437c478bd9Sstevel@tonic-gate 				usb_bulk_req_t		*bulk_reqp,
2447c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
2457c478bd9Sstevel@tonic-gate static void	ohci_insert_bulk_req(ohci_state_t	*ohcip,
2467c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
2477c478bd9Sstevel@tonic-gate 				usb_bulk_req_t		*bulk_reqp,
2487c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
2497c478bd9Sstevel@tonic-gate 				usb_flags_t		flags);
2507c478bd9Sstevel@tonic-gate static int	ohci_start_pipe_polling(ohci_state_t	*ohcip,
2517c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
2527c478bd9Sstevel@tonic-gate 				usb_flags_t		flags);
2537c478bd9Sstevel@tonic-gate static void	ohci_set_periodic_pipe_polling(
2547c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2557c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
2567c478bd9Sstevel@tonic-gate static ohci_trans_wrapper_t *ohci_allocate_intr_resources(
2577c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2587c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
2597c478bd9Sstevel@tonic-gate 				usb_intr_req_t		*intr_reqp,
2607c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
2617c478bd9Sstevel@tonic-gate static void	ohci_insert_intr_req(ohci_state_t	*ohcip,
2627c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
2637c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
2647c478bd9Sstevel@tonic-gate 				usb_flags_t		flags);
2657c478bd9Sstevel@tonic-gate static int	ohci_stop_periodic_pipe_polling(
2667c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2677c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
2687c478bd9Sstevel@tonic-gate 				usb_flags_t		flags);
2697c478bd9Sstevel@tonic-gate static ohci_trans_wrapper_t *ohci_allocate_isoc_resources(
2707c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2717c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
2727c478bd9Sstevel@tonic-gate 				usb_isoc_req_t		*isoc_reqp,
2737c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags);
2747c478bd9Sstevel@tonic-gate static int	ohci_insert_isoc_req(ohci_state_t	*ohcip,
2757c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
2767c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
2777c478bd9Sstevel@tonic-gate 				uint_t			flags);
27802acac7eSsl static int	ohci_insert_hc_td(ohci_state_t		*ohcip,
2797c478bd9Sstevel@tonic-gate 				uint_t			hctd_ctrl,
28002acac7eSsl 				uint32_t		hctd_dma_offs,
2817c478bd9Sstevel@tonic-gate 				size_t			hctd_length,
2827c478bd9Sstevel@tonic-gate 				uint32_t		hctd_ctrl_phase,
2837c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
2847c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
2857c478bd9Sstevel@tonic-gate static ohci_td_t *ohci_allocate_td_from_pool(
2867c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
2877c478bd9Sstevel@tonic-gate static void	ohci_fill_in_td(ohci_state_t		*ohcip,
2887c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
2897c478bd9Sstevel@tonic-gate 				ohci_td_t		*new_dummy,
2907c478bd9Sstevel@tonic-gate 				uint_t			hctd_ctrl,
29102acac7eSsl 				uint32_t		hctd_dma_offs,
2927c478bd9Sstevel@tonic-gate 				size_t			hctd_length,
2937c478bd9Sstevel@tonic-gate 				uint32_t		hctd_ctrl_phase,
2947c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
2957c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
2967c478bd9Sstevel@tonic-gate static void	ohci_init_itd(
2977c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
2987c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
2997c478bd9Sstevel@tonic-gate 				uint_t			hctd_ctrl,
30002acac7eSsl 				uint32_t		index,
3017c478bd9Sstevel@tonic-gate 				ohci_td_t		*td);
3027c478bd9Sstevel@tonic-gate static int	ohci_insert_td_with_frame_number(
3037c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3047c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
3057c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
3067c478bd9Sstevel@tonic-gate 				ohci_td_t		*current_td,
3077c478bd9Sstevel@tonic-gate 				ohci_td_t		*dummy_td);
3087c478bd9Sstevel@tonic-gate static void	ohci_insert_td_on_tw(ohci_state_t	*ohcip,
3097c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
3107c478bd9Sstevel@tonic-gate 				ohci_td_t		*td);
3113e1e1e62SToomas Soome static void	ohci_done_list_tds(ohci_state_t		*ohcip,
3127c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate /* Transfer Wrapper (TW) functions */
3157c478bd9Sstevel@tonic-gate static ohci_trans_wrapper_t  *ohci_create_transfer_wrapper(
3167c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3177c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
3187c478bd9Sstevel@tonic-gate 				size_t			length,
3197c478bd9Sstevel@tonic-gate 				uint_t			usb_flags);
32002acac7eSsl static ohci_trans_wrapper_t  *ohci_create_isoc_transfer_wrapper(
32102acac7eSsl 				ohci_state_t		*ohcip,
32202acac7eSsl 				ohci_pipe_private_t	*pp,
32302acac7eSsl 				size_t			length,
32402acac7eSsl 				usb_isoc_pkt_descr_t	*descr,
32502acac7eSsl 				ushort_t		pkt_count,
32629aca3ebSlc 				size_t			td_count,
32702acac7eSsl 				uint_t			usb_flags);
3289b58c2adSzhigang lu - Sun Microsystems - Beijing China int	ohci_allocate_tds_for_tw(
3297c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3307c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
3317c478bd9Sstevel@tonic-gate 				size_t			td_count);
3327c478bd9Sstevel@tonic-gate static ohci_trans_wrapper_t  *ohci_allocate_tw_resources(
3337c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3347c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
3357c478bd9Sstevel@tonic-gate 				size_t			length,
3367c478bd9Sstevel@tonic-gate 				usb_flags_t		usb_flags,
3377c478bd9Sstevel@tonic-gate 				size_t			td_count);
3387c478bd9Sstevel@tonic-gate static void	ohci_free_tw_tds_resources(
3397c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3407c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
3417c478bd9Sstevel@tonic-gate static void	ohci_start_xfer_timer(
3427c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3437c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
3447c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
3457c478bd9Sstevel@tonic-gate static void	ohci_stop_xfer_timer(
3467c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3477c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
3487c478bd9Sstevel@tonic-gate 				uint_t			flag);
3497c478bd9Sstevel@tonic-gate static void	ohci_xfer_timeout_handler(void		*arg);
3507c478bd9Sstevel@tonic-gate static void	ohci_remove_tw_from_timeout_list(
3517c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3527c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
3537c478bd9Sstevel@tonic-gate static void	ohci_start_timer(ohci_state_t		*ohcip);
3547c478bd9Sstevel@tonic-gate static void	ohci_free_dma_resources(ohci_state_t	*ohcip,
3557c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
3567c478bd9Sstevel@tonic-gate static void	ohci_free_tw(ohci_state_t		*ohcip,
3577c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
35802acac7eSsl static int	ohci_tw_rebind_cookie(
35902acac7eSsl 				ohci_state_t		*ohcip,
36002acac7eSsl 				ohci_pipe_private_t	*pp,
36102acac7eSsl 				ohci_trans_wrapper_t	*tw);
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate /* Interrupt Handling functions */
3649c75c6bfSgovinda static uint_t	ohci_intr(caddr_t			arg1,
3659c75c6bfSgovinda 				caddr_t			arg2);
3667c478bd9Sstevel@tonic-gate static void	ohci_handle_missed_intr(
3677c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
3687c478bd9Sstevel@tonic-gate static void	ohci_handle_ue(ohci_state_t		*ohcip);
3697c478bd9Sstevel@tonic-gate static void	ohci_handle_endpoint_reclaimation(
3707c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
3717c478bd9Sstevel@tonic-gate static void	ohci_traverse_done_list(
3727c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3737c478bd9Sstevel@tonic-gate 				ohci_td_t		*head_done_list);
3747c478bd9Sstevel@tonic-gate static ohci_td_t *ohci_reverse_done_list(
3757c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3767c478bd9Sstevel@tonic-gate 				ohci_td_t		*head_done_list);
3777c478bd9Sstevel@tonic-gate static usb_cr_t	ohci_parse_error(ohci_state_t		*ohcip,
3787c478bd9Sstevel@tonic-gate 				ohci_td_t		*td);
3797c478bd9Sstevel@tonic-gate static void	ohci_parse_isoc_error(
3807c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3817c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
3827c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
3837c478bd9Sstevel@tonic-gate 				ohci_td_t		*td);
3847c478bd9Sstevel@tonic-gate static usb_cr_t ohci_check_for_error(
3857c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3867c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
3877c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
3887c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
3897c478bd9Sstevel@tonic-gate 				uint_t			ctrl);
3907c478bd9Sstevel@tonic-gate static void	ohci_handle_error(
3917c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3927c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
3937c478bd9Sstevel@tonic-gate 				usb_cr_t		error);
3947c478bd9Sstevel@tonic-gate static int	ohci_cleanup_data_underrun(
3957c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
3967c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
3977c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
3987c478bd9Sstevel@tonic-gate 				ohci_td_t		*td);
3997c478bd9Sstevel@tonic-gate static void	ohci_handle_normal_td(
4007c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4017c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
4027c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
4037c478bd9Sstevel@tonic-gate static void	ohci_handle_ctrl_td(ohci_state_t	*ohcip,
4047c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4057c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
4067c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
4077c478bd9Sstevel@tonic-gate 				void			*);
4087c478bd9Sstevel@tonic-gate static void	ohci_handle_bulk_td(ohci_state_t	*ohcip,
4097c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4107c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
4117c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
4127c478bd9Sstevel@tonic-gate 				void			*);
4137c478bd9Sstevel@tonic-gate static void	ohci_handle_intr_td(ohci_state_t	*ohcip,
4147c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4157c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
4167c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
4177c478bd9Sstevel@tonic-gate 				void			*);
4187c478bd9Sstevel@tonic-gate static void	ohci_handle_one_xfer_completion(
4197c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4207c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
4217c478bd9Sstevel@tonic-gate static void	ohci_handle_isoc_td(ohci_state_t	*ohcip,
4227c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4237c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
4247c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
4257c478bd9Sstevel@tonic-gate 				void			*);
4267c478bd9Sstevel@tonic-gate static void	ohci_sendup_td_message(
4277c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4287c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4297c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
4307c478bd9Sstevel@tonic-gate 				ohci_td_t		*td,
4317c478bd9Sstevel@tonic-gate 				usb_cr_t		error);
432688b07c5Sgc static int	ohci_check_done_head(
433688b07c5Sgc 				ohci_state_t *ohcip,
434688b07c5Sgc 				ohci_td_t		*done_head);
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate /* Miscillaneous functions */
4377c478bd9Sstevel@tonic-gate static void	ohci_cpr_cleanup(
4387c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
4397c478bd9Sstevel@tonic-gate static usb_req_attrs_t ohci_get_xfer_attrs(ohci_state_t *ohcip,
4407c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4417c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
4427c478bd9Sstevel@tonic-gate static int	ohci_allocate_periodic_in_resource(
4437c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4447c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4457c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
4467c478bd9Sstevel@tonic-gate 				usb_flags_t		flags);
4477c478bd9Sstevel@tonic-gate static int	ohci_wait_for_sof(
4487c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip);
4497c478bd9Sstevel@tonic-gate static void	ohci_pipe_cleanup(
4507c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4517c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
4527c478bd9Sstevel@tonic-gate static void	ohci_wait_for_transfers_completion(
4537c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4547c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
4557c478bd9Sstevel@tonic-gate static void	ohci_check_for_transfers_completion(
4567c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4577c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp);
4587c478bd9Sstevel@tonic-gate static void	ohci_save_data_toggle(ohci_state_t	*ohcip,
4597c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
4607c478bd9Sstevel@tonic-gate static void	ohci_restore_data_toggle(ohci_state_t	*ohcip,
4617c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph);
4627c478bd9Sstevel@tonic-gate static void	ohci_deallocate_periodic_in_resource(
4637c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4647c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4657c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw);
4667c478bd9Sstevel@tonic-gate static void	ohci_do_client_periodic_in_req_callback(
4677c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4687c478bd9Sstevel@tonic-gate 				ohci_pipe_private_t	*pp,
4697c478bd9Sstevel@tonic-gate 				usb_cr_t		completion_reason);
4707c478bd9Sstevel@tonic-gate static void	ohci_hcdi_callback(
4717c478bd9Sstevel@tonic-gate 				usba_pipe_handle_data_t	*ph,
4727c478bd9Sstevel@tonic-gate 				ohci_trans_wrapper_t	*tw,
4737c478bd9Sstevel@tonic-gate 				usb_cr_t		completion_reason);
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate /* Kstat Support */
4767c478bd9Sstevel@tonic-gate static void	ohci_create_stats(ohci_state_t		*ohcip);
4773e1e1e62SToomas Soome static void	ohci_destroy_stats(ohci_state_t		*ohcip);
4787c478bd9Sstevel@tonic-gate static void	ohci_do_byte_stats(
4797c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4807c478bd9Sstevel@tonic-gate 				size_t			len,
4813e1e1e62SToomas Soome 				uint8_t			attr,
4823e1e1e62SToomas Soome 				uint8_t			addr);
4837c478bd9Sstevel@tonic-gate static void	ohci_do_intrs_stats(
4847c478bd9Sstevel@tonic-gate 				ohci_state_t		*ohcip,
4857c478bd9Sstevel@tonic-gate 				int			val);
4863e1e1e62SToomas Soome static void	ohci_print_op_regs(ohci_state_t		*ohcip);
4877c478bd9Sstevel@tonic-gate static void	ohci_print_ed(ohci_state_t		*ohcip,
4887c478bd9Sstevel@tonic-gate 				ohci_ed_t		*ed);
4897c478bd9Sstevel@tonic-gate static void	ohci_print_td(ohci_state_t		*ohcip,
4907c478bd9Sstevel@tonic-gate 				ohci_td_t		*td);
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate /* extern */
4937c478bd9Sstevel@tonic-gate int usba_hubdi_root_hub_power(dev_info_t *dip, int comp, int level);
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate /*
4967c478bd9Sstevel@tonic-gate  * Device operations (dev_ops) entries function prototypes.
4977c478bd9Sstevel@tonic-gate  *
4987c478bd9Sstevel@tonic-gate  * We use the hub cbops since all nexus ioctl operations defined so far will
4997c478bd9Sstevel@tonic-gate  * be executed by the root hub. The following are the Host Controller Driver
5007c478bd9Sstevel@tonic-gate  * (HCD) entry points.
5017c478bd9Sstevel@tonic-gate  *
5027c478bd9Sstevel@tonic-gate  * the open/close/ioctl functions call the corresponding usba_hubdi_*
5037c478bd9Sstevel@tonic-gate  * calls after looking up the dip thru the dev_t.
5047c478bd9Sstevel@tonic-gate  */
5057c478bd9Sstevel@tonic-gate static int	ohci_open(dev_t	*devp, int flags, int otyp, cred_t *credp);
5067c478bd9Sstevel@tonic-gate static int	ohci_close(dev_t dev, int flag, int otyp, cred_t *credp);
5077c478bd9Sstevel@tonic-gate static int	ohci_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
5087c478bd9Sstevel@tonic-gate 				cred_t *credp, int *rvalp);
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate static int	ohci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
5117c478bd9Sstevel@tonic-gate static int	ohci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
51219397407SSherry Moore static int	ohci_quiesce(dev_info_t *dip);
51319397407SSherry Moore 
5147c478bd9Sstevel@tonic-gate static int	ohci_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
5157c478bd9Sstevel@tonic-gate 				void *arg, void **result);
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate static struct cb_ops ohci_cb_ops = {
5187c478bd9Sstevel@tonic-gate 	ohci_open,			/* Open */
5197c478bd9Sstevel@tonic-gate 	ohci_close,			/* Close */
5207c478bd9Sstevel@tonic-gate 	nodev,				/* Strategy */
5217c478bd9Sstevel@tonic-gate 	nodev,				/* Print */
5227c478bd9Sstevel@tonic-gate 	nodev,				/* Dump */
5237c478bd9Sstevel@tonic-gate 	nodev,				/* Read */
5247c478bd9Sstevel@tonic-gate 	nodev,				/* Write */
5257c478bd9Sstevel@tonic-gate 	ohci_ioctl,			/* Ioctl */
5267c478bd9Sstevel@tonic-gate 	nodev,				/* Devmap */
5277c478bd9Sstevel@tonic-gate 	nodev,				/* Mmap */
5287c478bd9Sstevel@tonic-gate 	nodev,				/* Segmap */
5297c478bd9Sstevel@tonic-gate 	nochpoll,			/* Poll */
5307c478bd9Sstevel@tonic-gate 	ddi_prop_op,			/* cb_prop_op */
5317c478bd9Sstevel@tonic-gate 	NULL,				/* Streamtab */
5327c478bd9Sstevel@tonic-gate 	D_MP				/* Driver compatibility flag */
5337c478bd9Sstevel@tonic-gate };
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate static struct dev_ops ohci_ops = {
5367c478bd9Sstevel@tonic-gate 	DEVO_REV,			/* Devo_rev */
5377c478bd9Sstevel@tonic-gate 	0,				/* Refcnt */
5387c478bd9Sstevel@tonic-gate 	ohci_info,			/* Info */
5397c478bd9Sstevel@tonic-gate 	nulldev,			/* Identify */
5407c478bd9Sstevel@tonic-gate 	nulldev,			/* Probe */
5417c478bd9Sstevel@tonic-gate 	ohci_attach,			/* Attach */
5427c478bd9Sstevel@tonic-gate 	ohci_detach,			/* Detach */
5437c478bd9Sstevel@tonic-gate 	nodev,				/* Reset */
5447c478bd9Sstevel@tonic-gate 	&ohci_cb_ops,			/* Driver operations */
5457c478bd9Sstevel@tonic-gate 	&usba_hubdi_busops,		/* Bus operations */
54619397407SSherry Moore 	usba_hubdi_root_hub_power,	/* Power */
54719397407SSherry Moore 	ohci_quiesce,			/* Quiesce */
5487c478bd9Sstevel@tonic-gate };
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate /*
5517c478bd9Sstevel@tonic-gate  * The USBA library must be loaded for this driver.
5527c478bd9Sstevel@tonic-gate  */
5537c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
5543e1e1e62SToomas Soome 	&mod_driverops,		/* Type of module. This one is a driver */
5553e1e1e62SToomas Soome 	"USB OpenHCI Driver",	/* Name of the module. */
5567c478bd9Sstevel@tonic-gate 	&ohci_ops,		/* Driver ops */
5577c478bd9Sstevel@tonic-gate };
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
5607c478bd9Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
5617c478bd9Sstevel@tonic-gate };
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate int
_init(void)5657c478bd9Sstevel@tonic-gate _init(void)
5667c478bd9Sstevel@tonic-gate {
5677c478bd9Sstevel@tonic-gate 	int error;
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	/* Initialize the soft state structures */
5707c478bd9Sstevel@tonic-gate 	if ((error = ddi_soft_state_init(&ohci_statep, sizeof (ohci_state_t),
5717c478bd9Sstevel@tonic-gate 	    OHCI_INSTS)) != 0) {
5727c478bd9Sstevel@tonic-gate 		return (error);
5737c478bd9Sstevel@tonic-gate 	}
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	/* Install the loadable module */
5767c478bd9Sstevel@tonic-gate 	if ((error = mod_install(&modlinkage)) != 0) {
5777c478bd9Sstevel@tonic-gate 		ddi_soft_state_fini(&ohci_statep);
5787c478bd9Sstevel@tonic-gate 	}
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	return (error);
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)5857c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
5867c478bd9Sstevel@tonic-gate {
5877c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
5887c478bd9Sstevel@tonic-gate }
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate int
_fini(void)5927c478bd9Sstevel@tonic-gate _fini(void)
5937c478bd9Sstevel@tonic-gate {
5947c478bd9Sstevel@tonic-gate 	int error;
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate 	if ((error = mod_remove(&modlinkage)) == 0) {
5977c478bd9Sstevel@tonic-gate 		/* Release per module resources */
5987c478bd9Sstevel@tonic-gate 		ddi_soft_state_fini(&ohci_statep);
5997c478bd9Sstevel@tonic-gate 	}
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 	return (error);
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate /*
6067c478bd9Sstevel@tonic-gate  * Host Controller Driver (HCD) entry points
6077c478bd9Sstevel@tonic-gate  */
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate /*
6107c478bd9Sstevel@tonic-gate  * ohci_attach:
6117c478bd9Sstevel@tonic-gate  */
6127c478bd9Sstevel@tonic-gate static int
ohci_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)6133e1e1e62SToomas Soome ohci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
6147c478bd9Sstevel@tonic-gate {
6157c478bd9Sstevel@tonic-gate 	int			instance;
6167c478bd9Sstevel@tonic-gate 	ohci_state_t		*ohcip = NULL;
6177c478bd9Sstevel@tonic-gate 	usba_hcdi_register_args_t hcdi_args;
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate 	switch (cmd) {
6207c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
6217c478bd9Sstevel@tonic-gate 		break;
6227c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
6237c478bd9Sstevel@tonic-gate 		ohcip = ohci_obtain_state(dip);
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 		return (ohci_cpr_resume(ohcip));
6267c478bd9Sstevel@tonic-gate 	default:
6277c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6287c478bd9Sstevel@tonic-gate 	}
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 	/* Get the instance and create soft state */
6317c478bd9Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 	if (ddi_soft_state_zalloc(ohci_statep, instance) != 0) {
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6367c478bd9Sstevel@tonic-gate 	}
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 	ohcip = ddi_get_soft_state(ohci_statep, instance);
6397c478bd9Sstevel@tonic-gate 	if (ohcip == NULL) {
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6427c478bd9Sstevel@tonic-gate 	}
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	ohcip->ohci_flags = OHCI_ATTACH;
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	ohcip->ohci_log_hdl = usb_alloc_log_hdl(dip, "ohci", &ohci_errlevel,
6477c478bd9Sstevel@tonic-gate 	    &ohci_errmask, &ohci_instance_debug, 0);
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 	ohcip->ohci_flags |= OHCI_ZALLOC;
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	/* Set host controller soft state to initilization */
6527c478bd9Sstevel@tonic-gate 	ohcip->ohci_hc_soft_state = OHCI_CTLR_INIT_STATE;
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
6557c478bd9Sstevel@tonic-gate 	    "ohcip = 0x%p", (void *)ohcip);
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	/* Initialize the DMA attributes */
6587c478bd9Sstevel@tonic-gate 	ohci_set_dma_attributes(ohcip);
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	/* Save the dip and instance */
6617c478bd9Sstevel@tonic-gate 	ohcip->ohci_dip = dip;
6627c478bd9Sstevel@tonic-gate 	ohcip->ohci_instance = instance;
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate 	/* Initialize the kstat structures */
6657c478bd9Sstevel@tonic-gate 	ohci_create_stats(ohcip);
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 	/* Create the td and ed pools */
6687c478bd9Sstevel@tonic-gate 	if (ohci_allocate_pools(ohcip) != DDI_SUCCESS) {
6697c478bd9Sstevel@tonic-gate 		(void) ohci_cleanup(ohcip);
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6727c478bd9Sstevel@tonic-gate 	}
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	/* Map the registers */
6757c478bd9Sstevel@tonic-gate 	if (ohci_map_regs(ohcip) != DDI_SUCCESS) {
6767c478bd9Sstevel@tonic-gate 		(void) ohci_cleanup(ohcip);
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6797c478bd9Sstevel@tonic-gate 	}
6807c478bd9Sstevel@tonic-gate 
681af95cb89Szhigang lu - Sun Microsystems - Beijing China 	/* Get the ohci chip vendor and device id */
682af95cb89Szhigang lu - Sun Microsystems - Beijing China 	ohcip->ohci_vendor_id = pci_config_get16(
683af95cb89Szhigang lu - Sun Microsystems - Beijing China 	    ohcip->ohci_config_handle, PCI_CONF_VENID);
684af95cb89Szhigang lu - Sun Microsystems - Beijing China 	ohcip->ohci_device_id = pci_config_get16(
685af95cb89Szhigang lu - Sun Microsystems - Beijing China 	    ohcip->ohci_config_handle, PCI_CONF_DEVID);
686af95cb89Szhigang lu - Sun Microsystems - Beijing China 	ohcip->ohci_rev_id = pci_config_get8(
687af95cb89Szhigang lu - Sun Microsystems - Beijing China 	    ohcip->ohci_config_handle, PCI_CONF_REVID);
688af95cb89Szhigang lu - Sun Microsystems - Beijing China 
6897c478bd9Sstevel@tonic-gate 	/* Register interrupts */
6907c478bd9Sstevel@tonic-gate 	if (ohci_register_intrs_and_init_mutex(ohcip) != DDI_SUCCESS) {
6917c478bd9Sstevel@tonic-gate 		(void) ohci_cleanup(ohcip);
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6947c478bd9Sstevel@tonic-gate 	}
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	mutex_enter(&ohcip->ohci_int_mutex);
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 	/* Initialize the controller */
6997c478bd9Sstevel@tonic-gate 	if (ohci_init_ctlr(ohcip) != DDI_SUCCESS) {
7007c478bd9Sstevel@tonic-gate 		mutex_exit(&ohcip->ohci_int_mutex);
7017c478bd9Sstevel@tonic-gate 		(void) ohci_cleanup(ohcip);
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
7047c478bd9Sstevel@tonic-gate 	}
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 	/*
7077c478bd9Sstevel@tonic-gate 	 * At this point, the hardware wiil be okay.
7087c478bd9Sstevel@tonic-gate 	 * Initialize the usba_hcdi structure
7097c478bd9Sstevel@tonic-gate 	 */
7107c478bd9Sstevel@tonic-gate 	ohcip->ohci_hcdi_ops = ohci_alloc_hcdi_ops(ohcip);
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 	mutex_exit(&ohcip->ohci_int_mutex);
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	/*
7157c478bd9Sstevel@tonic-gate 	 * Make this HCD instance known to USBA
7167c478bd9Sstevel@tonic-gate 	 * (dma_attr must be passed for USBA busctl's)
7177c478bd9Sstevel@tonic-gate 	 */
7187c478bd9Sstevel@tonic-gate 	hcdi_args.usba_hcdi_register_version = HCDI_REGISTER_VERSION;
7197c478bd9Sstevel@tonic-gate 	hcdi_args.usba_hcdi_register_dip = dip;
7207c478bd9Sstevel@tonic-gate 	hcdi_args.usba_hcdi_register_ops = ohcip->ohci_hcdi_ops;
7217c478bd9Sstevel@tonic-gate 	hcdi_args.usba_hcdi_register_dma_attr = &ohcip->ohci_dma_attr;
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	/*
7247c478bd9Sstevel@tonic-gate 	 * Priority and iblock_cookie are one and the same
7257c478bd9Sstevel@tonic-gate 	 * (However, retaining hcdi_soft_iblock_cookie for now
7267c478bd9Sstevel@tonic-gate 	 * assigning it w/ priority. In future all iblock_cookie
7277c478bd9Sstevel@tonic-gate 	 * could just go)
7287c478bd9Sstevel@tonic-gate 	 */
7297c478bd9Sstevel@tonic-gate 	hcdi_args.usba_hcdi_register_iblock_cookie =
730abdbd06dSagiri 	    (ddi_iblock_cookie_t)(uintptr_t)ohcip->ohci_intr_pri;
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 	if (usba_hcdi_register(&hcdi_args, 0) != DDI_SUCCESS) {
7337c478bd9Sstevel@tonic-gate 		(void) ohci_cleanup(ohcip);
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
7367c478bd9Sstevel@tonic-gate 	}
7377c478bd9Sstevel@tonic-gate 	ohcip->ohci_flags |= OHCI_USBAREG;
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate 	mutex_enter(&ohcip->ohci_int_mutex);
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate 	if ((ohci_init_root_hub(ohcip)) != USB_SUCCESS) {
7427c478bd9Sstevel@tonic-gate 		mutex_exit(&ohcip->ohci_int_mutex);
7437c478bd9Sstevel@tonic-gate 		(void) ohci_cleanup(ohcip);
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
7467c478bd9Sstevel@tonic-gate 	}
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 	mutex_exit(&ohcip->ohci_int_mutex);
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 	/* Finally load the root hub driver */
7517c478bd9Sstevel@tonic-gate 	if (ohci_load_root_hub_driver(ohcip) != USB_SUCCESS) {
7527c478bd9Sstevel@tonic-gate 		(void) ohci_cleanup(ohcip);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
7557c478bd9Sstevel@tonic-gate 	}
7567c478bd9Sstevel@tonic-gate 	ohcip->ohci_flags |= OHCI_RHREG;
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate 	/* Display information in the banner */
7597c478bd9Sstevel@tonic-gate 	ddi_report_dev(dip);
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 	mutex_enter(&ohcip->ohci_int_mutex);
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate 	/* Reset the ohci initilization flag */
7647c478bd9Sstevel@tonic-gate 	ohcip->ohci_flags &= ~OHCI_ATTACH;
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate 	/* Print the Host Control's Operational registers */
7677c478bd9Sstevel@tonic-gate 	ohci_print_op_regs(ohcip);
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 	/* For RIO we need to call pci_report_pmcap */
7707c478bd9Sstevel@tonic-gate 	if (OHCI_IS_RIO(ohcip)) {
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 		(void) pci_report_pmcap(dip, PCI_PM_IDLESPEED, (void *)4000);
7737c478bd9Sstevel@tonic-gate 	}
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 	mutex_exit(&ohcip->ohci_int_mutex);
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
7787c478bd9Sstevel@tonic-gate 	    "ohci_attach: dip = 0x%p done", (void *)dip);
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate /*
7857c478bd9Sstevel@tonic-gate  * ohci_detach:
7867c478bd9Sstevel@tonic-gate  */
7877c478bd9Sstevel@tonic-gate int
ohci_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)7883e1e1e62SToomas Soome ohci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
7897c478bd9Sstevel@tonic-gate {
7907c478bd9Sstevel@tonic-gate 	ohci_state_t		*ohcip = ohci_obtain_state(dip);
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl, "ohci_detach:");
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	switch (cmd) {
7957c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 		return (ohci_cleanup(ohcip));
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 		return (ohci_cpr_suspend(ohcip));
8027c478bd9Sstevel@tonic-gate 	default:
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
8057c478bd9Sstevel@tonic-gate 	}
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate /*
8107c478bd9Sstevel@tonic-gate  * ohci_info:
8117c478bd9Sstevel@tonic-gate  */
8127c478bd9Sstevel@tonic-gate /* ARGSUSED */
8137c478bd9Sstevel@tonic-gate static int
ohci_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)8143e1e1e62SToomas Soome ohci_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
8157c478bd9Sstevel@tonic-gate {
8167c478bd9Sstevel@tonic-gate 	dev_t			dev;
8177c478bd9Sstevel@tonic-gate 	ohci_state_t		*ohcip;
8187c478bd9Sstevel@tonic-gate 	int			instance;
8197c478bd9Sstevel@tonic-gate 	int			error = DDI_FAILURE;
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 	switch (infocmd) {
8227c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
8237c478bd9Sstevel@tonic-gate 		dev = (dev_t)arg;
8247c478bd9Sstevel@tonic-gate 		instance = OHCI_UNIT(dev);
8257c478bd9Sstevel@tonic-gate 		ohcip = ddi_get_soft_state(ohci_statep, instance);
8267c478bd9Sstevel@tonic-gate 		if (ohcip != NULL) {
8277c478bd9Sstevel@tonic-gate 			*result = (void *)ohcip->ohci_dip;
8287c478bd9Sstevel@tonic-gate 			if (*result != NULL) {
8297c478bd9Sstevel@tonic-gate 				error = DDI_SUCCESS;
8307c478bd9Sstevel@tonic-gate 			}
8317c478bd9Sstevel@tonic-gate 		} else {
8327c478bd9Sstevel@tonic-gate 			*result = NULL;
8337c478bd9Sstevel@tonic-gate 		}
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate 		break;
8367c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
8377c478bd9Sstevel@tonic-gate 		dev = (dev_t)arg;
8387c478bd9Sstevel@tonic-gate 		instance = OHCI_UNIT(dev);
8397c478bd9Sstevel@tonic-gate 		*result = (void *)(uintptr_t)instance;
8407c478bd9Sstevel@tonic-gate 		error = DDI_SUCCESS;
8417c478bd9Sstevel@tonic-gate 		break;
8427c478bd9Sstevel@tonic-gate 	default:
8437c478bd9Sstevel@tonic-gate 		break;
8447c478bd9Sstevel@tonic-gate 	}
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 	return (error);
8477c478bd9Sstevel@tonic-gate }
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate /*
8517c478bd9Sstevel@tonic-gate  * cb_ops entry points
8527c478bd9Sstevel@tonic-gate  */
8537c478bd9Sstevel@tonic-gate static dev_info_t *
ohci_get_dip(dev_t dev)8543e1e1e62SToomas Soome ohci_get_dip(dev_t dev)
8557c478bd9Sstevel@tonic-gate {
8567c478bd9Sstevel@tonic-gate 	int		instance = OHCI_UNIT(dev);
8577c478bd9Sstevel@tonic-gate 	ohci_state_t	*ohcip = ddi_get_soft_state(ohci_statep, instance);
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 	if (ohcip) {
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate 		return (ohcip->ohci_dip);
8627c478bd9Sstevel@tonic-gate 	} else {
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate 		return (NULL);
8657c478bd9Sstevel@tonic-gate 	}
8667c478bd9Sstevel@tonic-gate }
8677c478bd9Sstevel@tonic-gate 
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate static int
ohci_open(dev_t * devp,int flags,int otyp,cred_t * credp)8703e1e1e62SToomas Soome ohci_open(dev_t *devp, int flags, int otyp, cred_t *credp)
8717c478bd9Sstevel@tonic-gate {
8727c478bd9Sstevel@tonic-gate 	dev_info_t	*dip = ohci_get_dip(*devp);
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate 	return (usba_hubdi_open(dip, devp, flags, otyp, credp));
8757c478bd9Sstevel@tonic-gate }
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate static int
ohci_close(dev_t dev,int flag,int otyp,cred_t * credp)8793e1e1e62SToomas Soome ohci_close(dev_t dev, int flag, int otyp, cred_t *credp)
8807c478bd9Sstevel@tonic-gate {
8817c478bd9Sstevel@tonic-gate 	dev_info_t	*dip = ohci_get_dip(dev);
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 	return (usba_hubdi_close(dip, dev, flag, otyp, credp));
8847c478bd9Sstevel@tonic-gate }
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate static int
ohci_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)8883e1e1e62SToomas Soome ohci_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
8893e1e1e62SToomas Soome     int *rvalp)
8907c478bd9Sstevel@tonic-gate {
8917c478bd9Sstevel@tonic-gate 	dev_info_t	*dip = ohci_get_dip(dev);
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 	return (usba_hubdi_ioctl(dip,
8947c478bd9Sstevel@tonic-gate 	    dev, cmd, arg, mode, credp, rvalp));
8957c478bd9Sstevel@tonic-gate }
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate /*
8997c478bd9Sstevel@tonic-gate  * Host Controller Driver (HCD) initialization functions
9007c478bd9Sstevel@tonic-gate  */
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate /*
9037c478bd9Sstevel@tonic-gate  * ohci_set_dma_attributes:
9047c478bd9Sstevel@tonic-gate  *
9057c478bd9Sstevel@tonic-gate  * Set the limits in the DMA attributes structure. Most of the values used
9067c478bd9Sstevel@tonic-gate  * in the  DMA limit structres are the default values as specified by  the
9077c478bd9Sstevel@tonic-gate  * Writing PCI device drivers document.
9087c478bd9Sstevel@tonic-gate  */
9097c478bd9Sstevel@tonic-gate static void
ohci_set_dma_attributes(ohci_state_t * ohcip)9107c478bd9Sstevel@tonic-gate ohci_set_dma_attributes(ohci_state_t	*ohcip)
9117c478bd9Sstevel@tonic-gate {
9127c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
9137c478bd9Sstevel@tonic-gate 	    "ohci_set_dma_attributes:");
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate 	/* Initialize the DMA attributes */
9167c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_version = DMA_ATTR_V0;
9177c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_addr_lo = 0x00000000ull;
9187c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_addr_hi = 0xfffffffeull;
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate 	/* 32 bit addressing */
9217c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_count_max = OHCI_DMA_ATTR_COUNT_MAX;
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 	/* Byte alignment */
9247c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_align = OHCI_DMA_ATTR_ALIGNMENT;
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate 	/*
9277c478bd9Sstevel@tonic-gate 	 * Since PCI  specification is byte alignment, the
9287c478bd9Sstevel@tonic-gate 	 * burstsize field should be set to 1 for PCI devices.
9297c478bd9Sstevel@tonic-gate 	 */
9307c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_burstsizes = 0x1;
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_minxfer = 0x1;
9337c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_maxxfer = OHCI_DMA_ATTR_MAX_XFER;
9347c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_seg = 0xffffffffull;
9357c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_sgllen = 1;
9367c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_granular = OHCI_DMA_ATTR_GRANULAR;
9377c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_flags = 0;
9387c478bd9Sstevel@tonic-gate }
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 
9417c478bd9Sstevel@tonic-gate /*
9427c478bd9Sstevel@tonic-gate  * ohci_allocate_pools:
9437c478bd9Sstevel@tonic-gate  *
9447c478bd9Sstevel@tonic-gate  * Allocate the system memory for the Endpoint Descriptor (ED) and for the
9457c478bd9Sstevel@tonic-gate  * Transfer Descriptor (TD) pools. Both ED and TD structures must be aligned
9467c478bd9Sstevel@tonic-gate  * to a 16 byte boundary.
9477c478bd9Sstevel@tonic-gate  */
9487c478bd9Sstevel@tonic-gate static int
ohci_allocate_pools(ohci_state_t * ohcip)9497c478bd9Sstevel@tonic-gate ohci_allocate_pools(ohci_state_t	*ohcip)
9507c478bd9Sstevel@tonic-gate {
9517c478bd9Sstevel@tonic-gate 	ddi_device_acc_attr_t		dev_attr;
9527c478bd9Sstevel@tonic-gate 	size_t				real_length;
9537c478bd9Sstevel@tonic-gate 	int				result;
9547c478bd9Sstevel@tonic-gate 	uint_t				ccount;
9557c478bd9Sstevel@tonic-gate 	int				i;
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
9587c478bd9Sstevel@tonic-gate 	    "ohci_allocate_pools:");
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate 	/* The host controller will be little endian */
9617c478bd9Sstevel@tonic-gate 	dev_attr.devacc_attr_version	= DDI_DEVICE_ATTR_V0;
9627c478bd9Sstevel@tonic-gate 	dev_attr.devacc_attr_endian_flags  = DDI_STRUCTURE_LE_ACC;
9637c478bd9Sstevel@tonic-gate 	dev_attr.devacc_attr_dataorder	= DDI_STRICTORDER_ACC;
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	/* Byte alignment to TD alignment */
9667c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_align = OHCI_DMA_ATTR_TD_ALIGNMENT;
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 	/* Allocate the TD pool DMA handle */
9697c478bd9Sstevel@tonic-gate 	if (ddi_dma_alloc_handle(ohcip->ohci_dip, &ohcip->ohci_dma_attr,
97029aca3ebSlc 	    DDI_DMA_SLEEP, 0,
97129aca3ebSlc 	    &ohcip->ohci_td_pool_dma_handle) != DDI_SUCCESS) {
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
9747c478bd9Sstevel@tonic-gate 	}
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	/* Allocate the memory for the TD pool */
9777c478bd9Sstevel@tonic-gate 	if (ddi_dma_mem_alloc(ohcip->ohci_td_pool_dma_handle,
97829aca3ebSlc 	    ohci_td_pool_size * sizeof (ohci_td_t),
97929aca3ebSlc 	    &dev_attr,
98029aca3ebSlc 	    DDI_DMA_CONSISTENT,
98129aca3ebSlc 	    DDI_DMA_SLEEP,
98229aca3ebSlc 	    0,
98329aca3ebSlc 	    (caddr_t *)&ohcip->ohci_td_pool_addr,
98429aca3ebSlc 	    &real_length,
98529aca3ebSlc 	    &ohcip->ohci_td_pool_mem_handle)) {
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
9887c478bd9Sstevel@tonic-gate 	}
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate 	/* Map the TD pool into the I/O address space */
9917c478bd9Sstevel@tonic-gate 	result = ddi_dma_addr_bind_handle(
99229aca3ebSlc 	    ohcip->ohci_td_pool_dma_handle,
99329aca3ebSlc 	    NULL,
99429aca3ebSlc 	    (caddr_t)ohcip->ohci_td_pool_addr,
99529aca3ebSlc 	    real_length,
99629aca3ebSlc 	    DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
99729aca3ebSlc 	    DDI_DMA_SLEEP,
99829aca3ebSlc 	    NULL,
99929aca3ebSlc 	    &ohcip->ohci_td_pool_cookie,
100029aca3ebSlc 	    &ccount);
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate 	bzero((void *)ohcip->ohci_td_pool_addr,
100329aca3ebSlc 	    ohci_td_pool_size * sizeof (ohci_td_t));
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate 	/* Process the result */
10067c478bd9Sstevel@tonic-gate 	if (result == DDI_DMA_MAPPED) {
10077c478bd9Sstevel@tonic-gate 		/* The cookie count should be 1 */
10087c478bd9Sstevel@tonic-gate 		if (ccount != 1) {
10097c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
10107c478bd9Sstevel@tonic-gate 			    "ohci_allocate_pools: More than 1 cookie");
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
10137c478bd9Sstevel@tonic-gate 		}
10147c478bd9Sstevel@tonic-gate 	} else {
10157c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L4(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
10167c478bd9Sstevel@tonic-gate 		    "ohci_allocate_pools: Result = %d", result);
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 		ohci_decode_ddi_dma_addr_bind_handle_result(ohcip, result);
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
10217c478bd9Sstevel@tonic-gate 	}
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 	/*
10247c478bd9Sstevel@tonic-gate 	 * DMA addresses for TD pools are bound
10257c478bd9Sstevel@tonic-gate 	 */
10267c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_addr_bind_flag |= OHCI_TD_POOL_BOUND;
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	/* Initialize the TD pool */
10297c478bd9Sstevel@tonic-gate 	for (i = 0; i < ohci_td_pool_size; i ++) {
10307c478bd9Sstevel@tonic-gate 		Set_TD(ohcip->ohci_td_pool_addr[i].hctd_state, HC_TD_FREE);
10317c478bd9Sstevel@tonic-gate 	}
10327c478bd9Sstevel@tonic-gate 
10337c478bd9Sstevel@tonic-gate 	/* Byte alignment to ED alignment */
10347c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_attr.dma_attr_align = OHCI_DMA_ATTR_ED_ALIGNMENT;
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 	/* Allocate the ED pool DMA handle */
10377c478bd9Sstevel@tonic-gate 	if (ddi_dma_alloc_handle(ohcip->ohci_dip,
103829aca3ebSlc 	    &ohcip->ohci_dma_attr,
103929aca3ebSlc 	    DDI_DMA_SLEEP,
104029aca3ebSlc 	    0,
104129aca3ebSlc 	    &ohcip->ohci_ed_pool_dma_handle) != DDI_SUCCESS) {
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
10447c478bd9Sstevel@tonic-gate 	}
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 	/* Allocate the memory for the ED pool */
10477c478bd9Sstevel@tonic-gate 	if (ddi_dma_mem_alloc(ohcip->ohci_ed_pool_dma_handle,
104829aca3ebSlc 	    ohci_ed_pool_size * sizeof (ohci_ed_t),
104929aca3ebSlc 	    &dev_attr,
105029aca3ebSlc 	    DDI_DMA_CONSISTENT,
105129aca3ebSlc 	    DDI_DMA_SLEEP,
105229aca3ebSlc 	    0,
105329aca3ebSlc 	    (caddr_t *)&ohcip->ohci_ed_pool_addr,
105429aca3ebSlc 	    &real_length,
105529aca3ebSlc 	    &ohcip->ohci_ed_pool_mem_handle) != DDI_SUCCESS) {
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
10587c478bd9Sstevel@tonic-gate 	}
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate 	result = ddi_dma_addr_bind_handle(ohcip->ohci_ed_pool_dma_handle,
106129aca3ebSlc 	    NULL,
106229aca3ebSlc 	    (caddr_t)ohcip->ohci_ed_pool_addr,
106329aca3ebSlc 	    real_length,
106429aca3ebSlc 	    DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
106529aca3ebSlc 	    DDI_DMA_SLEEP,
106629aca3ebSlc 	    NULL,
106729aca3ebSlc 	    &ohcip->ohci_ed_pool_cookie,
106829aca3ebSlc 	    &ccount);
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate 	bzero((void *)ohcip->ohci_ed_pool_addr,
107129aca3ebSlc 	    ohci_ed_pool_size * sizeof (ohci_ed_t));
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate 	/* Process the result */
10747c478bd9Sstevel@tonic-gate 	if (result == DDI_DMA_MAPPED) {
10757c478bd9Sstevel@tonic-gate 		/* The cookie count should be 1 */
10767c478bd9Sstevel@tonic-gate 		if (ccount != 1) {
10777c478bd9Sstevel@tonic-gate 			USB_DPRINTF_L2(PRINT_MASK_ATTA, ohcip->ohci_log_hdl,
10787c478bd9Sstevel@tonic-gate 			    "ohci_allocate_pools: More than 1 cookie");
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
10817c478bd9Sstevel@tonic-gate 		}
10827c478bd9Sstevel@tonic-gate 	} else {
10837c478bd9Sstevel@tonic-gate 		ohci_decode_ddi_dma_addr_bind_handle_result(ohcip, result);
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
10867c478bd9Sstevel@tonic-gate 	}
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate 	/*
10897c478bd9Sstevel@tonic-gate 	 * DMA addresses for ED pools are bound
10907c478bd9Sstevel@tonic-gate 	 */
10917c478bd9Sstevel@tonic-gate 	ohcip->ohci_dma_addr_bind_flag |= OHCI_ED_POOL_BOUND;
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate 	/* Initialize the ED pool */
10947c478bd9Sstevel@tonic-gate 	for (i = 0; i < ohci_ed_pool_size; i ++) {
10957c478bd9Sstevel@tonic-gate 		Set_ED(ohcip->ohci_ed_pool_addr[i].hced_state, HC_EPT_FREE);
10967c478bd9Sstevel@tonic-gate 	}
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
10997c478bd9Sstevel@tonic-gate }
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate 
11027c478bd9Sstevel@tonic-gate /*
11037c478bd9Sstevel@tonic-gate  * ohci_decode_ddi_dma_addr_bind_handle_result:
11047c478bd9Sstevel@tonic-gate  *
11057c478bd9Sstevel@tonic-gate  * Process the return values of ddi_dma_addr_bind_handle()
11067c478bd9Sstevel@tonic-gate  */
11077c478bd9Sstevel@tonic-gate static void
ohci_decode_ddi_dma_addr_bind_handle_result(ohci_state_t * ohcip,int result)11087c478bd9Sstevel@tonic-gate ohci_decode_ddi_dma_addr_bind_handle_result(
11097c478bd9Sstevel@tonic-gate 	ohci_state_t	*ohcip,
11107c478bd9Sstevel@tonic-gate 	int		result)
11117c478bd9Sstevel@tonic-gate {
11127c478bd9Sstevel@tonic-gate 	USB_DPRINTF_L2(PRINT_MASK_ALLOC, ohcip->ohci_log_hdl,
11137c478bd9Sstevel@tonic-gate 	    "ohci_decode_ddi_dma_addr_bind_handle_result:");
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate 	switch (result) {
11167c478bd9Sstevel@tonic-gate 	case DDI_DMA_PARTIAL_MAP:
11177c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_ALL, ohcip->ohci_log_hdl,
11187c478bd9Sstevel@tonic-gate 		    "Partial transfers not allowed");
11197c478bd9Sstevel@tonic-gate 		break;
11207c478bd9Sstevel@tonic-gate 	case DDI_DMA_INUSE:
11217c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_ALL,	ohcip->ohci_log_hdl,
11227c478bd9Sstevel@tonic-gate 		    "Handle is in use");
11237c478bd9Sstevel@tonic-gate 		break;
11247c478bd9Sstevel@tonic-gate 	case DDI_DMA_NORESOURCES:
11257c478bd9Sstevel@tonic-gate 		USB_DPRINTF_L2(PRINT_MASK_ALL,	ohcip->ohci_log_hdl,
1126