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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #ifndef _SYS_USB_USBSER_KEYSPAN_USA49MSG_H
31 #define	_SYS_USB_USBSER_KEYSPAN_USA49MSG_H
32 
33 typedef struct keyspan_usa49_port_ctrl_msg keyspan_usa49_port_ctrl_msg_t;
34 typedef struct keyspan_usa49_port_status_msg keyspan_usa49_port_status_msg_t;
35 
36 /*
37  * usa49msg.h
38  *
39  * Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
40  * This file is available under a BSD-style copyright
41  *
42  * Keyspan USB Async Message Formats for the USA49W
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions are
46  * met:
47  *
48  * 1. Redistributions of source code must retain this licence text
49  * without modification, this list of conditions, and the following
50  * disclaimer.	The following copyright notice must appear immediately at
51  * the beginning of all source files:
52  *
53  * Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
54  *
55  * This file is available under a BSD-style copyright
56  *
57  * 2. The name of InnoSys Incorporated may not be used to endorse or promote
58  * products derived from this software without specific prior written
59  * permission.
60  *
61  * THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR
62  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
63  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
64  * NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
65  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
66  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
67  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
68  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71  * SUCH DAMAGE.
72  *
73  * 4th revision: USA49W version
74  *
75  * Buffer formats for RX/TX data messages are not defined by
76  * a structure, but are described here:
77  *
78  * USB OUT (host -> USAxx, transmit) messages contain a
79  * REQUEST_ACK indicator (set to 0xff to request an ACK at the
80  * completion of transmit; 0x00 otherwise), followed by data:
81  *
82  *	RQSTACK DAT DAT DAT ...
83  *
84  * with a total data length of 63.
85  *
86  * USB IN (USAxx -> host, receive) messages begin with a status
87  * byte in which the 0x80 bit is either:
88  *
89  * (a)	0x80 bit clear
90  *		indicates that the bytes following it are all data
91  *		bytes:
92  *
93  *			STAT DATA DATA DATA DATA DATA ...
94  *
95  *		for a total of up to 63 DATA bytes,
96  *
97  * or:
98  *
99  *	(b)	0x80 bit set
100  *		indiates that the bytes following alternate data and
101  *		status bytes:
102  *
103  *			STAT DATA STAT DATA STAT DATA STAT DATA ...
104  *
105  *		for a total of up to 32 DATA bytes.
106  *
107  * The valid bits in the STAT bytes are:
108  *
109  *	OVERRUN	0x02
110  *	PARITY	0x04
111  *	FRAMING	0x08
112  *	BREAK	0x10
113  *
114  * Notes:
115  *
116  * (1) The OVERRUN bit can appear in either (a) or (b) format
117  *	messages, but the but the PARITY/FRAMING/BREAK bits
118  *	only appear in (b) format messages.
119  * (2) For the host to determine the exact point at which the
120  *	overrun occurred (to identify the point in the data
121  *	stream at which the data was lost), it needs to count
122  *	128 characters, starting at the first character of the
123  *	message in which OVERRUN was reported; the lost character(s)
124  *	would have been received between the 128th and 129th
125  *	characters.
126  * (3)	An RX data message in which the first byte has 0x80 clear
127  *	serves as a "break off" indicator.
128  * (4)	a control message specifying disablePort will be answered
129  *	with a status message, but no further status will be sent
130  *	until a control messages with enablePort is sent
131  *
132  * revision history:
133  *
134  * 1999feb10	add reportHskiaChanges to allow us to ignore them
135  * 1999feb10	add txAckThreshold for fast+loose throughput enhancement
136  * 1999mar30	beef up support for RX error reporting
137  * 1999apr14	add resetDataToggle to control message
138  * 2000jan04	merge with usa17msg.h
139  * 2000mar08	clone from usa26msg.h -> usa49msg.h
140  * 2000mar09	change to support 4 ports
141  * 2000may03	change external clocking to match USA-49W hardware
142  * 2000jun01	add extended BSD-style copyright text
143  * 2001jul05	change message format to improve OVERRUN case
144  */
145 
146 /*
147  * Host->device messages sent on the global control endpoint:
148  *
149  * portNumber	message
150  * ----------	--------------------
151  * 0,1,2,3	portControlMessage
152  * 0x80		globalControlMessage
153  */
154 
155 struct keyspan_usa49_port_ctrl_msg {
156 	/*
157 	 * 0.	0/1/2/3 	port control message follows
158 	 * 0x80 set	non-port control message follows
159 	 */
160 	uint8_t portNumber;
161 
162 	/*
163 	 * there are three types of "commands" sent in the control message:
164 	 *
165 	 * 1. configuration changes which must be requested by setting
166 	 * the corresponding "set" flag (and should only be requested
167 	 * when necessary, to reduce overhead on the USA26):
168 	 */
169 	uint8_t setClocking;	/* host requests baud rate be set */
170 	uint8_t baudLo;		/* host does baud divisor calculation */
171 
172 	/* baudHi is only used for first port (gives lower rates) */
173 	uint8_t baudHi;
174 	uint8_t prescaler;	/* specified as N/8; values 8-ff are valid */
175 	/* must be set any time internal baud rate is set; */
176 	uint8_t txClocking;	/* 0=internal, 1=external/DSR */
177 	uint8_t rxClocking;	/* 0=internal, 1=external/DSR */
178 
179 	uint8_t setLcr;		/* host requests lcr be set */
180 	uint8_t lcr;		/* use PARITY, STOPBITS, DATABITS below */
181 
182 	uint8_t setFlowControl;	/* host requests flow control be set */
183 	uint8_t ctsFlowControl;	/* 1=use CTS flow control, 0=don't */
184 	uint8_t xonFlowControl;	/* 1=use XON/XOFF flow control, 0=don't */
185 	uint8_t xonChar;	/* specified in current character format */
186 	uint8_t xoffChar;	/* specified in current character format */
187 
188 	uint8_t setRts;		/* host requests RTS output be set */
189 	uint8_t rts;		/* 1=active, 0=inactive */
190 
191 	uint8_t setDtr;		/* host requests DTR output be set */
192 	uint8_t dtr;		/* 1=on, 0=off */
193 
194 	/*
195 	 * 3. configuration data which is simply used as is (no overhead,
196 	 * but must be specified correctly in every host message).
197 	 */
198 
199 	/* forward when this number of chars available */
200 	uint8_t forwardingLength;
201 	uint8_t dsrFlowControl;	/* 1=use DSR flow control, 0=don't */
202 
203 	/* 0=not allowed, 1=normal, 2-255 deliver ACK faster */
204 	uint8_t txAckThreshold;
205 	uint8_t loopbackMode;	/* 0=no loopback, 1=loopback enabled */
206 
207 	/*
208 	 * 4.	commands which are flags only; these are processed in order
209 	 * (so that, e.g., if both _txOn and _txOff flags are set, the
210 	 * port ends in a TX_OFF state); any non-zero value is respected
211 	 */
212 
213 	/* enable transmitting (and continue if there's data) */
214 	uint8_t _txOn;
215 	uint8_t _txOff;		/* stop transmitting */
216 	uint8_t txFlush;	/* toss outbound data */
217 	uint8_t txBreak;	/* turn on break (cleared by _txOn) */
218 	uint8_t rxOn;		/* turn on receiver */
219 	uint8_t rxOff;		/* turn off receiver */
220 	uint8_t rxFlush;	/* toss inbound data */
221 
222 	/* forward all inbound data, NOW (as if fwdLen==1) */
223 	uint8_t rxForward;
224 
225 	/* return current status (even if it hasn't changed) */
226 	uint8_t returnStatus;
227 	uint8_t resetDataToggle;	/* reset data toggle state to DATA0 */
228 
229 	/* start servicing port (move data, check status) */
230 	uint8_t enablePort;
231 
232 	/* stop servicing port (does implicit tx/rx flush/off) */
233 	uint8_t disablePort;
234 
235 };
236 
237 /* defines for bits in lcr */
238 #define	USA_DATABITS_5		0x00
239 #define	USA_DATABITS_6		0x01
240 #define	USA_DATABITS_7		0x02
241 #define	USA_DATABITS_8		0x03
242 #define	STOPBITS_5678_1		0x00	/* 1 stop bit for all byte sizes */
243 #define	STOPBITS_5_1p5		0x04	/* 1.5 stop bits for 5-bit byte */
244 #define	STOPBITS_678_2		0x04	/* 2 stop bits for 6/7/8-bit byte */
245 #define	USA_PARITY_NONE		0x00
246 #define	USA_PARITY_ODD		0x08
247 #define	USA_PARITY_EVEN		0x18
248 #define	PARITY_1			0x28
249 #define	PARITY_0			0x38
250 
251 /*
252  * during normal operation, status messages are returned
253  * to the host whenever the board detects changes.  In some
254  * circumstances (e.g. Windows), status messages from the
255  * device cause problems; to shut them off, the host issues
256  * a control message with the disableStatusMessages flags
257  * set (to any non-zero value).  The device will respond to
258  * this message, and then suppress further status messages;
259  * it will resume sending status messages any time the host
260  * sends any control message (either global or port-specific).
261  */
262 
263 struct keyspan_usa49_globalControlMessage {
264 	uint8_t portNumber;	/* 0x80 */
265 
266 	/* 1/2=number of status responses requested */
267 	uint8_t sendGlobalStatus;
268 	uint8_t resetStatusToggle;	/* 1=reset global status toggle */
269 	uint8_t resetStatusCount;	/* a cycling value */
270 	uint8_t remoteWakeupEnable;	/* 0x10=P1, 0x20=P2, 0x40=P3, 0x80=P4 */
271 	uint8_t disableStatusMessages;	/* 1=send no status until host talks */
272 };
273 
274 /*
275  * Device->host messages send on the global status endpoint
276  *
277  * portNumber			message
278  * ----------			--------------------
279  * 0x00,0x01,0x02,0x03		portStatusMessage
280  * 0x80				globalStatusMessage
281  * 0x81				globalDebugMessage
282  */
283 
284 struct keyspan_usa49_port_status_msg {	/* one for each port */
285 	uint8_t portNumber;	/* 0,1,2,3 */
286 	uint8_t cts;		/* reports CTS pin */
287 	uint8_t dcd;		/* reports DCD pin */
288 	uint8_t dsr;		/* reports DSR pin */
289 	uint8_t ri;		/* reports RI pin */
290 	uint8_t _txOff;		/* transmit has been disabled (by host) */
291 
292 	/* transmit is in XOFF state (either host or RX XOFF) */
293 	uint8_t _txXoff;
294 	uint8_t rxEnabled;	/* as configured by rxOn/rxOff 1=on, 0=off */
295 
296 	/* 1=a control message has been processed */
297 	uint8_t controlResponse;
298 	uint8_t txAck;		/* ACK (data TX complete) */
299 	uint8_t rs232valid;	/* RS-232 signal valid */
300 };
301 
302 /* bits in RX data message when STAT byte is included */
303 #define	RXERROR_OVERRUN	0x02
304 #define	RXERROR_PARITY	0x04
305 #define	RXERROR_FRAMING	0x08
306 #define	RXERROR_BREAK	0x10
307 
308 struct keyspan_usa49_globalStatusMessage {
309 	uint8_t portNumber;	/* 0x80=globalStatusMessage */
310 	uint8_t sendGlobalStatus;	/* from request, decremented */
311 	uint8_t resetStatusCount;	/* as in request */
312 };
313 
314 struct keyspan_usa49_globalDebugMessage {
315 	uint8_t portNumber;	/* 0x81=globalDebugMessage */
316 	uint8_t n;		/* typically a count/status byte */
317 	uint8_t b;		/* typically a data byte */
318 };
319 
320 /* ie: the maximum length of an EZUSB endpoint buffer */
321 #define	MAX_DATA_LEN			64
322 
323 /* update status approx. 60 times a second (16.6666 ms) */
324 #define	STATUS_UPDATE_INTERVAL	16
325 
326 /* status rationing tuning value (each port gets checked each n ms) */
327 #define	STATUS_RATION	10
328 
329 #endif /* _SYS_USB_USBSER_KEYSPAN_USA49MSG_H */
330