usb_as.h revision 7492:2387323b838f
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 2008 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
33extern "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 */
42typedef 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
59typedef 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 */
82typedef 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	queue_t			*usb_as_rq;		/* read q ptr */
90	queue_t			*usb_as_wq;		/* write q ptr */
91	uint_t			usb_as_streams_flag;	/* streams status */
92
93	/* mblk containing the current control command */
94	mblk_t			*usb_as_def_mblk;
95
96	/* serialization */
97	usb_serialization_t	usb_as_ser_acc;
98
99	/* registration data */
100	usb_client_dev_data_t	*usb_as_dev_data;
101
102	/* info from descriptors per alternate */
103	uint_t			usb_as_n_alternates;
104	usb_as_alt_descr_t	*usb_as_alts;
105	uint_t			usb_as_alternate;
106
107	/* pipe handle */
108	usb_pipe_handle_t	usb_as_default_ph;
109
110	/* See below for flags */
111	uchar_t			usb_as_xfer_cr;
112
113	/* Isoc pipe stuff */
114	usb_pipe_handle_t	usb_as_isoc_ph;
115	usb_pipe_policy_t	usb_as_isoc_pp;
116	audiohdl_t		usb_as_ahdl;
117
118	uint_t			usb_as_request_count;
119	uint_t			usb_as_request_samples;
120	usb_audio_formats_t	usb_as_curr_format;
121
122	uint_t			usb_as_pkt_count;
123	ushort_t		usb_as_record_pkt_size;
124
125	uchar_t			usb_as_audio_state;
126	uchar_t			usb_as_setup_cnt;
127
128	usb_as_power_t		*usb_as_pm; /* power capabilities */
129
130	/* registration data */
131	usb_as_registration_t	usb_as_reg;
132
133	/* debug support */
134	uint_t			usb_as_send_debug_count;
135	uint_t			usb_as_rcv_debug_count;
136} usb_as_state_t;
137
138/* warlock directives, stable data */
139_NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_state_t))
140_NOTE(MUTEX_PROTECTS_DATA(usb_as_state_t::usb_as_mutex, usb_as_power_t))
141_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dip))
142_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_pm))
143_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_instance))
144_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_rq))
145_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_wq))
146_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_default_ph))
147_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_isoc_ph))
148_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_log_handle))
149_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_dev_data))
150_NOTE(DATA_READABLE_WITHOUT_LOCK(usb_as_state_t::usb_as_ser_acc))
151
152typedef struct usb_as_tq_arg {
153	usb_as_state_t	*usb_as_tq_arg_statep;
154	int		usb_as_tq_arg_cr;
155} usb_as_tq_arg_t;
156
157_NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_as_tq_arg_t))
158
159
160/* Default pipe states */
161#define	USB_AS_DEF_AVAILABLE	0
162#define	USB_AS_DEF_INUSE	1
163#define	USB_AS_DEF_UNAVAILABLE	2
164
165
166/*
167 * If a command has been initiated, the close callback should know
168 * how it finished. If there has been an error and ex cb initiaited
169 * the async pipe close, an M_ERROR should be sent up. If no error and
170 * default xfer cb had initiated close, M_CTL should be sent up. In
171 * some other cases, close callback may not send anything up.
172 */
173#define	USB_AS_SEND_MERR	1
174#define	USB_AS_SEND_MCTL	2
175#define	USB_AS_SEND_NONE	3
176
177
178/*
179 * States of playing/recording flag
180 */
181#define	USB_AS_IDLE			0
182#define	USB_AS_ACTIVE			1
183#define	USB_AS_PLAY_PAUSED		2
184#define	USB_AS_STOP_POLLING_STARTED	3
185
186/*
187 * Define constants needed for isoc transfer
188 */
189#define	USB_AS_N_FRAMES			8
190#define	USB_AS_MAX_REQUEST_COUNT	3
191
192/*
193 * usb_as turns the M_CTL request into a request control request on the
194 * default pipe.  usb_as needs the following information in the usb_as_req_t
195 * structure.  See the details below for specific values for each command.
196 */
197typedef struct usb_as_req {
198	uint16_t	usb_as_req_wValue;	/* wValue field of request */
199	uint16_t	usb_as_req_wIndex;	/* wIndex field of request */
200	uint16_t	usb_as_req_wLength;	/* wLength of request */
201	mblk_t		*usb_as_req_data;	/* data for send case */
202} usb_as_req_t;
203
204
205/* Streams status */
206#define	USB_AS_STREAMS_OPEN		1
207#define	USB_AS_STREAMS_DISMANTLING	2
208
209#define	USB_AS_BUFFER_SIZE		256	/* descriptor buffer size */
210
211/* minor node */
212#define	USB_AS_CONSTRUCT_MINOR(inst)	(inst)
213#define	USB_AS_MINOR_TO_INSTANCE(inst)	(inst)
214
215#ifdef __cplusplus
216}
217#endif
218
219#endif	/* _SYS_USB_AS_H */
220