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