ARM: Merge for-2635/samsung-ts
[linux-2.6-block.git] / include / linux / n_r3964.h
CommitLineData
1da177e4
LT
1/* r3964 linediscipline for linux
2 *
3 * -----------------------------------------------------------
4 * Copyright by
5 * Philips Automation Projects
6 * Kassel (Germany)
7 * http://www.pap-philips.de
8 * -----------------------------------------------------------
9 * This software may be used and distributed according to the terms of
10 * the GNU General Public License, incorporated herein by reference.
11 *
12 * Author:
13 * L. Haag
14 *
15 * $Log: r3964.h,v $
01e33b5a
KH
16 * Revision 1.4 2005/12/21 19:54:24 Kurt Huwig <kurt huwig de>
17 * Fixed HZ usage on 2.6 kernels
18 * Removed unnecessary include
19 *
1da177e4
LT
20 * Revision 1.3 2001/03/18 13:02:24 dwmw2
21 * Fix timer usage, use spinlocks properly.
22 *
23 * Revision 1.2 2001/03/18 12:53:15 dwmw2
24 * Merge changes in 2.4.2
25 *
26 * Revision 1.1.1.1 1998/10/13 16:43:14 dwmw2
27 * This'll screw the version control
28 *
29 * Revision 1.6 1998/09/30 00:40:38 dwmw2
30 * Updated to use kernel's N_R3964 if available
31 *
32 * Revision 1.4 1998/04/02 20:29:44 lhaag
33 * select, blocking, ...
34 *
35 * Revision 1.3 1998/02/12 18:58:43 root
36 * fixed some memory leaks
37 * calculation of checksum characters
38 *
39 * Revision 1.2 1998/02/07 13:03:17 root
40 * ioctl read_telegram
41 *
42 * Revision 1.1 1998/02/06 19:19:43 root
43 * Initial revision
44 *
45 *
46 */
47
48#ifndef __LINUX_N_R3964_H__
49#define __LINUX_N_R3964_H__
50
51/* line disciplines for r3964 protocol */
1da177e4
LT
52
53#ifdef __KERNEL__
01e33b5a
KH
54
55#include <linux/param.h>
56
1da177e4
LT
57/*
58 * Common ascii handshake characters:
59 */
60
61#define STX 0x02
62#define ETX 0x03
63#define DLE 0x10
64#define NAK 0x15
65
66/*
01e33b5a 67 * Timeouts (from milliseconds to jiffies)
1da177e4
LT
68 */
69
01e33b5a
KH
70#define R3964_TO_QVZ ((550)*HZ/1000)
71#define R3964_TO_ZVZ ((220)*HZ/1000)
72#define R3964_TO_NO_BUF ((400)*HZ/1000)
73#define R3964_NO_TX_ROOM ((100)*HZ/1000)
74#define R3964_TO_RX_PANIC ((4000)*HZ/1000)
1da177e4
LT
75#define R3964_MAX_RETRIES 5
76
77#endif
78
79/*
80 * Ioctl-commands
81 */
82
83#define R3964_ENABLE_SIGNALS 0x5301
84#define R3964_SETPRIORITY 0x5302
85#define R3964_USE_BCC 0x5303
86#define R3964_READ_TELEGRAM 0x5304
87
88/* Options for R3964_SETPRIORITY */
89#define R3964_MASTER 0
90#define R3964_SLAVE 1
91
92/* Options for R3964_ENABLE_SIGNALS */
93#define R3964_SIG_ACK 0x0001
94#define R3964_SIG_DATA 0x0002
95#define R3964_SIG_ALL 0x000f
96#define R3964_SIG_NONE 0x0000
97#define R3964_USE_SIGIO 0x1000
98
99/*
100 * r3964 operation states:
101 */
102#ifdef __KERNEL__
103
104enum { R3964_IDLE,
105 R3964_TX_REQUEST, R3964_TRANSMITTING,
106 R3964_WAIT_ZVZ_BEFORE_TX_RETRY, R3964_WAIT_FOR_TX_ACK,
107 R3964_WAIT_FOR_RX_BUF,
108 R3964_RECEIVING, R3964_WAIT_FOR_BCC, R3964_WAIT_FOR_RX_REPEAT
109 };
110
111/*
112 * All open file-handles are 'clients' and are stored in a linked list:
113 */
114
115struct r3964_message;
116
117struct r3964_client_info {
118 spinlock_t lock;
3cec556a 119 struct pid *pid;
1da177e4
LT
120 unsigned int sig_flags;
121
122 struct r3964_client_info *next;
123
124 struct r3964_message *first_msg;
125 struct r3964_message *last_msg;
126 struct r3964_block_header *next_block_to_read;
127 int msg_count;
128};
129
130
131#endif
132
133/* types for msg_id: */
134enum {R3964_MSG_ACK=1, R3964_MSG_DATA };
135
136#define R3964_MAX_MSG_COUNT 32
137
138/* error codes for client messages */
139#define R3964_OK 0 /* no error. */
140#define R3964_TX_FAIL -1 /* transmission error, block NOT sent */
141#define R3964_OVERFLOW -2 /* msg queue overflow */
142
143/* the client gets this struct when calling read(fd,...): */
144struct r3964_client_message {
145 int msg_id;
146 int arg;
147 int error_code;
148};
149
150#define R3964_MTU 256
151
152
153#ifdef __KERNEL__
154
155struct r3964_block_header;
156
157/* internal version of client_message: */
158struct r3964_message {
159 int msg_id;
160 int arg;
161 int error_code;
162 struct r3964_block_header *block;
163 struct r3964_message *next;
164};
165
166/*
167 * Header of received block in rx_buf/tx_buf:
168 */
169
170struct r3964_block_header
171{
172 unsigned int length; /* length in chars without header */
173 unsigned char *data; /* usually data is located
174 immediately behind this struct */
175 unsigned int locks; /* only used in rx_buffer */
176
177 struct r3964_block_header *next;
178 struct r3964_client_info *owner; /* =NULL in rx_buffer */
179};
180
181/*
182 * If rx_buf hasn't enough space to store R3964_MTU chars,
183 * we will reject all incoming STX-requests by sending NAK.
184 */
185
186#define RX_BUF_SIZE 4000
187#define TX_BUF_SIZE 4000
188#define R3964_MAX_BLOCKS_IN_RX_QUEUE 100
189
190#define R3964_PARITY 0x0001
191#define R3964_FRAME 0x0002
192#define R3964_OVERRUN 0x0004
193#define R3964_UNKNOWN 0x0008
194#define R3964_BREAK 0x0010
195#define R3964_CHECKSUM 0x0020
196#define R3964_ERROR 0x003f
197#define R3964_BCC 0x4000
198#define R3964_DEBUG 0x8000
199
200
201struct r3964_info {
202 spinlock_t lock;
203 struct tty_struct *tty;
204 unsigned char priority;
205 unsigned char *rx_buf; /* ring buffer */
206 unsigned char *tx_buf;
207
208 wait_queue_head_t read_wait;
209 //struct wait_queue *read_wait;
210
211 struct r3964_block_header *rx_first;
212 struct r3964_block_header *rx_last;
213 struct r3964_block_header *tx_first;
214 struct r3964_block_header *tx_last;
215 unsigned int tx_position;
216 unsigned int rx_position;
217 unsigned char last_rx;
218 unsigned char bcc;
219 unsigned int blocks_in_rx_queue;
220
221
222 struct r3964_client_info *firstClient;
223 unsigned int state;
224 unsigned int flags;
225
226 struct timer_list tmr;
227 int nRetry;
228};
229
230#endif
231
232#endif