Merge gregkh@master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[linux-2.6.22.y-op.git] / include / linux / n_r3964.h
blobdb4f3776978aafe81c36caf263f001d195e28311
1 /* r3964 linediscipline for linux
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.
12 * Author:
13 * L. Haag
15 * $Log: r3964.h,v $
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
20 * Revision 1.3 2001/03/18 13:02:24 dwmw2
21 * Fix timer usage, use spinlocks properly.
23 * Revision 1.2 2001/03/18 12:53:15 dwmw2
24 * Merge changes in 2.4.2
26 * Revision 1.1.1.1 1998/10/13 16:43:14 dwmw2
27 * This'll screw the version control
29 * Revision 1.6 1998/09/30 00:40:38 dwmw2
30 * Updated to use kernel's N_R3964 if available
32 * Revision 1.4 1998/04/02 20:29:44 lhaag
33 * select, blocking, ...
35 * Revision 1.3 1998/02/12 18:58:43 root
36 * fixed some memory leaks
37 * calculation of checksum characters
39 * Revision 1.2 1998/02/07 13:03:17 root
40 * ioctl read_telegram
42 * Revision 1.1 1998/02/06 19:19:43 root
43 * Initial revision
48 #ifndef __LINUX_N_R3964_H__
49 #define __LINUX_N_R3964_H__
51 /* line disciplines for r3964 protocol */
53 #ifdef __KERNEL__
55 #include <linux/param.h>
58 * Common ascii handshake characters:
61 #define STX 0x02
62 #define ETX 0x03
63 #define DLE 0x10
64 #define NAK 0x15
67 * Timeouts (from milliseconds to jiffies)
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)
75 #define R3964_MAX_RETRIES 5
77 #endif
80 * Ioctl-commands
83 #define R3964_ENABLE_SIGNALS 0x5301
84 #define R3964_SETPRIORITY 0x5302
85 #define R3964_USE_BCC 0x5303
86 #define R3964_READ_TELEGRAM 0x5304
88 /* Options for R3964_SETPRIORITY */
89 #define R3964_MASTER 0
90 #define R3964_SLAVE 1
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
100 * r3964 operation states:
102 #ifdef __KERNEL__
104 enum { 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
112 * All open file-handles are 'clients' and are stored in a linked list:
115 struct r3964_message;
117 struct r3964_client_info {
118 spinlock_t lock;
119 pid_t pid;
120 unsigned int sig_flags;
122 struct r3964_client_info *next;
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;
131 #endif
133 /* types for msg_id: */
134 enum {R3964_MSG_ACK=1, R3964_MSG_DATA };
136 #define R3964_MAX_MSG_COUNT 32
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 */
143 /* the client gets this struct when calling read(fd,...): */
144 struct r3964_client_message {
145 int msg_id;
146 int arg;
147 int error_code;
150 #define R3964_MTU 256
153 #ifdef __KERNEL__
155 struct r3964_block_header;
157 /* internal version of client_message: */
158 struct r3964_message {
159 int msg_id;
160 int arg;
161 int error_code;
162 struct r3964_block_header *block;
163 struct r3964_message *next;
167 * Header of received block in rx_buf/tx_buf:
170 struct r3964_block_header
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 */
177 struct r3964_block_header *next;
178 struct r3964_client_info *owner; /* =NULL in rx_buffer */
182 * If rx_buf hasn't enough space to store R3964_MTU chars,
183 * we will reject all incoming STX-requests by sending NAK.
186 #define RX_BUF_SIZE 4000
187 #define TX_BUF_SIZE 4000
188 #define R3964_MAX_BLOCKS_IN_RX_QUEUE 100
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
201 struct 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;
208 wait_queue_head_t read_wait;
209 //struct wait_queue *read_wait;
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;
222 struct r3964_client_info *firstClient;
223 unsigned int state;
224 unsigned int flags;
226 struct timer_list tmr;
227 int nRetry;
230 #endif
232 #endif