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