ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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  (HZ) /* Delay for Boot-download (jiffies)       */
74 #define ICN_CHANLOCK_DELAY (HZ/10)      /* Delay for Channel-mapping (jiffies)     */
75
76 #define ICN_TIMER_BCREAD (HZ/100)       /* B-Channel poll-cycle                    */
77 #define ICN_TIMER_DCREAD (HZ/2) /* D-Channel poll-cycle                    */
78
79 #define ICN_CODE_STAGE1 4096    /* Size of bootcode                        */
80 #define ICN_CODE_STAGE2 65536   /* Size of protocol-code                   */
81
82 #define ICN_MAX_SQUEUE 8000     /* Max. outstanding send-data (2* hw-buf.) */
83 #define ICN_FRAGSIZE (250)      /* Max. size of send-fragments             */
84 #define ICN_BCH 2               /* Number of supported channels per card   */
85
86 /* type-definitions for accessing the mmap-io-areas */
87
88 #define SHM_DCTL_OFFSET (0)     /* Offset to data-controlstructures in shm */
89 #define SHM_CCTL_OFFSET (0x1d2) /* Offset to comm-controlstructures in shm */
90 #define SHM_CBUF_OFFSET (0x200) /* Offset to comm-buffers in shm           */
91 #define SHM_DBUF_OFFSET (0x2000)        /* Offset to data-buffers in shm           */
92
93 /*
94  * Layout of card's data buffers
95  */
96 typedef struct {
97         unsigned char length;   /* Bytecount of fragment (max 250)    */
98         unsigned char endflag;  /* 0=last frag., 0xff=frag. continued */
99         unsigned char data[ICN_FRAGSIZE];       /* The data                           */
100         /* Fill to 256 bytes */
101         char unused[0x100 - ICN_FRAGSIZE - 2];
102 } frag_buf;
103
104 /*
105  * Layout of card's shared memory
106  */
107 typedef union {
108         struct {
109                 unsigned char scns;     /* Index to free SendFrag.             */
110                 unsigned char scnr;     /* Index to active SendFrag   READONLY */
111                 unsigned char ecns;     /* Index to free RcvFrag.     READONLY */
112                 unsigned char ecnr;     /* Index to valid RcvFrag              */
113                 char unused[6];
114                 unsigned short fuell1;  /* Internal Buf Bytecount              */
115         } data_control;
116         struct {
117                 char unused[SHM_CCTL_OFFSET];
118                 unsigned char iopc_i;   /* Read-Ptr Status-Queue      READONLY */
119                 unsigned char iopc_o;   /* Write-Ptr Status-Queue              */
120                 unsigned char pcio_i;   /* Write-Ptr Command-Queue             */
121                 unsigned char pcio_o;   /* Read-Ptr Command Queue     READONLY */
122         } comm_control;
123         struct {
124                 char unused[SHM_CBUF_OFFSET];
125                 unsigned char pcio_buf[0x100];  /* Ring-Buffer Command-Queue           */
126                 unsigned char iopc_buf[0x100];  /* Ring-Buffer Status-Queue            */
127         } comm_buffers;
128         struct {
129                 char unused[SHM_DBUF_OFFSET];
130                 frag_buf receive_buf[0x10];
131                 frag_buf send_buf[0x10];
132         } data_buffers;
133 } icn_shmem;
134
135 /*
136  * Per card driver data
137  */
138 typedef struct icn_card {
139         struct icn_card *next;  /* Pointer to next device struct    */
140         struct icn_card *other; /* Pointer to other card for ICN4B  */
141         unsigned short port;    /* Base-port-address                */
142         int myid;               /* Driver-Nr. assigned by linklevel */
143         int rvalid;             /* IO-portregion has been requested */
144         int leased;             /* Flag: This Adapter is connected  */
145                                 /*       to a leased line           */
146         unsigned short flags;   /* Statusflags                      */
147         int doubleS0;           /* Flag: ICN4B                      */
148         int secondhalf;         /* Flag: Second half of a doubleS0  */
149         int fw_rev;             /* Firmware revision loaded         */
150         int ptype;              /* Protocol type (1TR6 or Euro)     */
151         struct timer_list st_timer;   /* Timer for Status-Polls     */
152         struct timer_list rb_timer;   /* Timer for B-Channel-Polls  */
153         u_char rcvbuf[ICN_BCH][4096]; /* B-Channel-Receive-Buffers  */
154         int rcvidx[ICN_BCH];    /* Index for above buffers          */
155         int l2_proto[ICN_BCH];  /* Current layer-2-protocol         */
156         isdn_if interface;      /* Interface to upper layer         */
157         int iptr;               /* Index to imsg-buffer             */
158         char imsg[60];          /* Internal buf for status-parsing  */
159         char msg_buf[2048];     /* Buffer for status-messages       */
160         char *msg_buf_write;    /* Writepointer for statusbuffer    */
161         char *msg_buf_read;     /* Readpointer for statusbuffer     */
162         char *msg_buf_end;      /* Pointer to end of statusbuffer   */
163         int sndcount[ICN_BCH];  /* Byte-counters for B-Ch.-send     */
164         int xlen[ICN_BCH];      /* Byte-counters/Flags for sent-ACK */
165         struct sk_buff *xskb[ICN_BCH]; /* Current transmitted skb   */
166         struct sk_buff_head spqueue[ICN_BCH];  /* Sendqueue         */
167         char regname[35];       /* Name used for request_region     */
168         u_char xmit_lock[ICN_BCH]; /* Semaphore for pollbchan_send()*/
169         spinlock_t lock;        /* protect critical operations      */
170 } icn_card;
171
172 /*
173  * Main driver data
174  */
175 typedef struct icn_dev {
176         spinlock_t devlock;     /* spinlock to protect this struct  */
177         unsigned long memaddr;  /* Address of memory mapped buffers */
178         icn_shmem *shmem;       /* Pointer to memory-mapped-buffers */
179         int mvalid;             /* IO-shmem has been requested      */
180         int channel;            /* Currently mapped channel         */
181         struct icn_card *mcard; /* Currently mapped card            */
182         int chanlock;           /* Semaphore for channel-mapping    */
183         int firstload;          /* Flag: firmware never loaded      */
184 } icn_dev;
185
186 typedef icn_dev *icn_devptr;
187
188 #ifdef __KERNEL__
189
190 static icn_card *cards = (icn_card *) 0;
191 static u_char chan2bank[] =
192 {0, 4, 8, 12};                  /* for icn_map_channel() */
193
194 static icn_dev dev;
195
196 #endif                          /* __KERNEL__ */
197
198 /* Utility-Macros */
199
200 /* Macros for accessing ports */
201 #define ICN_CFG    (card->port)
202 #define ICN_MAPRAM (card->port+1)
203 #define ICN_RUN    (card->port+2)
204 #define ICN_BANK   (card->port+3)
205
206 /* Return true, if there is a free transmit-buffer */
207 #define sbfree (((readb(&dev.shmem->data_control.scns)+1) & 0xf) != \
208                 readb(&dev.shmem->data_control.scnr))
209
210 /* Switch to next transmit-buffer */
211 #define sbnext (writeb((readb(&dev.shmem->data_control.scns)+1) & 0xf, \
212                        &dev.shmem->data_control.scns))
213
214 /* Shortcuts for transmit-buffer-access */
215 #define sbuf_n dev.shmem->data_control.scns
216 #define sbuf_d dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].data
217 #define sbuf_l dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].length
218 #define sbuf_f dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].endflag
219
220 /* Return true, if there is receive-data is available */
221 #define rbavl  (readb(&dev.shmem->data_control.ecnr) != \
222                 readb(&dev.shmem->data_control.ecns))
223
224 /* Switch to next receive-buffer */
225 #define rbnext (writeb((readb(&dev.shmem->data_control.ecnr)+1) & 0xf, \
226                        &dev.shmem->data_control.ecnr))
227
228 /* Shortcuts for receive-buffer-access */
229 #define rbuf_n dev.shmem->data_control.ecnr
230 #define rbuf_d dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].data
231 #define rbuf_l dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].length
232 #define rbuf_f dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].endflag
233
234 /* Shortcuts for command-buffer-access */
235 #define cmd_o (dev.shmem->comm_control.pcio_o)
236 #define cmd_i (dev.shmem->comm_control.pcio_i)
237
238 /* Return free space in command-buffer */
239 #define cmd_free ((readb(&cmd_i)>=readb(&cmd_o))? \
240                   0x100-readb(&cmd_i)+readb(&cmd_o): \
241                   readb(&cmd_o)-readb(&cmd_i))
242
243 /* Shortcuts for message-buffer-access */
244 #define msg_o (dev.shmem->comm_control.iopc_o)
245 #define msg_i (dev.shmem->comm_control.iopc_i)
246
247 /* Return length of Message, if avail. */
248 #define msg_avail ((readb(&msg_o)>readb(&msg_i))? \
249                    0x100-readb(&msg_o)+readb(&msg_i): \
250                    readb(&msg_i)-readb(&msg_o))
251
252 #define CID (card->interface.id)
253
254 #endif                          /* defined(__KERNEL__) || defined(__DEBUGVAR__) */
255 #endif                          /* icn_h */