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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_USB_USBSER_DSDI_H
28 #define	_SYS_USB_USBSER_DSDI_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * USB-to-serial device-specific driver interface (DSDI)
34  */
35 
36 #include <sys/types.h>
37 #include <sys/dditypes.h>
38 #include <sys/usb/usba.h>
39 #include <sys/usb/usba/usbai_private.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 typedef void	*ds_hdl_t;	/* DSD device handler */
46 
47 /*
48  * interrupt emulation callbacks
49  */
50 typedef struct ds_cb {
51 	void		(*cb_tx)(caddr_t);	/* transmit callback */
52 	void		(*cb_rx)(caddr_t);	/* receive callback */
53 	void		(*cb_status)(caddr_t);	/* status change callback */
54 	caddr_t		cb_arg;			/* callback argument */
55 } ds_cb_t;
56 
57 typedef struct ds_port_params ds_port_params_t;	/* see below */
58 
59 typedef struct ds_attach_info {
60 	/*
61 	 * passed to DSD:
62 	 */
63 	dev_info_t	*ai_dip;	/* devinfo */
64 	/*
65 	 * these event callbacks should be registered by DSD
66 	 * using usb_register_event_cbs()
67 	 */
68 	usb_event_t	*ai_usb_events;
69 	/*
70 	 * returned by DSD:
71 	 */
72 	ds_hdl_t	*ai_hdl; /* handle to be used by GSD in other calls */
73 	uint_t		*ai_port_cnt;	/* number of ports */
74 } ds_attach_info_t;
75 
76 /*
77  * device operations used by Generic Serial Driver (GSD)
78  *
79  * ops returning int should return USB_SUCCESS on successful completion
80  * or appropriate USB_* error code in case of failure
81  *
82  * ops can block unless otherwise indicated
83  */
84 typedef struct ds_ops {
85 	int	ds_version;	/* structure version */
86 
87 	/*
88 	 * configuration operations
89 	 * ------------------------
90 	 *
91 	 * attach/detach device instance, called from GSD attach(9E)/detach(9E)
92 	 */
93 	int	(*ds_attach)(ds_attach_info_t *aip);
94 	void	(*ds_detach)(ds_hdl_t);
95 
96 	/*
97 	 * register/unregister interrupt callbacks for the given port
98 	 */
99 	int	(*ds_register_cb)(ds_hdl_t, uint_t port_num, ds_cb_t *cb);
100 	void	(*ds_unregister_cb)(ds_hdl_t, uint_t port_num);
101 
102 	/*
103 	 * open/close port
104 	 */
105 	int	(*ds_open_port)(ds_hdl_t, uint_t port_num);
106 	int	(*ds_close_port)(ds_hdl_t, uint_t port_num);
107 
108 	/*
109 	 * power management
110 	 * ----------------
111 	 *
112 	 * set power level of the component;
113 	 * DSD should set new_state to the resulting USB device state
114 	 */
115 	int	(*ds_usb_power)(ds_hdl_t, int comp, int level, int *new_state);
116 
117 	/*
118 	 * CPR suspend/resume
119 	 */
120 	int	(*ds_suspend)(ds_hdl_t);
121 	int	(*ds_resume)(ds_hdl_t);
122 
123 	/*
124 	 * USB device disconnect/reconnect
125 	 */
126 	int	(*ds_disconnect)(ds_hdl_t);
127 	int	(*ds_reconnect)(ds_hdl_t);
128 
129 	/*
130 	 * standard UART operations
131 	 * ------------------------
132 	 *
133 	 * set one or more port parameters: baud rate, parity,
134 	 * stop bits, character size, xon/xoff char, flow control
135 	 */
136 	int	(*ds_set_port_params)(ds_hdl_t, uint_t port_num,
137 			ds_port_params_t *tp);
138 
139 	/*
140 	 * set modem controls: each bit set to 1 in 'mask' will be set to the
141 	 * value of corresponding bit in 'val'; other bits are not affected
142 	 */
143 	int	(*ds_set_modem_ctl)(ds_hdl_t, uint_t port_num,
144 			int mask, int val);
145 
146 	/*
147 	 * get modem control/status: values of bits that correspond
148 	 * to those set to 1 in 'mask' are returned in 'valp'
149 	 */
150 	int	(*ds_get_modem_ctl)(ds_hdl_t, uint_t port_num,
151 			int mask, int *valp);
152 
153 	/*
154 	 * set/clear break ('ctl' is DS_ON/DS_OFF)
155 	 */
156 	int	(*ds_break_ctl)(ds_hdl_t, uint_t port_num, int ctl);
157 
158 	/*
159 	 * set/clear internal loopback ('ctl' is DS_ON/DS_OFF)
160 	 */
161 	int	(*ds_loopback)(ds_hdl_t, uint_t port_num, int ctl);
162 
163 	/*
164 	 * data xfer
165 	 * ---------
166 	 *
167 	 * data transmit: DSD is *required* to accept mblk for transfer and
168 	 * return USB_SUCCESS; after which GSD no longer owns the mblk
169 	 */
170 	int	(*ds_tx)(ds_hdl_t, uint_t port_num, mblk_t *mp);
171 
172 	/*
173 	 * data receipt: DSD returns either received data mblk or NULL
174 	 * if no data available. this op must not block as it is intended
175 	 * to be called from is usually called GSD receive callback
176 	 */
177 	mblk_t	*(*ds_rx)(ds_hdl_t, uint_t port_num);
178 
179 	/*
180 	 * stop/start data transmit or/and receive:
181 	 * 'dir' can be an OR of DS_TX and DS_RX; must succeed.
182 	 */
183 	void	(*ds_stop)(ds_hdl_t, uint_t port_num, int dir);
184 	void	(*ds_start)(ds_hdl_t, uint_t port_num, int dir);
185 
186 	/*
187 	 * flush FIFOs: 'dir' can be an OR of DS_TX and DS_RX,
188 	 * affecting transmit and received FIFO respectively
189 	 */
190 	int	(*ds_fifo_flush)(ds_hdl_t, uint_t port_num, int dir);
191 
192 	/*
193 	 * drain (wait until empty) output FIFO
194 	 *
195 	 * return failure if the FIFO does not get empty after at least
196 	 * 'timeout' seconds (zero timeout means wait forever)
197 	 */
198 	int	(*ds_fifo_drain)(ds_hdl_t, uint_t port_num, int timeout);
199 } ds_ops_t;
200 
201 /*
202  * ds_version
203  */
204 enum {
205 	DS_OPS_VERSION_V0	= 0,
206 	DS_OPS_VERSION		= DS_OPS_VERSION_V0
207 };
208 
209 /*
210  * parameter type
211  */
212 typedef enum {
213 	DS_PARAM_BAUD,		/* baud rate */
214 	DS_PARAM_PARITY,	/* parity */
215 	DS_PARAM_STOPB,		/* stop bits */
216 	DS_PARAM_CHARSZ,	/* char size */
217 	DS_PARAM_XON_XOFF,	/* xon/xoff chars */
218 	DS_PARAM_FLOW_CTL	/* flow control */
219 } ds_port_param_type_t;
220 
221 /*
222  * a single param entry, union used to pass various data types
223  */
224 typedef struct ds_port_param_entry {
225 	ds_port_param_type_t	param;	 /* parameter */
226 	union {
227 		uint_t		ui;
228 		uchar_t		uc[4];
229 	} val;			/* parameter value(s) */
230 } ds_port_param_entry_t;
231 
232 /*
233  * port parameter array
234  */
235 struct ds_port_params {
236 	ds_port_param_entry_t	*tp_entries;	/* entry array */
237 	int			tp_cnt;		/* entry count */
238 };
239 
240 /*
241  * direction (ds_fifo_flush, ds_fifo_drain)
242  */
243 enum {
244 	DS_TX		= 0x01,	/* transmit direction */
245 	DS_RX		= 0x02	/* receive direction */
246 };
247 
248 /*
249  * on/off (ds_break_ctl, ds_loopback)
250  */
251 enum {
252 	DS_OFF,
253 	DS_ON
254 };
255 
256 /*
257  * input error codes, returned by DSD in an M_BREAK message
258  */
259 enum {
260 	DS_PARITY_ERR	= 0x01,	/* parity error */
261 	DS_FRAMING_ERR	= 0x02,	/* framing error */
262 	DS_OVERRUN_ERR	= 0x03,	/* data overrun */
263 	DS_BREAK_ERR	= 0x04	/* break detected */
264 };
265 
266 #ifdef	__cplusplus
267 }
268 #endif
269 
270 #endif	/* _SYS_USB_USBSER_DSDI_H */
271