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_AS_H
27 #define	_SYS_USB_AS_H
28 
29 
30 #include <sys/usb/usba/usbai_private.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* driver specific macros */
37 #define	USB_AS_HIWATER		(AM_MAX_QUEUED_MSGS_SIZE)
38 #define	USB_AS_LOWATER		(32*1024)
39 
40 
41 /* this structure is built from the descriptors */
42 typedef struct usb_as_alt_descr {
43 	uchar_t				alt_mode; /* USB_AUDIO_PLAY/RECORD */
44 	uchar_t				alt_valid;
45 	uchar_t				alt_format_len;
46 
47 	uchar_t				alt_n_sample_rates;
48 	uint_t				*alt_sample_rates;
49 	uint_t				alt_continuous_sr;
50 
51 	usb_if_descr_t			*alt_if;
52 	usb_audio_as_if_descr_t 	*alt_general;
53 	usb_audio_type1_format_descr_t	*alt_format;
54 	usb_ep_descr_t			*alt_ep;
55 	usb_audio_as_isoc_ep_descr_t	*alt_cs_ep;
56 } usb_as_alt_descr_t;
57 
58 
59 typedef struct usb_as_power {
60 	void		*aspm_state;	/* points back to usb_as_state */
61 	int		aspm_pm_busy;	/* device busy accounting */
62 	uint8_t		aspm_wakeup_enabled;
63 
64 	/* this is the bit mask of the power states that device has */
65 	uint8_t		aspm_pwr_states;
66 
67 	/* wakeup and power transistion capabilites of an interface */
68 	uint8_t		aspm_capabilities;
69 
70 	/* current power level the device is in */
71 	uint8_t		aspm_current_power;
72 } usb_as_power_t;
73 
74 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_state))
75 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_wakeup_enabled))
76 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_pwr_states))
77 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_power_t::aspm_capabilities))
78 _NOTE(SCHEME_PROTECTS_DATA("unshared", usb_ctrl_req))
79 
80 
81 /* usb_as soft state */
82 typedef struct usb_as_state {
83 	dev_info_t		*usb_as_dip;
84 	uint_t			usb_as_instance;
85 	usb_log_handle_t	usb_as_log_handle;
86 	uint_t			usb_as_dev_state;
87 	uint_t			usb_as_ifno;
88 	kmutex_t		usb_as_mutex;
89 	uint_t			usb_as_flag;		/* status */
90 
91 	/* mblk containing the current control command */
92 	mblk_t			*usb_as_def_mblk;
93 
94 	/* serialization */
95 	usb_serialization_t	usb_as_ser_acc;
96 
97 	/* registration data */
98 	usb_client_dev_data_t	*usb_as_dev_data;
99 
100 	/* info from descriptors per alternate */
101 	uint_t			usb_as_n_alternates;
102 	usb_as_alt_descr_t	*usb_as_alts;
103 	uint_t			usb_as_alternate;
104 
105 	/* pipe handle */
106 	usb_pipe_handle_t	usb_as_default_ph;
107 
108 	/* See below for flags */
109 	uchar_t			usb_as_xfer_cr;
110 
111 	/* Isoc pipe stuff */
112 	usb_pipe_handle_t	usb_as_isoc_ph;
113 	usb_pipe_policy_t	usb_as_isoc_pp;
114 	audiohdl_t		usb_as_ahdl;
115 
116 	uint_t			usb_as_request_count;
117 	uint_t			usb_as_request_samples;
118 	usb_audio_formats_t	usb_as_curr_format;
119 
120 	uint_t			usb_as_pkt_count;
121 	ushort_t		usb_as_record_pkt_size;
122 
123 	uchar_t			usb_as_audio_state;
124 	uchar_t			usb_as_setup_cnt;
125 
126 	usb_as_power_t		*usb_as_pm; /* power capabilities */
127 
128 	/* registration data */
129 	usb_as_registration_t	usb_as_reg;
130 
131 	/* debug support */
132 	uint_t			usb_as_send_debug_count;
133 	uint_t			usb_as_rcv_debug_count;
134 	char			dstr[64];
135 } usb_as_state_t;
136 
137 /* warlock directives, stable data */
138 _NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_state_t))
139 _NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_power_t))
140 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dip))
141 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_pm))
142 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_instance))
143 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_default_ph))
144 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_isoc_ph))
145 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_log_handle))
146 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dev_data))
147 _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_ser_acc))
148 
149 typedef struct usb_as_tq_arg {
150 	usb_as_state_t	*usb_as_tq_arg_statep;
151 	int		usb_as_tq_arg_cr;
152 } usb_as_tq_arg_t;
153 
154 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_as_tq_arg_t))
155 
156 
157 /* Default pipe states */
158 #define	USB_AS_DEF_AVAILABLE	0
159 #define	USB_AS_DEF_INUSE	1
160 #define	USB_AS_DEF_UNAVAILABLE	2
161 
162 
163 /*
164  * If a command has been initiated, the close callback should know
165  * how it finished. If there has been an error and ex cb initiaited
166  * the async pipe close, an M_ERROR should be sent up. If no error and
167  * default xfer cb had initiated close, M_CTL should be sent up. In
168  * some other cases, close callback may not send anything up.
169  */
170 #define	USB_AS_SEND_MERR	1
171 #define	USB_AS_SEND_MCTL	2
172 #define	USB_AS_SEND_NONE	3
173 
174 
175 /*
176  * States of playing/recording flag
177  */
178 #define	USB_AS_IDLE			0
179 #define	USB_AS_ACTIVE			1
180 #define	USB_AS_PLAY_PAUSED		2
181 #define	USB_AS_STOP_POLLING_STARTED	3
182 
183 /*
184  * Define constants needed for isoc transfer
185  */
186 #define	USB_AS_N_FRAMES			8
187 #define	USB_AS_MAX_REQUEST_COUNT	3
188 
189 /*
190  * usb_as turns the M_CTL request into a request control request on the
191  * default pipe.  usb_as needs the following information in the usb_as_req_t
192  * structure.  See the details below for specific values for each command.
193  */
194 typedef struct usb_as_req {
195 	uint16_t	usb_as_req_wValue;	/* wValue field of request */
196 	uint16_t	usb_as_req_wIndex;	/* wIndex field of request */
197 	uint16_t	usb_as_req_wLength;	/* wLength of request */
198 	mblk_t		*usb_as_req_data;	/* data for send case */
199 } usb_as_req_t;
200 
201 
202 /* status */
203 #define	USB_AS_OPEN		1
204 #define	USB_AS_DISMANTLING	2
205 
206 #define	USB_AS_BUFFER_SIZE		256	/* descriptor buffer size */
207 
208 /* minor node */
209 #define	USB_AS_CONSTRUCT_MINOR(inst)	(inst)
210 #define	USB_AS_MINOR_TO_INSTANCE(inst)	(inst)
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif	/* _SYS_USB_AS_H */
217