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