1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 #ifndef icn_h
67 #define icn_h
68
69 #define ICN_IOCTL_SETMMIO 0
70 #define ICN_IOCTL_GETMMIO 1
71 #define ICN_IOCTL_SETPORT 2
72 #define ICN_IOCTL_GETPORT 3
73 #define ICN_IOCTL_LOADBOOT 4
74 #define ICN_IOCTL_LOADPROTO 5
75 #define ICN_IOCTL_LEASEDCFG 6
76 #define ICN_IOCTL_GETDOUBLE 7
77 #define ICN_IOCTL_DEBUGVAR 8
78
79 #if defined(__KERNEL__) || defined(__DEBUGVAR__)
80
81 #ifdef __KERNEL__
82
83
84 #include <linux/module.h>
85 #include <linux/version.h>
86 #include <linux/errno.h>
87 #include <linux/fs.h>
88 #include <linux/major.h>
89 #include <asm/segment.h>
90 #include <asm/io.h>
91 #include <linux/kernel.h>
92 #include <linux/signal.h>
93 #include <linux/malloc.h>
94 #include <linux/mm.h>
95 #include <linux/mman.h>
96 #include <linux/ioport.h>
97 #include <linux/timer.h>
98 #include <linux/wait.h>
99 #include <linux/isdnif.h>
100
101 #endif
102
103
104 #ifdef ICN_DEBUG_PORT
105 #define OUTB_P(v,p) {printk(KERN_DEBUG "icn: outb_p(0x%02x,0x%03x)\n",v,p); outb_p(v,p);}
106 #else
107 #define OUTB_P outb
108 #endif
109
110
111 #define ICN_BASEADDR 0x320
112 #define ICN_PORTLEN (0x04)
113 #define ICN_MEMADDR 0x0d0000
114
115
116 #define ICN_CFG (dev->port)
117 #define ICN_MAPRAM (dev->port+1)
118 #define ICN_RUN (dev->port+2)
119 #define ICN_BANK (dev->port+3)
120
121 #define ICN_FLAGS_B1ACTIVE 1
122 #define ICN_FLAGS_B2ACTIVE 2
123 #define ICN_FLAGS_RBTIMER 8
124
125 #define ICN_BOOT_TIMEOUT1 100
126 #define ICN_CHANLOCK_DELAY 10
127
128 #define ICN_TIMER_BCREAD 3
129 #define ICN_TIMER_DCREAD 50
130
131 #define ICN_CODE_STAGE1 4096
132 #define ICN_CODE_STAGE2 65536
133
134 #define ICN_MAX_SQUEUE 65536
135 #define ICN_FRAGSIZE (250)
136 #define ICN_BCH 2
137
138
139
140 #define SHM_DCTL_OFFSET (0)
141 #define SHM_CCTL_OFFSET (0x1d2)
142 #define SHM_CBUF_OFFSET (0x200)
143 #define SHM_DBUF_OFFSET (0x2000)
144
145 typedef struct {
146 unsigned char length;
147 unsigned char endflag;
148 unsigned char data[ICN_FRAGSIZE];
149
150 char unused[0x100 - ICN_FRAGSIZE - 2];
151 } frag_buf;
152
153 typedef union {
154 struct {
155 unsigned char scns;
156 unsigned char scnr;
157 unsigned char ecns;
158 unsigned char ecnr;
159 char unused[6];
160 unsigned short fuell1;
161 } data_control;
162 struct {
163 char unused[SHM_CCTL_OFFSET];
164 unsigned char iopc_i;
165 unsigned char iopc_o;
166 unsigned char pcio_i;
167 unsigned char pcio_o;
168 } comm_control;
169 struct {
170 char unused[SHM_CBUF_OFFSET];
171 unsigned char pcio_buf[0x100];
172 unsigned char iopc_buf[0x100];
173 } comm_buffers;
174 struct {
175 char unused[SHM_DBUF_OFFSET];
176 frag_buf receive_buf[0x10];
177 frag_buf send_buf[0x10];
178 } data_buffers;
179 } icn_shmem;
180
181
182 typedef struct {
183 char *next;
184 short length;
185 short size;
186 u_char *rptr;
187 u_char buffer[1];
188 } pqueue;
189
190 typedef struct {
191 unsigned short port;
192 icn_shmem *shmem;
193 int myid;
194 int rvalid;
195 int mvalid;
196 int leased;
197
198 unsigned short flags;
199 int doubleS0;
200 int secondhalf;
201 int ptype;
202 struct timer_list st_timer;
203 struct timer_list rb_timer;
204 int channel;
205 int chanlock;
206 u_char rcvbuf[ICN_BCH][4096];
207 int rcvidx[ICN_BCH];
208 int l2_proto[ICN_BCH];
209 isdn_if interface;
210 int iptr;
211 char imsg[60];
212 char msg_buf[2048];
213 char *msg_buf_write;
214 char *msg_buf_read;
215 char *msg_buf_end;
216 int sndcount[ICN_BCH];
217 pqueue *spqueue[ICN_BCH];
218 #ifdef DEBUG_RCVCALLBACK
219 int akt_pending[ICN_BCH];
220 int max_pending[ICN_BCH];
221 #endif
222 } icn_dev;
223
224 typedef icn_dev *icn_devptr;
225
226 #ifdef __KERNEL__
227 static icn_dev *dev = (icn_dev *) 0;
228 static icn_dev *dev2 = (icn_dev *) 0;
229
230
231
232
233
234 int portbase = ICN_BASEADDR;
235 int membase = ICN_MEMADDR;
236 char *icn_id = "\0";
237 char *icn_id2 = "\0";
238 static char regname[35];
239
240 #endif
241
242
243
244
245 #define sbfree (((dev->shmem->data_control.scns+1) & 0xf) != \
246 dev->shmem->data_control.scnr)
247
248
249 #define sbnext (dev->shmem->data_control.scns = \
250 ((dev->shmem->data_control.scns+1) & 0xf))
251
252
253 #define sbuf_n dev->shmem->data_control.scns
254 #define sbuf_d dev->shmem->data_buffers.send_buf[sbuf_n].data
255 #define sbuf_l dev->shmem->data_buffers.send_buf[sbuf_n].length
256 #define sbuf_f dev->shmem->data_buffers.send_buf[sbuf_n].endflag
257
258
259 #define rbavl (dev->shmem->data_control.ecnr != \
260 dev->shmem->data_control.ecns)
261
262
263 #define rbnext (dev->shmem->data_control.ecnr = \
264 ((dev->shmem->data_control.ecnr+1) & 0xf))
265
266
267 #define rbuf_n dev->shmem->data_control.ecnr
268 #define rbuf_d dev->shmem->data_buffers.receive_buf[rbuf_n].data
269 #define rbuf_l dev->shmem->data_buffers.receive_buf[rbuf_n].length
270 #define rbuf_f dev->shmem->data_buffers.receive_buf[rbuf_n].endflag
271
272
273 #define cmd_o (dev->shmem->comm_control.pcio_o)
274 #define cmd_i (dev->shmem->comm_control.pcio_i)
275
276
277 #define cmd_free ((cmd_i>=cmd_o)?0x100-cmd_i+cmd_o:cmd_o-cmd_i)
278
279
280 #define msg_o (dev->shmem->comm_control.iopc_o)
281 #define msg_i (dev->shmem->comm_control.iopc_i)
282
283
284 #define msg_avail ((msg_o>msg_i)?0x100-msg_o+msg_i:msg_i-msg_o)
285
286 #define MIN(a,b) ((a<b)?a:b)
287 #define MAX(a,b) ((a>b)?a:b)
288
289
290
291
292
293 #define check_shmem check_region
294 #define release_shmem release_region
295 #define request_shmem request_region
296
297 #endif
298 #endif