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 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 
28 #ifndef _SYS_USB_USBSER_KEYSPAN_USA49MSG_H
29 #define	_SYS_USB_USBSER_KEYSPAN_USA49MSG_H
30 
31 typedef struct keyspan_usa49_port_ctrl_msg keyspan_usa49_port_ctrl_msg_t;
32 typedef struct keyspan_usa49_port_status_msg keyspan_usa49_port_status_msg_t;
33 
34 /*
35  * usa49msg.h
36  *
37  * Copyright (C) 1998-2000 InnoSys Incorporated.  All Rights Reserved
38  *
39  * Keyspan USB Async Message Formats for the USA49W
40  *
41  *
42  * Buffer formats for RX/TX data messages are not defined by
43  * a structure, but are described here:
44  *
45  * USB OUT (host -> USAxx, transmit) messages contain a
46  * REQUEST_ACK indicator (set to 0xff to request an ACK at the
47  * completion of transmit; 0x00 otherwise), followed by data:
48  *
49  *	RQSTACK DAT DAT DAT ...
50  *
51  * with a total data length of 63.
52  *
53  * USB IN (USAxx -> host, receive) messages begin with a status
54  * byte in which the 0x80 bit is either:
55  *
56  * (a)	0x80 bit clear
57  *		indicates that the bytes following it are all data
58  *		bytes:
59  *
60  *			STAT DATA DATA DATA DATA DATA ...
61  *
62  *		for a total of up to 63 DATA bytes,
63  *
64  * or:
65  *
66  *	(b)	0x80 bit set
67  *		indiates that the bytes following alternate data and
68  *		status bytes:
69  *
70  *			STAT DATA STAT DATA STAT DATA STAT DATA ...
71  *
72  *		for a total of up to 32 DATA bytes.
73  *
74  * The valid bits in the STAT bytes are:
75  *
76  *	OVERRUN	0x02
77  *	PARITY	0x04
78  *	FRAMING	0x08
79  *	BREAK	0x10
80  *
81  * Notes:
82  *
83  * (1) The OVERRUN bit can appear in either (a) or (b) format
84  *	messages, but the but the PARITY/FRAMING/BREAK bits
85  *	only appear in (b) format messages.
86  * (2) For the host to determine the exact point at which the
87  *	overrun occurred (to identify the point in the data
88  *	stream at which the data was lost), it needs to count
89  *	128 characters, starting at the first character of the
90  *	message in which OVERRUN was reported; the lost character(s)
91  *	would have been received between the 128th and 129th
92  *	characters.
93  * (3)	An RX data message in which the first byte has 0x80 clear
94  *	serves as a "break off" indicator.
95  * (4)	a control message specifying disablePort will be answered
96  *	with a status message, but no further status will be sent
97  *	until a control messages with enablePort is sent
98  *
99  */
100 
101 /*
102  * Host->device messages sent on the global control endpoint:
103  *
104  * portNumber	message
105  * ----------	--------------------
106  * 0,1,2,3	portControlMessage
107  * 0x80		globalControlMessage
108  */
109 
110 struct keyspan_usa49_port_ctrl_msg {
111 	/*
112 	 * 0.	0/1/2/3 	port control message follows
113 	 * 0x80 set	non-port control message follows
114 	 */
115 	uint8_t portNumber;
116 
117 	/*
118 	 * there are three types of "commands" sent in the control message:
119 	 *
120 	 * 1. configuration changes which must be requested by setting
121 	 * the corresponding "set" flag (and should only be requested
122 	 * when necessary, to reduce overhead on the USA26):
123 	 */
124 	uint8_t setClocking;	/* host requests baud rate be set */
125 	uint8_t baudLo;		/* host does baud divisor calculation */
126 
127 	/* baudHi is only used for first port (gives lower rates) */
128 	uint8_t baudHi;
129 	uint8_t prescaler;	/* specified as N/8; values 8-ff are valid */
130 	/* must be set any time internal baud rate is set; */
131 	uint8_t txClocking;	/* 0=internal, 1=external/DSR */
132 	uint8_t rxClocking;	/* 0=internal, 1=external/DSR */
133 
134 	uint8_t setLcr;		/* host requests lcr be set */
135 	uint8_t lcr;		/* use PARITY, STOPBITS, DATABITS below */
136 
137 	uint8_t setFlowControl;	/* host requests flow control be set */
138 	uint8_t ctsFlowControl;	/* 1=use CTS flow control, 0=don't */
139 	uint8_t xonFlowControl;	/* 1=use XON/XOFF flow control, 0=don't */
140 	uint8_t xonChar;	/* specified in current character format */
141 	uint8_t xoffChar;	/* specified in current character format */
142 
143 	uint8_t setRts;		/* host requests RTS output be set */
144 	uint8_t rts;		/* 1=active, 0=inactive */
145 
146 	uint8_t setDtr;		/* host requests DTR output be set */
147 	uint8_t dtr;		/* 1=on, 0=off */
148 
149 	/*
150 	 * 3. configuration data which is simply used as is (no overhead,
151 	 * but must be specified correctly in every host message).
152 	 */
153 
154 	/* forward when this number of chars available */
155 	uint8_t forwardingLength;
156 	uint8_t dsrFlowControl;	/* 1=use DSR flow control, 0=don't */
157 
158 	/* 0=not allowed, 1=normal, 2-255 deliver ACK faster */
159 	uint8_t txAckThreshold;
160 	uint8_t loopbackMode;	/* 0=no loopback, 1=loopback enabled */
161 
162 	/*
163 	 * 4.	commands which are flags only; these are processed in order
164 	 * (so that, e.g., if both _txOn and _txOff flags are set, the
165 	 * port ends in a TX_OFF state); any non-zero value is respected
166 	 */
167 
168 	/* enable transmitting (and continue if there's data) */
169 	uint8_t _txOn;
170 	uint8_t _txOff;		/* stop transmitting */
171 	uint8_t txFlush;	/* toss outbound data */
172 	uint8_t txBreak;	/* turn on break (cleared by _txOn) */
173 	uint8_t rxOn;		/* turn on receiver */
174 	uint8_t rxOff;		/* turn off receiver */
175 	uint8_t rxFlush;	/* toss inbound data */
176 
177 	/* forward all inbound data, NOW (as if fwdLen==1) */
178 	uint8_t rxForward;
179 
180 	/* return current status (even if it hasn't changed) */
181 	uint8_t returnStatus;
182 	uint8_t resetDataToggle;	/* reset data toggle state to DATA0 */
183 
184 	/* start servicing port (move data, check status) */
185 	uint8_t enablePort;
186 
187 	/* stop servicing port (does implicit tx/rx flush/off) */
188 	uint8_t disablePort;
189 
190 };
191 
192 /* defines for bits in lcr */
193 #define	USA_DATABITS_5		0x00
194 #define	USA_DATABITS_6		0x01
195 #define	USA_DATABITS_7		0x02
196 #define	USA_DATABITS_8		0x03
197 #define	STOPBITS_5678_1		0x00	/* 1 stop bit for all byte sizes */
198 #define	STOPBITS_5_1p5		0x04	/* 1.5 stop bits for 5-bit byte */
199 #define	STOPBITS_678_2		0x04	/* 2 stop bits for 6/7/8-bit byte */
200 #define	USA_PARITY_NONE		0x00
201 #define	USA_PARITY_ODD		0x08
202 #define	USA_PARITY_EVEN		0x18
203 #define	PARITY_1			0x28
204 #define	PARITY_0			0x38
205 
206 /*
207  * during normal operation, status messages are returned
208  * to the host whenever the board detects changes.  In some
209  * circumstances (e.g. Windows), status messages from the
210  * device cause problems; to shut them off, the host issues
211  * a control message with the disableStatusMessages flags
212  * set (to any non-zero value).  The device will respond to
213  * this message, and then suppress further status messages;
214  * it will resume sending status messages any time the host
215  * sends any control message (either global or port-specific).
216  */
217 
218 struct keyspan_usa49_globalControlMessage {
219 	uint8_t portNumber;	/* 0x80 */
220 
221 	/* 1/2=number of status responses requested */
222 	uint8_t sendGlobalStatus;
223 	uint8_t resetStatusToggle;	/* 1=reset global status toggle */
224 	uint8_t resetStatusCount;	/* a cycling value */
225 	uint8_t remoteWakeupEnable;	/* 0x10=P1, 0x20=P2, 0x40=P3, 0x80=P4 */
226 	uint8_t disableStatusMessages;	/* 1=send no status until host talks */
227 };
228 
229 /*
230  * Device->host messages send on the global status endpoint
231  *
232  * portNumber			message
233  * ----------			--------------------
234  * 0x00,0x01,0x02,0x03		portStatusMessage
235  * 0x80				globalStatusMessage
236  * 0x81				globalDebugMessage
237  */
238 
239 struct keyspan_usa49_port_status_msg {	/* one for each port */
240 	uint8_t portNumber;	/* 0,1,2,3 */
241 	uint8_t cts;		/* reports CTS pin */
242 	uint8_t dcd;		/* reports DCD pin */
243 	uint8_t dsr;		/* reports DSR pin */
244 	uint8_t ri;		/* reports RI pin */
245 	uint8_t _txOff;		/* transmit has been disabled (by host) */
246 
247 	/* transmit is in XOFF state (either host or RX XOFF) */
248 	uint8_t _txXoff;
249 	uint8_t rxEnabled;	/* as configured by rxOn/rxOff 1=on, 0=off */
250 
251 	/* 1=a control message has been processed */
252 	uint8_t controlResponse;
253 	uint8_t txAck;		/* ACK (data TX complete) */
254 	uint8_t rs232valid;	/* RS-232 signal valid */
255 };
256 
257 /* bits in RX data message when STAT byte is included */
258 #define	RXERROR_OVERRUN	0x02
259 #define	RXERROR_PARITY	0x04
260 #define	RXERROR_FRAMING	0x08
261 #define	RXERROR_BREAK	0x10
262 
263 struct keyspan_usa49_globalStatusMessage {
264 	uint8_t portNumber;	/* 0x80=globalStatusMessage */
265 	uint8_t sendGlobalStatus;	/* from request, decremented */
266 	uint8_t resetStatusCount;	/* as in request */
267 };
268 
269 struct keyspan_usa49_globalDebugMessage {
270 	uint8_t portNumber;	/* 0x81=globalDebugMessage */
271 	uint8_t n;		/* typically a count/status byte */
272 	uint8_t b;		/* typically a data byte */
273 };
274 
275 /* ie: the maximum length of an EZUSB endpoint buffer */
276 #define	MAX_DATA_LEN			64
277 
278 /* update status approx. 60 times a second (16.6666 ms) */
279 #define	STATUS_UPDATE_INTERVAL	16
280 
281 /* status rationing tuning value (each port gets checked each n ms) */
282 #define	STATUS_RATION	10
283 
284 #endif /* _SYS_USB_USBSER_KEYSPAN_USA49MSG_H */
285