http://downloads.netgear.com/files/GPL/GPL_Source_V361j_DM111PSP_series_consumer_rele...
[bcm963xx.git] / kernel / linux / include / linux / n_r3964.h
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  2006/04/12 06:25:58  michaelc
17  * Original Broadcom V3.06.02V release
18  *
19  * 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 */
51 #include <asm/termios.h>
52
53 #ifdef __KERNEL__
54 /*
55  * Common ascii handshake characters:
56  */
57
58 #define STX 0x02
59 #define ETX 0x03
60 #define DLE 0x10
61 #define NAK 0x15
62
63 /*
64  * Timeouts (msecs/10 msecs per timer interrupt):
65  */
66
67 #define R3964_TO_QVZ 550/10
68 #define R3964_TO_ZVZ 220/10
69 #define R3964_TO_NO_BUF 400/10
70 #define R3964_NO_TX_ROOM 100/10
71 #define R3964_TO_RX_PANIC 4000/10
72 #define R3964_MAX_RETRIES 5
73
74 #endif
75
76 /*
77  * Ioctl-commands
78  */
79
80 #define R3964_ENABLE_SIGNALS      0x5301
81 #define R3964_SETPRIORITY         0x5302
82 #define R3964_USE_BCC             0x5303
83 #define R3964_READ_TELEGRAM       0x5304
84
85 /* Options for R3964_SETPRIORITY */
86 #define R3964_MASTER   0
87 #define R3964_SLAVE    1
88
89 /* Options for R3964_ENABLE_SIGNALS */
90 #define R3964_SIG_ACK   0x0001
91 #define R3964_SIG_DATA  0x0002
92 #define R3964_SIG_ALL   0x000f
93 #define R3964_SIG_NONE  0x0000
94 #define R3964_USE_SIGIO 0x1000
95
96 /*
97  * r3964 operation states:
98  */
99 #ifdef __KERNEL__
100
101 enum { R3964_IDLE, 
102            R3964_TX_REQUEST, R3964_TRANSMITTING, 
103            R3964_WAIT_ZVZ_BEFORE_TX_RETRY, R3964_WAIT_FOR_TX_ACK,
104            R3964_WAIT_FOR_RX_BUF,
105            R3964_RECEIVING, R3964_WAIT_FOR_BCC, R3964_WAIT_FOR_RX_REPEAT
106            };
107
108 /*
109  * All open file-handles are 'clients' and are stored in a linked list:
110  */
111
112 struct r3964_message;
113
114 struct r3964_client_info {
115         spinlock_t     lock;
116         pid_t          pid;
117         unsigned int   sig_flags;
118
119         struct r3964_client_info *next;
120
121         struct r3964_message *first_msg;
122         struct r3964_message *last_msg;
123         struct r3964_block_header *next_block_to_read;
124         int            msg_count;
125 };
126
127
128 #endif
129
130 /* types for msg_id: */
131 enum {R3964_MSG_ACK=1, R3964_MSG_DATA };
132
133 #define R3964_MAX_MSG_COUNT 32
134
135 /* error codes for client messages */
136 #define R3964_OK 0        /* no error. */
137 #define R3964_TX_FAIL -1  /* transmission error, block NOT sent */
138 #define R3964_OVERFLOW -2 /* msg queue overflow */
139
140 /* the client gets this struct when calling read(fd,...): */
141 struct r3964_client_message {
142           int     msg_id;
143           int     arg;
144           int     error_code;
145 };
146
147 #define R3964_MTU      256
148
149
150 #ifdef __KERNEL__
151
152 struct r3964_block_header;
153
154 /* internal version of client_message: */
155 struct r3964_message {
156           int     msg_id;
157           int     arg;
158           int     error_code;
159           struct r3964_block_header *block;
160           struct r3964_message *next;
161 };
162
163 /*
164  * Header of received block in rx_buf/tx_buf:
165  */
166
167 struct r3964_block_header 
168 {
169         unsigned int length;             /* length in chars without header */
170         unsigned char *data;             /* usually data is located 
171                                         immediately behind this struct */
172         unsigned int locks;              /* only used in rx_buffer */
173           
174     struct r3964_block_header *next;
175         struct r3964_client_info *owner;  /* =NULL in rx_buffer */
176 };
177
178 /*
179  * If rx_buf hasn't enough space to store R3964_MTU chars,
180  * we will reject all incoming STX-requests by sending NAK.
181  */
182
183 #define RX_BUF_SIZE    4000
184 #define TX_BUF_SIZE    4000
185 #define R3964_MAX_BLOCKS_IN_RX_QUEUE 100
186
187 #define R3964_PARITY 0x0001
188 #define R3964_FRAME  0x0002
189 #define R3964_OVERRUN 0x0004
190 #define R3964_UNKNOWN 0x0008
191 #define R3964_BREAK   0x0010
192 #define R3964_CHECKSUM 0x0020
193 #define R3964_ERROR  0x003f
194 #define R3964_BCC   0x4000
195 #define R3964_DEBUG 0x8000
196
197
198 struct r3964_info {
199         spinlock_t     lock;
200         struct tty_struct *tty;
201         unsigned char priority;
202         unsigned char *rx_buf;            /* ring buffer */
203         unsigned char *tx_buf;
204
205         wait_queue_head_t read_wait;
206         //struct wait_queue *read_wait;
207
208         struct r3964_block_header *rx_first;
209         struct r3964_block_header *rx_last;
210         struct r3964_block_header *tx_first;
211         struct r3964_block_header *tx_last;
212         unsigned int tx_position;
213         unsigned int rx_position;
214         unsigned char last_rx;
215         unsigned char bcc;
216         unsigned int  blocks_in_rx_queue;
217           
218         
219         struct r3964_client_info *firstClient;
220         unsigned int state;
221         unsigned int flags;
222
223         struct timer_list tmr;
224         int nRetry;
225 };
226
227 #endif  
228
229 #endif