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