1 /* $Id: icn.h,v 1.30.6.5 2001/09/23 22:24:55 kai Exp $
3 * ISDN lowlevel-module for the ICN active ISDN-Card.
5 * Copyright 1994 by Fritz Elfert (fritz@isdn4linux.de)
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
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
26 /* Struct for adding new cards */
27 typedef struct icn_cdef {
33 #if defined(__KERNEL__) || defined(__DEBUGVAR__)
38 #include <linux/version.h>
39 #include <linux/errno.h>
41 #include <linux/major.h>
43 #include <linux/kernel.h>
44 #include <linux/signal.h>
45 #include <linux/slab.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>
54 #endif /* __KERNEL__ */
56 /* some useful macros for debugging */
58 #define OUTB_P(v,p) {printk(KERN_DEBUG "icn: outb_p(0x%02x,0x%03x)\n",v,p); outb_p(v,p);}
63 /* Defaults for Port-Address and shared-memory */
64 #define ICN_BASEADDR 0x320
65 #define ICN_PORTLEN (0x04)
66 #define ICN_MEMADDR 0x0d0000
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 */
73 #define ICN_BOOT_TIMEOUT1 (HZ) /* Delay for Boot-download (jiffies) */
74 #define ICN_CHANLOCK_DELAY (HZ/10) /* Delay for Channel-mapping (jiffies) */
76 #define ICN_TIMER_BCREAD (HZ/100) /* B-Channel poll-cycle */
77 #define ICN_TIMER_DCREAD (HZ/2) /* D-Channel poll-cycle */
79 #define ICN_CODE_STAGE1 4096 /* Size of bootcode */
80 #define ICN_CODE_STAGE2 65536 /* Size of protocol-code */
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 */
86 /* type-definitions for accessing the mmap-io-areas */
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 */
94 * Layout of card's data buffers
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];
105 * Layout of card's shared memory
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 */
114 unsigned short fuell1; /* Internal Buf Bytecount */
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 */
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 */
129 char unused[SHM_DBUF_OFFSET];
130 frag_buf receive_buf[0x10];
131 frag_buf send_buf[0x10];
136 * Per card driver data
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 */
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 */
186 typedef icn_dev *icn_devptr;
190 static icn_card *cards = (icn_card *) 0;
191 static u_char chan2bank[] =
192 {0, 4, 8, 12}; /* for icn_map_channel() */
196 #endif /* __KERNEL__ */
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)
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))
210 /* Switch to next transmit-buffer */
211 #define sbnext (writeb((readb(&dev.shmem->data_control.scns)+1) & 0xf, \
212 &dev.shmem->data_control.scns))
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
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))
224 /* Switch to next receive-buffer */
225 #define rbnext (writeb((readb(&dev.shmem->data_control.ecnr)+1) & 0xf, \
226 &dev.shmem->data_control.ecnr))
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
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)
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))
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)
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))
252 #define CID (card->interface.id)
254 #endif /* defined(__KERNEL__) || defined(__DEBUGVAR__) */