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