1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #ifndef _SYS_USB_HWAHC_H
27 #define _SYS_USB_HWAHC_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33
34 #include <sys/usb/usba/wa.h>
35 #include <sys/usb/hubd/hub.h>
36 #include <sys/usb/hubd/hubdvar.h>
37 #include <sys/usb/usba/hcdi.h>
38 #include <sys/usb/usba/whcdi.h>
39 #include <sys/disp.h>
40 #include <sys/sunldi.h>
41
42 /*
43 * Power Management support
44 */
45 typedef struct hwahc_power {
46 void *hwahc_state; /* points back to hwahc_state */
47 uint8_t hwahc_pwr_states; /* bit mask of device pwr states */
48 int hwahc_pm_busy; /* device busy counting */
49 uint8_t hwahc_wakeup_enabled;
50
51 /* wakeup and power transistion capabilites of an interface */
52 uint8_t hwahc_pm_capabilities;
53
54 /* current power level the device is in */
55 uint8_t hwahc_current_power;
56 } hwahc_power_t;
57
58 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_power_t::hwahc_wakeup_enabled))
59
60 /* softstate init state */
61 #define HWAHC_LOCK_INITED 0x0001
62 #define HWAHC_HUBDI_REGISTERED 0x0002
63 #define HWAHC_MINOR_NODE_CREATED 0x0004
64 #define HWAHC_EVENTS_REGISTERED 0x0010
65 #define HWAHC_HUBREG 0x0020
66 #define HWAHC_WA_INITED 0x0040
67 #define HWAHC_HCDI_REGISTERED 0x0080
68 #define HWAHC_HC_INITED 0x0400
69 #define HWAHC_WA_STARTED 0x0800
70
71 /* hardware operation state */
72 #define HWAHC_HW_STOPPED 0
73 #define HWAHC_HW_STARTED 1
74 #define HWAHC_HW_CH_STOPPED 2
75 #define HWAHC_HW_CH_SUSPEND 3
76
77 /* Tracking events registered by children */
78 #define HWAHC_CHILD_EVENT_DISCONNECT 0x01
79 #define HWAHC_CHILD_EVENT_PRESUSPEND 0x02
80
81 /* Host controller software states */
82 #define HWAHC_CTRL_INIT_STATE 0 /* Initialization state */
83 #define HWAHC_CTRL_SUSPEND_STATE 1 /* Suspend state */
84 #define HWAHC_CTRL_OPERATIONAL_STATE 2 /* Operational state */
85 #define HWAHC_CTRL_ERROR_STATE 3 /* Error state */
86
87 /* Host controller pipe states */
88 #define HWAHC_PIPE_STATE_IDLE 1 /* Pipe is in ready state */
89 #define HWAHC_PIPE_STATE_ACTIVE 2 /* Pipe is in busy state */
90 #define HWAHC_PIPE_STATE_ERROR 3 /* Pipe is in error state */
91
92 /* Additional pipe states for the hwahc_pipe_cleanup */
93 #define HWAHC_PIPE_STATE_CLOSE 4 /* Pipe close */
94 #define HWAHC_PIPE_STATE_RESET 5 /* Pipe reset */
95 #define HWAHC_PIPE_STATE_STOP_POLLING 6 /* Pipe stop polling */
96
97 typedef struct hwahc_pipe_private {
98 usba_pipe_handle_data_t *pp_pipe_handle;
99 uint_t pp_state;
100 usb_pipe_policy_t pp_policy;
101 wusb_wa_rpipe_hdl_t *pp_rp;
102 wusb_dev_info_t *pp_wdev; /* parent device */
103
104 /*
105 * To support Intr/Isoc IN polling.
106 * Save the original client's request
107 */
108 usb_opaque_t pp_client_periodic_in_reqp;
109 kcondvar_t pp_xfer_cmpl_cv;
110 } hwahc_pipe_private_t;
111
112 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_pipe_private_t::pp_pipe_handle))
113 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_pipe_private_t::pp_rp))
114 _NOTE(DATA_READABLE_WITHOUT_LOCK(
115 hwahc_pipe_private_t::pp_client_periodic_in_reqp))
116
117 /*
118 * Softstate structure
119 */
120 typedef struct hwahc_state {
121 int hwahc_instance;
122 uint_t hwahc_flags;
123 uint_t hwahc_dev_state; /* USB device states */
124 usb_log_handle_t hwahc_log_handle;
125
126 hwahc_power_t *hwahc_pm;
127 dev_info_t *hwahc_dip; /* device info handle */
128
129 /* mutex to protect softstate and hw regs */
130 kmutex_t hwahc_mutex;
131
132 hubd_t *hwahc_hubd;
133 int hwahc_hw_state; /* hc start flag */
134 uint_t hwahc_open_count;
135
136 int hwahc_hc_soft_state; /* driver states. */
137
138 /* default pipe handle as a usba client device */
139 usb_pipe_handle_t hwahc_default_pipe;
140
141 uint_t hwahc_open_pipe_count;
142
143 /* wire adapter common data */
144 wusb_wa_data_t hwahc_wa_data;
145 wusb_secrt_data_t hwahc_secrt_data;
146
147 /* WUSB HC common data. hold HC and children info */
148 wusb_hc_data_t hwahc_hc_data;
149
150 /* for DN notification */
151 usba_list_entry_t hwahc_dn_notif_queue;
152 kthread_t *hwahc_notif_thread_id;
153
154 /* for transfer result notification */
155 kthread_t *hwahc_result_thread_id;
156 kcondvar_t hwahc_result_thread_cv;
157
158 int8_t hwahc_bus_pwr; /* bus power event count */
159
160 /* track event registration of children */
161 uint8_t hwahc_child_events[128];
162
163 ndi_event_hdl_t hwahc_ndi_event_hdl;
164
165 usb_client_dev_data_t *hwahc_dev_data; /* registration data */
166 usba_hcdi_ops_t *hwahc_hcdi_ops; /* HCDI structure */
167
168 } hwahc_state_t;
169
170 /* warlock directives */
171 _NOTE(MUTEX_PROTECTS_DATA(hwahc_state_t::hwahc_mutex, hwahc_state_t))
172 _NOTE(MUTEX_PROTECTS_DATA(hwahc_state_t::hwahc_mutex, hwahc_pipe_private_t))
173 _NOTE(MUTEX_PROTECTS_DATA(hwahc_state_t::hwahc_mutex,
174 hwahc_pipe_private_t::pp_state))
175 _NOTE(MUTEX_PROTECTS_DATA(hwahc_state_t::hwahc_mutex, hwahc_power_t))
176
177 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_state_t::hwahc_log_handle))
178 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_state_t::hwahc_wa_data))
179 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_state_t::hwahc_dip))
180 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_state_t::hwahc_default_pipe))
181 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_state_t::hwahc_ndi_event_hdl))
182 _NOTE(DATA_READABLE_WITHOUT_LOCK(hwahc_state_t::hwahc_pm
183 hwahc_state_t::hwahc_hubd))
184
185 _NOTE(SCHEME_PROTECTS_DATA("stable data", usb_ep_comp_descr))
186 _NOTE(SCHEME_PROTECTS_DATA("stable data", usba_device_t))
187
188 /* Debug masks */
189 #define PRINT_MASK_ATTA 0x00000001 /* Attach time */
190 #define PRINT_MASK_RPIPES 0x00000002 /* Rpipe management */
191 #define PRINT_MASK_HUB 0x00000004 /* Hub related stuff */
192 #define PRINT_MASK_EVENTS 0x00000008 /* Intr notification */
193 #define PRINT_MASK_SECURITY 0x00000020 /* Security info */
194 #define PRINT_MASK_CBOPS 0x00000040 /* CB-OPS */
195 #define PRINT_MASK_HCDI 0x00000080 /* HCDI entry points */
196 #define PRINT_MASK_DUMPING 0x00000100 /* Dump hwa info */
197 #define PRINT_MASK_OPEN 0x00000200 /* Open time */
198 #define PRINT_MASK_CLOSE 0x00000400 /* Close time */
199 #define PRINT_MASK_PM 0x00000800 /* For pwr mgmt */
200 #define PRINT_MASK_ALL 0xFFFFFFFF
201
202 #define HWAHC_MINOR_HUB_BITS_MASK 0xff
203 #define HWAHC_MINOR_INSTANCE_MASK ~HWAHC_MINOR_HUB_BITS_MASK
204 #define HWAHC_MINOR_INSTANCE_SHIFT 8
205
206 #define HWAHC_MINOR_TO_INSTANCE(minor) \
207 (((minor) & HWAHC_MINOR_INSTANCE_MASK) >> \
208 HWAHC_MINOR_INSTANCE_SHIFT)
209
210 #define HWAHC_CONSTRUCT_MINOR(inst) \
211 (inst << HWAHC_MINOR_INSTANCE_SHIFT)
212
213 /* base of MAC layer dev address for HWA class device */
214 #define HWAHC_DEV_ADDR_BASE 0xA100
215
216 typedef struct hwahc_dn_notif_list {
217 hwa_notif_dn_recvd_t *dn_notif;
218 usba_list_entry_t notif_list;
219 } hwahc_dn_notif_list_t;
220
221 _NOTE(MUTEX_PROTECTS_DATA(hwahc_state_t::hwahc_mutex, hwahc_dn_notif_list_t))
222
223 /* max elements in notification queue */
224 #define HWAHC_MAX_NOTIF 100
225
226 /* notification queue drain timeout - 60sec */
227 #define HWAHC_NOTIF_DRAIN_TIMEOUT 60
228
229 /*
230 * cfgadm state values
231 */
232 #define HWAHC_CFGADM_NORMAL 0 /* normal state */
233 #define HWAHC_CFGADM_DISCONNECTED 1 /* logically disconnected */
234 #define HWAHC_CFGADM_UNCONFIGURED 2 /* port is unconfigured */
235 #define HWAHC_CFGADM_EMPTY 3 /* port is empty */
236 #define HWAHC_CFGADM_STILL_REFERENCED 4 /* ndi_devi_offline failed */
237 #define HWAHC_CFGADM_CONFIGURED 5 /* port is configured */
238 #define HWAHC_CFGADM_INVALID 0xFF /* invalid state */
239
240 #ifdef __cplusplus
241 }
242 #endif
243
244 #endif /* _SYS_USB_HWAHC_H */