vserver 1.9.5.x5
[linux-2.6.git] / drivers / isdn / icn / icn.h
1 /* $Id: icn.h,v 1.30.6.5 2001/09/23 22:24:55 kai Exp $
2  *
3  * ISDN lowlevel-module for the ICN active ISDN-Card.
4  *
5  * Copyright 1994 by Fritz Elfert (fritz@isdn4linux.de)
6  *
7  * This software may be used and distributed according to the terms
8  * of the GNU General Public License, incorporated herein by reference.
9  *
10  */
11
12 #ifndef icn_h
13 #define icn_h
14
15 #define ICN_IOCTL_SETMMIO   0
16 #define ICN_IOCTL_GETMMIO   1
17 #define ICN_IOCTL_SETPORT   2
18 #define ICN_IOCTL_GETPORT   3
19 #define ICN_IOCTL_LOADBOOT  4
20 #define ICN_IOCTL_LOADPROTO 5
21 #define ICN_IOCTL_LEASEDCFG 6
22 #define ICN_IOCTL_GETDOUBLE 7
23 #define ICN_IOCTL_DEBUGVAR  8
24 #define ICN_IOCTL_ADDCARD   9
25
26 /* Struct for adding new cards */
27 typedef struct icn_cdef {
28         int port;
29         char id1[10];
30         char id2[10];
31 } icn_cdef;
32
33 #if defined(__KERNEL__) || defined(__DEBUGVAR__)
34
35 #ifdef __KERNEL__
36 /* Kernel includes */
37
38 #include <linux/version.h>
39 #include <linux/errno.h>
40 #include <linux/fs.h>
41 #include <linux/major.h>
42 #include <asm/io.h>
43 #include <linux/kernel.h>
44 #include <linux/signal.h>
45 #include <linux/slab.h>
46 #include <linux/mm.h>
47 #include <linux/mman.h>
48 #include <linux/ioport.h>
49 #include <linux/timer.h>
50 #include <linux/wait.h>
51 #include <linux/delay.h>
52 #include <linux/isdnif.h>
53
54 #endif                          /* __KERNEL__ */
55
56 /* some useful macros for debugging */
57 #ifdef ICN_DEBUG_PORT
58 #define OUTB_P(v,p) {printk(KERN_DEBUG "icn: outb_p(0x%02x,0x%03x)\n",v,p); outb_p(v,p);}
59 #else
60 #define OUTB_P outb
61 #endif
62
63 /* Defaults for Port-Address and shared-memory */
64 #define ICN_BASEADDR 0x320
65 #define ICN_PORTLEN (0x04)
66 #define ICN_MEMADDR 0x0d0000
67
68 #define ICN_FLAGS_B1ACTIVE 1    /* B-Channel-1 is open                     */
69 #define ICN_FLAGS_B2ACTIVE 2    /* B-Channel-2 is open                     */
70 #define ICN_FLAGS_RUNNING  4    /* Cards driver activated                  */
71 #define ICN_FLAGS_RBTIMER  8    /* cyclic scheduling of B-Channel-poll     */
72
73 #define ICN_BOOT_TIMEOUT1  1000 /* Delay for Boot-download (msecs)         */
74
75 #define ICN_TIMER_BCREAD (HZ/100)       /* B-Channel poll-cycle                    */
76 #define ICN_TIMER_DCREAD (HZ/2) /* D-Channel poll-cycle                    */
77
78 #define ICN_CODE_STAGE1 4096    /* Size of bootcode                        */
79 #define ICN_CODE_STAGE2 65536   /* Size of protocol-code                   */
80
81 #define ICN_MAX_SQUEUE 8000     /* Max. outstanding send-data (2* hw-buf.) */
82 #define ICN_FRAGSIZE (250)      /* Max. size of send-fragments             */
83 #define ICN_BCH 2               /* Number of supported channels per card   */
84
85 /* type-definitions for accessing the mmap-io-areas */
86
87 #define SHM_DCTL_OFFSET (0)     /* Offset to data-controlstructures in shm */
88 #define SHM_CCTL_OFFSET (0x1d2) /* Offset to comm-controlstructures in shm */
89 #define SHM_CBUF_OFFSET (0x200) /* Offset to comm-buffers in shm           */
90 #define SHM_DBUF_OFFSET (0x2000)        /* Offset to data-buffers in shm           */
91
92 /*
93  * Layout of card's data buffers
94  */
95 typedef struct {
96         unsigned char length;   /* Bytecount of fragment (max 250)    */
97         unsigned char endflag;  /* 0=last frag., 0xff=frag. continued */
98         unsigned char data[ICN_FRAGSIZE];       /* The data                           */
99         /* Fill to 256 bytes */
100         char unused[0x100 - ICN_FRAGSIZE - 2];
101 } frag_buf;
102
103 /*
104  * Layout of card's shared memory
105  */
106 typedef union {
107         struct {
108                 unsigned char scns;     /* Index to free SendFrag.             */
109                 unsigned char scnr;     /* Index to active SendFrag   READONLY */
110                 unsigned char ecns;     /* Index to free RcvFrag.     READONLY */
111                 unsigned char ecnr;     /* Index to valid RcvFrag              */
112                 char unused[6];
113                 unsigned short fuell1;  /* Internal Buf Bytecount              */
114         } data_control;
115         struct {
116                 char unused[SHM_CCTL_OFFSET];
117                 unsigned char iopc_i;   /* Read-Ptr Status-Queue      READONLY */
118                 unsigned char iopc_o;   /* Write-Ptr Status-Queue              */
119                 unsigned char pcio_i;   /* Write-Ptr Command-Queue             */
120                 unsigned char pcio_o;   /* Read-Ptr Command Queue     READONLY */
121         } comm_control;
122         struct {
123                 char unused[SHM_CBUF_OFFSET];
124                 unsigned char pcio_buf[0x100];  /* Ring-Buffer Command-Queue           */
125                 unsigned char iopc_buf[0x100];  /* Ring-Buffer Status-Queue            */
126         } comm_buffers;
127         struct {
128                 char unused[SHM_DBUF_OFFSET];
129                 frag_buf receive_buf[0x10];
130                 frag_buf send_buf[0x10];
131         } data_buffers;
132 } icn_shmem;
133
134 /*
135  * Per card driver data
136  */
137 typedef struct icn_card {
138         struct icn_card *next;  /* Pointer to next device struct    */
139         struct icn_card *other; /* Pointer to other card for ICN4B  */
140         unsigned short port;    /* Base-port-address                */
141         int myid;               /* Driver-Nr. assigned by linklevel */
142         int rvalid;             /* IO-portregion has been requested */
143         int leased;             /* Flag: This Adapter is connected  */
144                                 /*       to a leased line           */
145         unsigned short flags;   /* Statusflags                      */
146         int doubleS0;           /* Flag: ICN4B                      */
147         int secondhalf;         /* Flag: Second half of a doubleS0  */
148         int fw_rev;             /* Firmware revision loaded         */
149         int ptype;              /* Protocol type (1TR6 or Euro)     */
150         struct timer_list st_timer;   /* Timer for Status-Polls     */
151         struct timer_list rb_timer;   /* Timer for B-Channel-Polls  */
152         u_char rcvbuf[ICN_BCH][4096]; /* B-Channel-Receive-Buffers  */
153         int rcvidx[ICN_BCH];    /* Index for above buffers          */
154         int l2_proto[ICN_BCH];  /* Current layer-2-protocol         */
155         isdn_if interface;      /* Interface to upper layer         */
156         int iptr;               /* Index to imsg-buffer             */
157         char imsg[60];          /* Internal buf for status-parsing  */
158         char msg_buf[2048];     /* Buffer for status-messages       */
159         char *msg_buf_write;    /* Writepointer for statusbuffer    */
160         char *msg_buf_read;     /* Readpointer for statusbuffer     */
161         char *msg_buf_end;      /* Pointer to end of statusbuffer   */
162         int sndcount[ICN_BCH];  /* Byte-counters for B-Ch.-send     */
163         int xlen[ICN_BCH];      /* Byte-counters/Flags for sent-ACK */
164         struct sk_buff *xskb[ICN_BCH]; /* Current transmitted skb   */
165         struct sk_buff_head spqueue[ICN_BCH];  /* Sendqueue         */
166         char regname[35];       /* Name used for request_region     */
167         u_char xmit_lock[ICN_BCH]; /* Semaphore for pollbchan_send()*/
168         spinlock_t lock;        /* protect critical operations      */
169 } icn_card;
170
171 /*
172  * Main driver data
173  */
174 typedef struct icn_dev {
175         spinlock_t devlock;     /* spinlock to protect this struct  */
176         unsigned long memaddr;  /* Address of memory mapped buffers */
177         icn_shmem __iomem *shmem;       /* Pointer to memory-mapped-buffers */
178         int mvalid;             /* IO-shmem has been requested      */
179         int channel;            /* Currently mapped channel         */
180         struct icn_card *mcard; /* Currently mapped card            */
181         int chanlock;           /* Semaphore for channel-mapping    */
182         int firstload;          /* Flag: firmware never loaded      */
183 } icn_dev;
184
185 typedef icn_dev *icn_devptr;
186
187 #ifdef __KERNEL__
188
189 static icn_card *cards = (icn_card *) 0;
190 static u_char chan2bank[] =
191 {0, 4, 8, 12};                  /* for icn_map_channel() */
192
193 static icn_dev dev;
194
195 #endif                          /* __KERNEL__ */
196
197 /* Utility-Macros */
198
199 /* Macros for accessing ports */
200 #define ICN_CFG    (card->port)
201 #define ICN_MAPRAM (card->port+1)
202 #define ICN_RUN    (card->port+2)
203 #define ICN_BANK   (card->port+3)
204
205 /* Return true, if there is a free transmit-buffer */
206 #define sbfree (((readb(&dev.shmem->data_control.scns)+1) & 0xf) != \
207                 readb(&dev.shmem->data_control.scnr))
208
209 /* Switch to next transmit-buffer */
210 #define sbnext (writeb((readb(&dev.shmem->data_control.scns)+1) & 0xf, \
211                        &dev.shmem->data_control.scns))
212
213 /* Shortcuts for transmit-buffer-access */
214 #define sbuf_n dev.shmem->data_control.scns
215 #define sbuf_d dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].data
216 #define sbuf_l dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].length
217 #define sbuf_f dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].endflag
218
219 /* Return true, if there is receive-data is available */
220 #define rbavl  (readb(&dev.shmem->data_control.ecnr) != \
221                 readb(&dev.shmem->data_control.ecns))
222
223 /* Switch to next receive-buffer */
224 #define rbnext (writeb((readb(&dev.shmem->data_control.ecnr)+1) & 0xf, \
225                        &dev.shmem->data_control.ecnr))
226
227 /* Shortcuts for receive-buffer-access */
228 #define rbuf_n dev.shmem->data_control.ecnr
229 #define rbuf_d dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].data
230 #define rbuf_l dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].length
231 #define rbuf_f dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].endflag
232
233 /* Shortcuts for command-buffer-access */
234 #define cmd_o (dev.shmem->comm_control.pcio_o)
235 #define cmd_i (dev.shmem->comm_control.pcio_i)
236
237 /* Return free space in command-buffer */
238 #define cmd_free ((readb(&cmd_i)>=readb(&cmd_o))? \
239                   0x100-readb(&cmd_i)+readb(&cmd_o): \
240                   readb(&cmd_o)-readb(&cmd_i))
241
242 /* Shortcuts for message-buffer-access */
243 #define msg_o (dev.shmem->comm_control.iopc_o)
244 #define msg_i (dev.shmem->comm_control.iopc_i)
245
246 /* Return length of Message, if avail. */
247 #define msg_avail ((readb(&msg_o)>readb(&msg_i))? \
248                    0x100-readb(&msg_o)+readb(&msg_i): \
249                    readb(&msg_i)-readb(&msg_o))
250
251 #define CID (card->interface.id)
252
253 #endif                          /* defined(__KERNEL__) || defined(__DEBUGVAR__) */
254 #endif                          /* icn_h */